哨兵模式的redis修改IP脚本

Posted wzy0623

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了哨兵模式的redis修改IP脚本相关的知识,希望对你有一定的参考价值。

change_to_intranet_ip_6.sh

#!/bin/bash

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


# 1. 检查哨兵状态
echo -e "\\n检查当前哨兵状态\\n"
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 info | grep master

echo -e "\\n按任意键停止哨兵进程,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 shutdown
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -h 172.18.17.167 -p 30002 shutdown
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -h 172.18.17.168 -p 30002 shutdown

echo -e "\\n按任意键备份配置文件,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/cp_conf_6.sh
ssh root@172.18.17.167 /root/cp_conf_6.sh
ssh root@172.18.17.168 /root/cp_conf_6.sh

echo -e "\\n按任意键将slave的配置改为内网IP,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/change_ip_slave_6.sh
ssh root@172.18.17.167 /root/change_ip_slave_6.sh
ssh root@172.18.17.168 /root/change_ip_slave_6.sh

echo -e "\\n按任意键将哨兵配置改为内网IP,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/change_ip_sentinel_6.sh
ssh root@172.18.17.167 /root/change_ip_sentinel_6.sh
ssh root@172.18.17.168 /root/change_ip_sentinel_6.sh

echo -e "\\n按任意键启动哨兵进程,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/start_sentinel_6.sh
ssh root@172.18.17.167 /root/start_sentinel_6.sh
ssh root@172.18.17.168 /root/start_sentinel_6.sh

wait
echo -e "\\n检查当前哨兵状态\\n"
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 info | grep master

cp_conf_6.sh

#!/bin/bash

\\cp -f /data1/redisdata19/redis.conf /data1/redisdata19/redis.conf.bak
\\cp -f /data1/sentinel_6/sentinel.conf /data1/sentinel_6/sentinel.conf.bak

change_ip_slave_6.sh

#!/bin/bash

master_host=`sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn info replication | grep master_host | awk -F: 'print $2' | sed -e 's/104.245.234.166/172.18.17.166/g;s/104.245.234.167/172.18.17.167/g;s/104.245.234.168/172.18.17.168/g' | tr -d '\\r' | tr -d '\\n'`

if [ $master_host ]; then
  master_port=`sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn info replication | grep master_port | awk -F: 'print $2' | tr -d '\\r' | tr -d '\\n'`
  cat /dev/null > /data1/redisdata19/replication.txt
  echo "replicaof $master_host $master_port" >> /data1/redisdata19/replication.txt
  echo "config rewrite" >> /data1/redisdata19/replication.txt
  cat /data1/redisdata19/replication.txt | sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn
fi

change_ip_sentinel_6.sh

#!/bin/bash

sed -i 's/104.245.234.166/172.18.17.166/g;s/104.245.234.167/172.18.17.167/g;s/104.245.234.168/172.18.17.168/g' /data1/sentinel_6/sentinel.conf

start_sentinel_6.sh

#!/bin/bash

sudo -u redis /home/redis/redis-6.2.3/src/redis-sentinel /data1/sentinel_6/sentinel.conf > /data1/sentinel_6/sentinel.log 2>&1 &

rollback_to_internet_ip_6.sh

#!/bin/bash

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


# 1. 检查哨兵状态
echo -e "\\n检查当前哨兵状态\\n"
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 info | grep master

echo -e "\\n按任意键停止哨兵进程,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 shutdown
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -h 172.18.17.167 -p 30002 shutdown
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -h 172.18.17.168 -p 30002 shutdown

echo -e "\\n按任意键恢复配置文件,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/rollback_conf_6.sh
ssh root@172.18.17.167 /root/rollback_conf_6.sh
ssh root@172.18.17.168 /root/rollback_conf_6.sh

echo -e "\\n按任意键将slave的配置改为外网IP,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/rollback_ip_slave_6.sh
ssh root@172.18.17.167 /root/rollback_ip_slave_6.sh
ssh root@172.18.17.168 /root/rollback_ip_slave_6.sh

echo -e "\\n按任意键启动哨兵进程,组合键 CTRL+C 终止命令!\\n"
char=`get_char`

/root/start_sentinel_6.sh
ssh root@172.18.17.167 /root/start_sentinel_6.sh
ssh root@172.18.17.168 /root/start_sentinel_6.sh

wait
echo -e "\\n检查当前哨兵状态\\n"
sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 30002 info | grep master

rollback_conf_6.sh

#!/bin/bash

\\cp -f /data1/redisdata19/redis.conf.bak /data1/redisdata19/redis.conf
\\cp -f /data1/sentinel_6/sentinel.conf.bak /data1/sentinel_6/sentinel.conf

chown redis:redis /data1/redisdata19/redis.conf
chown redis:redis /data1/sentinel_6/sentinel.conf

rollback_ip_slave_6.sh

#!/bin/bash

master_host=`sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn info replication | grep master_host | awk -F: 'print $2' | sed -e 's/172.18.17.166/104.245.234.166/g;s/172.18.17.167/104.245.234.167/g;s/172.18.17.168/104.245.234.168/g' | tr -d '\\r' | tr -d '\\n'`

if [ $master_host ]; then
  master_port=`sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn info replication | grep master_port | awk -F: 'print $2' | tr -d '\\r' | tr -d '\\n'`
  cat /dev/null > /data1/redisdata19/replication.txt
  echo "replicaof $master_host $master_port" >> /data1/redisdata19/replication.txt
  echo "config rewrite" >> /data1/redisdata19/replication.txt
  cat /data1/redisdata19/replication.txt | sudo -u redis /home/redis/redis-6.2.3/src/redis-cli -p 20019 -a plzasmdn
fi

以上是关于哨兵模式的redis修改IP脚本的主要内容,如果未能解决你的问题,请参考以下文章

Redis哨兵模式搭建(一主二从三哨兵)

Redis主从复制哨兵模式

redis哨兵机制环境搭建

Docker教程-6-在Redis主从复制基础上搭建哨兵模式

Docker教程-6-在Redis主从复制基础上搭建哨兵模式

Docker教程-6-在Redis主从复制基础上搭建哨兵模式