tiyan 发表于 2017-12-21 23:12:22

Centos-6.8 x64安装redis-3.2.8

Redis源码安装 安装环境Centos-6.8 x64 redis-3.2.8.tar.gz(放置在download下)  

1.解压文件  
[root
@LS-Min download]# tar -zxvf redis-3.2.8.tar.gz  
...
  
[root
@LS-Min download]# cd redis-3.2.8  
2.编译文件
  
# make
  
...
  
# cd src
  
3.测试是否编译成功
  
# ./redis-server
  
4590:C 03 Mar 14:07:31.106 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
  
4590:M 03 Mar 14:07:31.106 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  _._                                                
  _.-``__ ''-._                                             
  _.-``    `.`_.''-._         Redis 3.2.8 (00000000/0) 64 bit
  .-`` .-```.```\/    _.,_ ''-._                                 
  (    '      ,       .-`| `,    )   Running in standalone mode
  |`-._`-...-` __...-.``-._|'` _.-'|   Port: 6379
  |    `-._   `._    /   _.-'    |   PID: 4590
  `-._    `-._`-./_.-'    _.-'                                 
  |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  |    `-._`-._      _.-'_.-'    |         http://redis.io      
  `-._    `-._`-.__.-'_.-'    _.-'                                 
  |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  |    `-._`-._      _.-'_.-'    |                                 
  `-._    `-._`-.__.-'_.-'    _.-'                                 
  `-._    `-.__.-'    _.-'                                       
  `-._      _.-'                                          
  `-.__.-'                                             
  

  
4./usr/local下建立redis文件夹
  
# mkdir -p /usr/local/redis-3.2.8/conf
  
# mkdir -p /usr/local/redis-3.2.8/bin
  
5.将redis-3.2.8/src目录下可执行文件复制
  
# cp redis-server redis-cli redis-benchmark redis-check-aof redis-check-rdb redis-sentinel /usr/local/redis-3.2.8/bin
  
# cd ../
  
# cp redis.conf /usr/local/redis-3.2.8/conf
  
6.作为系统服务
  
# cp utils/redis_init_script /etc/init.d/redis
  

  
7.编辑redis.conf
  
# vim /usr/local/redis-3.2.8/conf/redis.conf
  
(1)bind 127.0.0.1 后追加 本机ip
  bind 127.0.0.1 10.21.36.120
  (2)daemonize no --> daemonize yes 守护进程运行
  (3)pidfile /var/run/redis_6379.pid -->pidfile /var/run/redis.pid
  (4)logfile "" --> logfile "/usr/local/redis-3.2.8/logs/redis.log"
  (5)#requirepass foobared --> requirepass abcd1234 启用密码
  
#wq
  
8.编辑init.d/redis
  
# vim /etc/init.d/redis
  
(1)增加
  # chkconfig: 2345 90 10
  # description: Redis is a persistent key-value database
  (2)EXEC=/usr/local/redis-3.2.8/bin/redis-server
  (3)CLIEXEC=/usr/local/redis-3.2.8/bin/redis-cli
  (4)PIDFILE=/var/run/redis.pid
  (5)CONF="/usr/local/redis-3.2.8/conf/redis.conf"
  (6)$CLIEXEC -p $REDISPORT shutdown -->$CLIEXEC -a "abcd1234" -p $REDISPORT shutdown#-a 指定密码
  
#wq
  
9.开机自启动
  
# chkconfig redis on
  

  
10. 开放防火墙6379端口
  
# vim /etc/sysconfig/iptables
  
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT 下增加
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379-j ACCEPT
  
# service iptables restart
  
iptables: Setting chains to policy ACCEPT: filter         
  
iptables: Flushing firewall rules:                        
  
iptables: Unloading modules:                              
  
iptables: Applying firewall rules:                        
  

  常见问题:
  
(1)bind 127.0.0.1 10.21.36.120 绑定10.21.36.120后,让其他机器访问,不能去掉127.0.0.1否则本机服务stop会失败
  
# service redis stop
  
   Stopping ...
  Could not connect to Redis at 127.0.0.1:6379: Connection refused
  Waiting for Redis to shutdown ...
  Waiting for Redis to shutdown ...
  
(2)启用密码后,/etc/init.d/redis 要做修改$CLIEXEC -p $REDISPORT shutdown -->$CLIEXEC -a "abcd1234" -p $REDISPORT shutdown
  否则本机服务stop会失败
# service redis stop
  
   Stopping ...
  OK
  (error) NOAUTH Authentication required.
  Waiting for Redis to shutdown ...
  Waiting for Redis to shutdown ..
  

  
(3))service redis stop失败时 停止redis服务
  
   # ps -ef|grep redis
  
   root      4518   10 13:47 ?      00:00:00 /usr/local/redis-3.2.8/bin/redis-server 127.0.0.1:6379                        
# kill -9 4518
# rm -rf /var/run/redis.pid
  

  
页: [1]
查看完整版本: Centos-6.8 x64安装redis-3.2.8