#!/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.confsed−i"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.confsed−i"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 &