标签:redis
1.下载redis安装文件
https://github.com/antirez/redis/archive/3.2.5.tar.gz
2.安装编绎所需包。
[root@server ~]#yum install gcc tcl
3.安装redis
[root@server ~]#mkdir /usr/local/redis [root@server ~]#cd /usr/local/src [root@server src]# tar -zxvf redis-3.2.5.tar.gz [root@server src]#cd redis-3.2.5 [root@server redis-3.2.5]#make PREFIX=/usr/local/redis install [root@server redis-3.2.5]#ls /usr/local/redis/bin /*在redis目录下多出一个bin目录*/ redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
4.redis配置为服务
[root@server redis-3.2.5]#cp utils/redis_init_script /etc/rc.d/init.d/redis [root@server redis-3.2.5]#vi /etc/rc.d/init.d/redis 在第二行添加:#chkconfig: 2345 80 90 EXEC=/usr/local/bin/redis-server 修改成 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/bin/redis-cli 修改成 CLIEXEC=/usr/local/redis/bin/redis-cli CONF="/etc/redis/${REDISPORT}.conf" 修改成 CONF="/usr/local/redis/conf/${REDISPORT}.conf" $EXEC $CONF 修改成 $EXEC $CONF & [root@server redis-3.2.5]#mkdir /usr/local/redis/conf/ [root@server redis-3.2.5]#chkconfig --add redis [root@server redis-3.2.5]#cp redis.conf /usr/local/redis/6379.conf [root@server redis-3.2.5]#vi /usr/local/redis/6379.conf daemonize no 改为 daemonize yes pidfile /var/run/redis.pid 改为 pidfile /var/run/redis_6379.pid
5.打开防火墙端口
[root@server redis-3.2.5]#vi /etc/sysconfig/iptables /**追加一行**/ -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT [root@server redis-3.2.5]#service iptables restart [root@server redis-3.2.5]#service redis start /**启动redis**/
6.添加环境变量
[root@server redis-3.2.5]#vi /etc/profile PATH=$PATH:/usr/local/redis/bin export PATH :wq [root@server redis-3.2.5]#source /etc/profile [root@server redis-3.2.5]#redis-cli 127.0.0.1:6379> 127.0.0.1:6379> set testkey testvalue OK 127.0.0.1:6379> get test (nil) 127.0.0.1:6379> get testkey "testvalue" 127.0.0.1:6379> exit [root@server redis-3.2.5]#vi /usr/local/redis/conf/6379.conf /*添加一个验证密码*/ requirepass 123456 [root@server redis-3.2.5]#service redis stop [root@server redis-3.2.5]#service redis start [root@server redis-3.2.5]# redis-cli 127.0.0.1:6379> set key ss (error) NOAUTH Authentication required. [root@server redis-3.2.5]# redis-cli -a 123456 127.0.0.1:6379> set a b OK 127.0.0.1:6379> get a "b" 127.0.0.1:6379> exit; [root@server redis-3.2.5]#
本文出自 “开心程序” 博客,请务必保留此出处http://jamesoak.blog.51cto.com/4365697/1868076
标签:redis
原文地址:http://jamesoak.blog.51cto.com/4365697/1868076