redis 哨兵模式
三台机器:
192.168.150.200(主)
192.168.150.166(从)
192.168.150.207(从)
192.168.150.200主的操作:
先把redis-5.0.3.tar.gz 放到虚拟机
[root@localhost ~]# yum -y install gcc gcc-c++
[root@localhost ~]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make && make install
[root@localhost redis-5.0.3]# cp redis.conf /etc/
[root@localhost redis-5.0.3]# cp sentinel.conf /etc/
[root@localhost redis-5.0.3]# vim /etc/redis.conf
69 bind 0.0.0.0
136 daemonize yes (把no改成yes)
启动:
[root@localhost redis-5.0.3]# redis-server /etc/redis.conf
然后修改哨兵
[root@localhost redis-5.0.3]# vim /etc/sentinel.conf
15 bind 0.0.0.0 (改为所有IP)
17 protected-mode no (去掉注释)
26 daemonize yes (改为后台运行)
84 sentinel monitor mymaster 192.168.150.200 6379 2 (IP改为主的IP,端口后面是哨兵的数量,数字不能超过哨兵数)
36 logfile "/tmp/sentinel.log" (改不改都可以,方便查看日志)
如:tailf /tmp/sentinel.log
[root@localhost redis-5.0.3]# redis-sentinel /etc/sentinel.conf (启动)
192.168.150.166从的操作:
和主一样,拖包并且安装依赖
[root@localhost ~]# yum -y install gcc gcc-c++
[root@localhost ~]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make && make install
[root@localhost redis-5.0.3]# cp redis.conf /etc/
[root@localhost redis-5.0.3]# cp sentinel.conf /etc/
[root@localhost redis-5.0.3]# vim /etc/redis.conf
92 port 6380
69 bind 0.0.0.0
136 daemonize yes (把no改成yes)
286 replicaof 192.168.150.200 6379 (把masterip改成主的IP,masterport改为主的端口)
[root@localhost redis-5.0.3]# redis-server /etc/redis.conf
修改哨兵:
[root@localhost redis-5.0.3]# vim /etc/sentinel.conf
15 bind 0.0.0.0 (改为所有IP)
17 protected-mode no (去掉注释)
26 daemonize yes (改为后台运行)
84 sentinel monitor mymaster 192.168.150.200 6379 2
36 logfile "/tmp/sentinel.log"
[root@localhost redis-5.0.3]# redis-sentinel /etc/sentinel.conf (启动)
192.168.150.207从的操作:
[root@localhost ~]# yum -y install gcc gcc-c++
[root@localhost ~]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make && make install
[root@localhost redis-5.0.3]# cp redis.conf /etc/
[root@localhost redis-5.0.3]# cp sentinel.conf /etc/
[root@localhost redis-5.0.3]# vim /etc/redis.conf
92 port 6381
69 bind 0.0.0.0
136 daemonize yes (把no改成yes)
286 replicaof 192.168.150.200 6379 (把masterip改成主的IP,masterport改为主的端口)
[root@localhost redis-5.0.3]# redis-server /etc/redis.conf
修改哨兵:
[root@localhost redis-5.0.3]# vim /etc/sentinel.conf
15 bind 0.0.0.0 (改为所有IP)
17 protected-mode no (去掉注释)
26 daemonize yes (改为后台运行)
84 sentinel monitor mymaster 192.168.150.200 6379 2
36 logfile "/tmp/sentinel.log"
[root@localhost redis-5.0.3]# redis-sentinel /etc/sentinel.conf (启动)