#!/bin/bash
if [ ! -n "$1" ] ;then
echo "请输入集群端口号!"
exit
fi
master_name=`/home/redis/redis-3.2.3/src/redis-cli -p 30001 info | grep $1 | awk -F"," '{print $1}' | awk -F"=" '{print $2}'`
echo $master_name
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
# 移除哨兵监控
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.204 -p 30001 sentinel remove $master_name
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.205 -p 30001 sentinel remove $master_name
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.206 -p 30001 sentinel remove $master_name
echo -e "\n移除哨兵监控 ...,任意键继续,组合键 CTRL+C 终止命令!\n"
char=`get_char`
# 重置主从
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.204 -p $1 -a 123456 slaveof no one
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.205 -p $1 -a 123456 slaveof 192.168.200.204 $1
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.206 -p $1 -a 123456 slaveof 192.168.200.204 $1
echo -e "\n重置主从 ...,任意键继续,组合键 CTRL+C 终止命令!\n"
char=`get_char`
# 添加哨兵监控
cat /dev/null > /home/redis/tmp_sentinel_monitor
echo "sentinel monitor ${master_name} 192.168.200.204 $1 2" >> /home/redis/tmp_sentinel_monitor
echo "sentinel set ${master_name} auth-pass 123456" >> /home/redis/tmp_sentinel_monitor
echo "sentinel set ${master_name} down-after-milliseconds 5000" >> /home/redis/tmp_sentinel_monitor
echo "sentinel set ${master_name} failover-timeout 10000" >> /home/redis/tmp_sentinel_monitor
cat /home/redis/tmp_sentinel_monitor | /home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.204 -p 30001
cat /home/redis/tmp_sentinel_monitor | /home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.205 -p 30001
cat /home/redis/tmp_sentinel_monitor | /home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.206 -p 30001
echo -e "\n添加哨兵监控 ...,任意键继续,组合键 CTRL+C 终止命令!\n"
char=`get_char`
# 重启本机哨兵
/home/redis/restart_sentinel.sh
echo -e "\n重启本地哨兵 ...,任意键继续,组合键 CTRL+C 终止命令!\n"
char=`get_char`
# 重启远程哨兵
ssh 192.168.200.205 /home/redis/restart_sentinel.sh
ssh 192.168.200.206 /home/redis/restart_sentinel.sh
echo -e "\n重启远程哨兵 ...,任意键继续,组合键 CTRL+C 终止命令!\n"
char=`get_char`
wait
# 检查哨兵监控
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.204 -p 30001 info | grep $1
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.205 -p 30001 info | grep $1
/home/redis/redis-3.2.3/src/redis-cli -h 192.168.200.206 -p 30001 info | grep $1