redis哨兵模式安装脚本

#!/bin/bash
if [ ! -d “/data/deploy/redis/cluster” ];then
mkdir -p /data/deploy/redis/cluster
else
echo “目录已存在”
fi
cd /data/deploy/redis/
wget https://download.redis.io/releases/redis-5.0.14.tar.gz
tar zxvf redis-5.0.14.tar.gz
cd redis-5.0.14/src

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i ‘s/$releasever/7/g’ /etc/yum.repos.d/CentOS-Base.repo
yum repolist
yum install -y gcc

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install

cd /data/deploy/redis/redis-5.0.14/src
make
make test
sudo make install

mkdir -p /data/deploy/redis/master-slave/{6379,6380,6381}
cd /data/deploy/redis/master-slave
cp …/redis-5.0.14/redis.conf .
cp redis.conf 6379/
cp redis.conf 6380/
cp redis.conf 6381/

hostip=hostname -I|awk "{print $1}"

sed -i “s/127.0.0.1/ h o s t i p / g " 6379 / r e d i s . c o n f s e d − i " s / 127.0.0.1 / {hostip}/g" 6379/redis.conf sed -i "s/127.0.0.1/ hostip/g"6379/redis.confsedi"s/127.0.0.1/{hostip}/g” 6380/redis.conf
sed -i “s/127.0.0.1/${hostip}/g” 6381/redis.conf

sed -i ‘s/port 6379/port 6380/g’ 6380/redis.conf
sed -i ‘s/port 6379/port 6381/g’ 6381/redis.conf

sed -i ‘/requirepass foobared/a\requirepass nFqwIGTSbKafhcTN’ 6379/redis.conf
sed -i ‘/requirepass foobared/a\requirepass nFqwIGTSbKafhcTN’ 6380/redis.conf
sed -i ‘/requirepass nFqwIGTSbKafhcTN/a\masterauth nFqwIGTSbKafhcTN’ 6380/redis.conf
sed -i ‘/masterauth nFqwIGTSbKafhcTN/a\slaveof 10.167.169.73 6379’ 6380/redis.conf

sed -i ‘/requirepass foobared/a\requirepass nFqwIGTSbKafhcTN’ 6381/redis.conf
sed -i ‘/requirepass nFqwIGTSbKafhcTN/a\masterauth nFqwIGTSbKafhcTN’ 6381/redis.conf
sed -i ‘/masterauth nFqwIGTSbKafhcTN/a\slaveof 10.167.169.73 6379’ 6381/redis.conf

nohup /usr/local/bin/redis-server /data/deploy/redis/master-slave/6379/redis.conf >> /tmp/redis6379.log 2>&1 &
nohup /usr/local/bin/redis-server /data/deploy/redis/master-slave/6380/redis.conf >> /tmp/redis6380.log 2>&1 &
nohup /usr/local/bin/redis-server /data/deploy/redis/master-slave/6381/redis.conf >> /tmp/redis6381.log 2>&1 &

mkdir -p /data/deploy/redis/sentinel/{26379,26380,26381}
cd /data/deploy/redis/sentinel

cp sentinel.conf 26379/sentinel.conf
cp sentinel.conf 26380/sentinel.conf
cp sentinel.conf 26381/sentinel.conf

sed -i “s/127.0.0.1/ h o s t i p / g " 26379 / s e n t i n e l . c o n f s e d − i " s / 127.0.0.1 / {hostip}/g" 26379/sentinel.conf sed -i "s/127.0.0.1/ hostip/g"26379/sentinel.confsedi"s/127.0.0.1/{hostip}/g” 26380/sentinel.conf
sed -i “s/127.0.0.1/${hostip}/g” 26381/sentinel.conf

sed -i ‘s/port 26379/port 26380/g’ 26380/sentinel.conf
sed -i ‘s/port 26379/port 26381/g’ 26381/sentinel.conf

sed -i ‘/sentinel monitor mymaster/a\sentinel auth-pass mymaster nFqwIGTSbKafhcTN’ 26379/sentinel.conf
sed -i ‘/sentinel monitor mymaster/a\sentinel auth-pass mymaster nFqwIGTSbKafhcTN’ 26380/sentinel.conf
sed -i ‘/sentinel monitor mymaster/a\sentinel auth-pass mymaster nFqwIGTSbKafhcTN’ 26381/sentinel.conf

nohup /usr/local/bin/redis-sentinel /data/deploy/redis/sentinel/26379/sentinel.conf >> /tmp/redis26379.log 2>&1 &
nohup /usr/local/bin/redis-sentinel /data/deploy/redis/sentinel/26380/sentinel.conf >> /tmp/redis26380.log 2>&1 &
nohup /usr/local/bin/redis-sentinel /data/deploy/redis/sentinel/26381/sentinel.conf >> /tmp/redis26381.log 2>&1 &

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值