准备三个节点,系统版本为CentOS7.3
11.0.8.15 master
11.0.8.16 slave01
11.0.8.17 slave02
1、安装redis
# yum install -y redis
2、修改redis的配置文件
# vim /etc/redis.conf
#bind 127.0.0.1
protected-mode no
daemonize yes
appendonly yes
slaveof 11.0.8.15 6379 #从节点需要开启这条指令
3、启动redis服务
# systemctl start redis && systemctl enable redis
4、查看复制信息
# redis-cli -h 11.0.8.15
11.0.8.15:6379> set name keith
OK
11.0.8.15:6379> get name
"keith"
11.0.8.15:6379> keys *
1) "name"
11.0.8.15:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=11.0.8.16,port=6379,state=online,offset=128,lag=1
slave1:ip=11.0.8.17,port=6379,state=online,offset=142,lag=1
master_repl_offset:142
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:141
5、修改sentinel的配置文件
# vim /etc/redis-sentinel.conf
sentinel monitor mymaster 11.0.8.15 6379 2
6、启动sentinel服务
# systemctl start redis-sentinel && systemctl enable redis-sentinel
# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:26379 0.0.0.0:* LISTEN 41288/redis-sentine
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 41220/redis-server
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 932/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1555/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1178/master
tcp6 0 0 :::26379 :::* LISTEN 41288/redis-sentine
tcp6 0 0 :::6379 :::* LISTEN 41220/redis-server
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::53 :::* LISTEN 932/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 1555/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1178/master