Redis(一) CentOS十分钟搭建Redis2.8.9
redis介绍不再累赘 1、安装gcc,因为Redis是用C语言写的,所以需要gcc进行编译 yum install gcc -y 2、下载redis-2.8.9.tar.gz http://download.redis.io/releases/redis-2.8.9.tar.gz 3、安装Redis tar xf redis-2.8.9.tar.gz cd redis-2.8.9 make MALLOC=libc make PREFIX=/usr/local/redis install 4、安装完成以后查看目录以及文件 [root@salt-server bin]# pwd /usr/local/redis/bin [root@salt-server bin]# ls redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server 5、命令解释 redis-server:redis服务器的daemon启动程序 redis-cli:redis命令行操作工具 redis-benchmark:redis性能测试工具 redis-check-aof:对更新日志appendonly.aof检查 redis-check-dump:用于本地数据库rdb文件的检查 6、配置启动服务 设置环境变量: vim /etc/profile PATH=$PATH:/usr/local/redis/bin source /etc/profile 拷贝配置文件: mkdir /usr/local/redis/conf cp redis-2.8.9/redis.conf /usr/local/redis/conf echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf && sysctl -p 启动服务:redis-server /usr/local/redis/conf/redis.conf & 7、启动成功正常反馈如下 [root@salt-server ~]# redis-server /usr/local/redis/conf/redis.conf & [1] 11736 [root@salt-server ~]# [11736] 27 Jan 09:16:07.772 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.9 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 11736 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [11736] 27 Jan 09:16:07.773 # Server started, Redis version 2.8.9 [11736] 27 Jan 09:16:07.773 * The server is now ready to accept connections on port 6379 8、基本操作 关闭redis:redis-cli shutdown 可直接输入redis-cli进去交互式 [root@salt-client1 ~]# redis-cli 127.0.0.1:6379> 输入值并取值测试 [root@salt-client1 ~]# redis-cli 127.0.0.1:6379> set Test 001 //设置一个Test值为001 OK 127.0.0.1:6379> get Test //获取Test的值 "001" 127.0.0.1:6379> del Test //删除一个值 (integer) 1 127.0.0.1:6379>keys * //取所有值 9、客户端连接使用 [root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379 172.16.10.133:6379> 也可以不登录直接赋值 [root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379 set Test 789 OK [root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379 get Test "789" 10、redis安全 为redis客户端设置外部连接密码 vim /usr/local/redis/conf/redis.conf 修改requirepass如下: requirepass a)s$M7F57TN58$8 重启redis redis-cli shutdown redis-server /usr/local/redis/conf/redis.conf & 直接登录测试会提示认证失败需要指定密码 [root@salt-server ~]# redis-cli 127.0.0.1:6379> set d 1 (error) NOAUTH Authentication required. 127.0.0.1:6379> 指定密码登录 [root@salt-server ~]# redis-cli 127.0.0.1:6379> auth a)s$M7F57TN58$8 OK Over
本文题目:Redis(一) CentOS十分钟搭建Redis2.8.9
网页链接:http://pwwzsj.com/article/gpssde.html