yxsailing 发表于 2017-12-21 12:56:24

[redis] linux下哨兵篇(3)

#三台都修改为以下同样配置  
# grep -Ev "^$|#" /usr/local/src/redis-3.2.4/sentinel.conf> /etc/redis/sentinel.conf
  
# vim /etc/redis/sentinel.conf
  
port 26379                                    #sentinel监听端口
  
daemonize yes                                 #以daemon形式运行在后台
  
logfile /var/log/sentinel.log                   #日志文件
  
dir /tmp
  
sentinel monitor mymaster 192.168.56.101 6379 2 #监控mymaster组,master地址,端口,quorum次数
  
sentinel down-after-milliseconds mymaster 5000#5000毫秒即5秒连续不能连通master,认为master挂掉
  
sentinel parallel-syncs mymaster 1
  
sentinel failover-timeout mymaster 60000      #故障切换超时时间
  
sentinel auth-pass mymaster mima                #密码认证
  
protected-mode no                               #默认情况下sentinel只监听环回地址,这样就导致sentinel之间不能通信,可以改为监听网卡或者关闭protected-mode
  

  
#三台都启动
  
# /usr/local/redis/bin/redis-sentinel /etc/redis/sentinel.conf
  

  
#查看sentinel启动日志
  
#正常情况下可以看到+sentinel-address-switch字样
  
# more /var/log/sentinel.log
  
24470:X 08 Dec 10:53:12.205 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  _._                                                
  _.-``__ ''-._                                             
  _.-``    `.`_.''-._         Redis 3.2.4 (00000000/0) 64 bit
  .-`` .-```.```\/    _.,_ ''-._                                 
  (    '      ,       .-`| `,    )   Running in sentinel mode
  |`-._`-...-` __...-.``-._|'` _.-'|   Port: 26379
  |    `-._   `._    /   _.-'    |   PID: 24470
  `-._    `-._`-./_.-'    _.-'                                 
  |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  |    `-._`-._      _.-'_.-'    |         http://redis.io      
  `-._    `-._`-.__.-'_.-'    _.-'                                 
  |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  |    `-._`-._      _.-'_.-'    |                                 
  `-._    `-._`-.__.-'_.-'    _.-'                                 
  `-._    `-.__.-'    _.-'                                       
  `-._      _.-'                                          
  `-.__.-'                                             
  


  
24470:X 08 Dec 10:53:12.206 # Sentinel>  
24470:X 08 Dec 10:53:12.206 # +monitor master mymaster 192.168.56.101 6379 quorum 2
  
24470:X 08 Dec 10:53:14.321 * +sentinel-address-switch master mymaster 192.168.56.101 6379 ip 192.168.56.102 port 26379 for fae94df5596af315af0f5f97fe7ade3fad0b8a98
  
24470:X 08 Dec 10:53:14.336 * +sentinel-address-switch master mymaster 192.168.56.101 6379 ip 192.168.56.103 port 26379 for 8ea722390cabf3ad304b20f8cc42157603d21d84
  

  
#需要注意的地方,一旦启动sentinel服务后,服务会自动修改sentinel配置文件/etc/redis/sentinel.conf
  
# cat /etc/redis/sentinel.conf
  
port 26379
  
daemonize yes
  
dir "/tmp"
  
logfile "/var/log/sentinel.log"
  
sentinel myid 106e22fad7ad280b2c38542c164f7060b6587d68
  
sentinel monitor mymaster 192.168.56.101 6379 2
  
sentinel down-after-milliseconds mymaster 5000
  
sentinel failover-timeout mymaster 60000
  
sentinel auth-pass mymaster mima
  
protected-mode no
  
# Generated by CONFIG REWRITE
  
sentinel config-epoch mymaster 0
  
sentinel leader-epoch mymaster 0
  
sentinel known-slave mymaster 192.168.56.102 6379
  
sentinel known-slave mymaster 192.168.56.103 6379
  
sentinel known-sentinel mymaster 192.168.56.103 26379 8ea722390cabf3ad304b20f8cc42157603d21d84
  
sentinel known-sentinel mymaster 192.168.56.102 26379 fae94df5596af315af0f5f97fe7ade3fad0b8a98
  
sentinel current-epoch 0
  
页: [1]
查看完整版本: [redis] linux下哨兵篇(3)