主库不进行持久化,保证数据库的效率,从库进行持久化,进行备份
IP | 主机名 | 作用 |
---|---|---|
10.206.132.226 | redis01 | master,sentnel01 |
10.206.132.227 | redis02 | slave01,sentnel02 |
10.206.132.228 | redis03 | slave02,sentnel03 |
参考:Redis安装教程
在10.206.132.227
,10.206.132.228
修改配置文件
在配置文件Replication部分,添加
# replicaof <masterip> <masterport>
replicaof 10.206.132.226 6379
# masterauth <master-password>
masterauth monkey
在10.206.132.226
修改配置文件
在配置文件Replication部分,添加
# masterauth <master-password>
masterauth monkey
info replication
vi sentinel.conf
------------------------------------------------
daemonize yes
sentinel monitor mymaster 10.206.132.226 6379 2
sentinel auth-pass mymaster monkey
logfile /var/log/redis/sentinel.log
sentinel client-reconfig-script mymaster /usr/local/redis/script/failover_ip.sh
------------------------------------------------
mymaster:监听的master的别名
2:有三个哨兵,两个哨兵客观确认master下线,才可以进行切换
每一个redis服务器都需要增加redis的sudo权限
echo -e "redis\tALL=(ALL)\tNOPASSWD:/sbin/ip,NOPASSWD:/sbin/arping" > /etc/sudoers.d/redis
mkdir -p /usr/local/redis/script
cd /usr/local/redis/script
vi failover_ip.sh
---------------------------------------------------------------
#!/bin/bash
MASTER_IP=${6}
MY_IP=‘10.206.132.226‘ # local_ip
VIP=‘10.206.132.220‘ # VIP
NETMASK=‘24‘ # Netmask
INTERFACE=‘enp0s3‘ # DEV
if [ ${MASTER_IP} = ${MY_IP} ]; then
sudo /sbin/ip addr add ${VIP}/${NETMASK} dev ${INTERFACE}
sudo /sbin/arping -q -c 3 -A ${VIP} -I ${INTERFACE}
exit 0
else
sudo /sbin/ip addr del ${VIP}/${NETMASK} dev ${INTERFACE}
exit 0
fi
exit 1
---------------------------------------------------------------
chmod 755 failover_ip.sh
redis-sentinel sentinel.conf
三台机器sentinel打开后,会自动形成sentinel集群
原文:https://www.cnblogs.com/monkey6/p/14769039.html