准备两台Centos7
主 192.168.1.100
备主192.168.1.101
[root@localhost src]# yum -y install gcc lrzsz
[root@localhost src]# rz
tar xzvf redis-3.2.10.tar.gz -C /usr/local/src/
5 cd /usr/local/src/
[root@localhost src]# cd redis-3.2.8
[root@localhost redis-3.2.8]# make
[root@localhost redis-3.2.8]# make install
在Ip为192.168.1.100的主机的配置
[root@localhost redis-3.2.8]# mkdir redis_cluster/
[root@localhost redis_cluster]# mkdir 6379 6380
[root@localhost redis_cluster]# cp …/redis.conf 6379/
[root@localhost redis_cluster]# cp …/redis.conf 6380/
[root@localhost redis_cluster]# cp …/sentinel.conf 6380 #主机不需要哨兵
修改6379目录下的主配置文件
[root@localhost 6379]# cat redis.conf |grep -v “^$” |grep -v “^#”
只修改以下配置即可
bind 192.168.1.100
protected-mode yes
port 6379
daemonize yes
supervised no
pidfile “/var/run/redis_6379.pid”
slave-priority 25
修改6380目录下的从配置文件
vim redis.conf
bind 192.168.1.100
protected-mode yes
port 6380
daemonize yes
supervised no
pidfile “/var/run/redis_6380.pid”
slaveof 192.168.1.100 6379
slave-priority 100
vim sentinel.conf
protected-mode no
port 26379
dir “/tmp”
sentinel monitor mymaster 192.168.1.100 6379 2
daemonize yes
在Ip为192.168.1.101的主机的配置
创建环境目录并复制配置文件
[root@localhost redis-3.2.8]# mkdir redis_cluster/
[root@localhost redis_cluster]# mkdir 6379 6380
[root@localhost redis_cluster]# cp …/redis.conf 6379/
[root@localhost redis_cluster]# cp …/redis.conf 6380/
[root@localhost redis_cluster]# cp …/sentinel.conf 6380/
[root@localhost redis_cluster]# cp …/sentinel.conf 6379/
修改6379目录下的备主配置文件
vim redis.conf
bind 192.168.1.101
protected-mode yes
port 6379
daemonize yes
supervised no
pidfile “/var/run/redis_6379.pid”
dir “/usr/local/src/redis-3.2.10/redis_cluster/6379”
slave-priority 25
slaveof 192.168.1.100 6379
vim sentinel.conf
protected-mode no
port 26379
dir “/tmp”
sentinel monitor mymaster 192.168.1.100 6379 2
daemonize yes
修改6380目录下的备主配置文件
vim redis.conf
bind 192.168.1.101
protected-mode yes
port 6380
daemonize yes
supervised no
pidfile “/var/run/redis_6380.pid”
dir “/usr/local/src/redis-3.2.10/redis_cluster/6380”
slave-priority 100
slaveof 192.168.1.100 6379
vim sentinel.conf
protected-mode no
port 26380
dir “/tmp”
sentinel monitor mymaster 192.168.1.100 6379 2
daemonize yes
开启主从所有服务和哨兵
[root@localhost 6379]# redis-server redis.conf
[root@localhost 6379]# cd …/6380/
[root@localhost 6380]# redis-server redis.conf
[root@localhost 6380]# redis-sentinel sentinel.conf
验证
[root@localhost 6379]# systemctl stop firewalld
[root@localhost 6379]# setenforce 0
杀掉它
我们发现备主接替主机工作