echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] wait 10 sec for data sync from old master" >> $LOGFILE 2>&1 sleep 10 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] data rsync from old mater ok..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] Run slaveof no one,close master/slave" >> $LOGFILE 2>&1
$REDISCLI SLAVEOF NO ONE >> $LOGFILE 2>&1
echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] wait other slave connect...." >> $LOGFILE 2>&1
iv)增加redis_backup.sh文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
vim /etc/keepalived/redis_backup.sh
#!/bin/bash REDISCLI="/home/redis-4.0.6/src/redis-cli -a redis-2019" LOGFILE="/etc/keepalived/keepalived-redis-state.log" pid=$$ host=$1 port=$2 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] Being slave state..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] wait 10 sec for data sync from old master" >> $LOGFILE 2>&1 sleep 10 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] data rsync from old mater ok..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] Run 'SLAVEOF $host$port'" >> $LOGFILE 2>&1 $REDISCLI SLAVEOF $host$port >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] slave connect to $host ok..." >> $LOGFILE 2>&1
3)Redis-Slave节点安装keepalived服务 i)修改keepalived的配置文件
1 2
yum localinstall *.rpm或rpm -ivh *.rpm --nodeps --force vim /etc/keepalived/keepalived.conf
echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] wait 10 sec for data sync from old master" >> $LOGFILE 2>&1 sleep 10
echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] data rsync from old mater ok..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] Run slaveof no one,close master/slave" >> $LOGFILE 2>&1
$REDISCLI SLAVEOF NO ONE >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] wait other slave connect...." >> $LOGFILE 2>&1
iv)增加redis_backup.sh文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
vim /etc/keepalived/redis_backup.sh
#!/bin/bash REDISCLI="/home/redis-4.0.6/src/redis-cli -a redis-2019" LOGFILE="/etc/keepalived/keepalived-redis-state.log" pid=$$ host=$1 port=$2
echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] Being slave state..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] wait 10 sec for data sync from old master" >> $LOGFILE 2>&1 sleep 10 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[master] data rsync from old mater ok..." >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] Run 'SLAVEOF $host$port'" >> $LOGFILE 2>&1 $REDISCLI SLAVEOF $host$port >> $LOGFILE 2>&1 echo"`date +'%Y-%m-%d %H:%M:%S'`|$pid|state:[slaver] slave connect to $host ok..." >> $LOGFILE 2>&1
4)验证 i)使用redis-cli连接主数据库并输入密码登录
1 2 3
[root@Master bin]# /home/redis-4.0.6/src/redis-cli -p 6379 127.0.0.1:6379> auth redis-2019 OK
查看主数据库info属性:
1
127.0.0.1:6379> info
ii)使用redis-cli连接从数据库并输入密码登录
1 2 3
[root@Master bin]# /home/redis-4.0.6/src/redis-cli -p 6379 127.0.0.1:6379> auth redis-2019 OK