当前位置:首页 » 《关注互联网》 » 正文

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

19 人参与  2021年06月26日 17:23  分类 : 《关注互联网》  评论

点击全文阅读


#!/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

 


点击全文阅读


本文链接:http://zhangshiyu.com/post/21982.html

哨兵  终止  重启  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1