哨兵模式的redis实例重置脚本

初学乍练redis 专栏收录该内容
20 篇文章 5 订阅
#!/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

 

  • 2
    点赞
  • 1
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值