安装redis-5.0.9版本,一主二从三哨兵集群

Posted 西风h

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装redis-5.0.9版本,一主二从三哨兵集群相关的知识,希望对你有一定的参考价值。

shell脚本安装三哨兵模式集群,一主二从。

脚本如下

#!/bin/bash
echo "本地yum源是否配置完毕,是请忽略,否请按CTRL+C退出!"
sleep 3
echo "自动化安装redis-5.0.9版本,一主二从三哨兵集群:"
read -p "请根据实际数据挂载盘输入redis哨兵集群安装的主目录(譬如/wls或是/data):" maindir
ip addr
echo "redis5哨兵集群配置:"
read -p "请输入本地内网IP地址(参考上面输出信息,非127.0.0.1):" ip
read -p "请输入 master ip : " masterip
read -p "请输入 slave1 ip : " slave1ip
read -p "请输入 slave2 ip : " slave2ip
read -p "请输入加密密码:" password
read -p "请输入当前节点是 master 或者 slave:" kind
if [ -f /root/redis-5.0.9.tar.gz ];then

echo "系统内核参数优化!"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "net.core.somaxconn=551" >> /etc/sysctl.conf
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl -p

mkdir $maindir

yum -y install zlib-devel openssl-devel gcc-c++
echo "redis编译安装!"
cd /root
tar xf redis-5.0.9.tar.gz
cd redis-5.0.9
make PREFIX=$maindir/redis install
mkdir -pv $maindir/redis/{etc,logs,data,pid}
cp redis.conf $maindir/redis/etc/
cp sentinel.conf $maindir/redis/etc/

echo "如有异常,请按CTRL+C退出!如正常,将继续执行下一步!"
sleep 2

if [ $kind = master ];then

cat >$maindir/redis/etc/redis.conf <<EOF
daemonize yes
port 6379
bind $ip 127.0.0.1
dir $maindir/redis
pidfile $maindir/redis/pid/redis.pid
logfile $maindir/redis/logs/redis.log
appendonly yes
appendfsync everysec
requirepass $password
masterauth $password
EOF
cat >$maindir/redis/etc/sentinel.conf <<EOF
daemonize yes
port 26379
bind 0.0.0.0 
dir $maindir/redis/
pidfile $maindir/redis/pid/redis-sentinel.pid
logfile "$maindir/redis/logs/redis-sentinel.log"
sentinel monitor mymaster $masterip  6379 2
sentinel auth-pass mymaster $password
sentinel down-after-milliseconds mymaster 30000 
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
EOF
else
cat >$maindir/redis/etc/redis.conf <<EOF
daemonize yes
port 6379
bind $ip 127.0.0.1
dir $maindir/redis
pidfile $maindir/redis/pid/redis.pid
logfile $maindir/redis/logs/redis.log
appendonly yes
appendfsync everysec
requirepass $password
slaveof  $masterip 6379
slaveof  $slave1ip 6379
slaveof  $slave2ip 6379
masterauth $password
EOF
cat >$maindir/redis/etc/sentinel.conf <<EOF
daemonize yes
port 26379
bind 0.0.0.0 
dir $maindir/redis/
pidfile $maindir/redis/pid/redis-sentinel.pid
logfile "$maindir/redis/logs/redis-sentinel.log"
sentinel monitor mymaster $masterip  6379 2
sentinel auth-pass mymaster $password
sentinel down-after-milliseconds mymaster 30000 
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
EOF
fi

echo "如有异常,请按CTRL+C退出!如正常,将继续执行下一步!"
sleep 2
cat > /etc/profile.d/redis.sh <<EOF
PATH=$maindir/redis/bin:\\$PATH
export PATH
EOF
source /etc/profile.d/redis.sh
$maindir/redis/bin/redis-server $maindir/redis/etc/redis.conf &
$maindir/redis/bin/redis-sentinel $maindir/redis/etc/sentinel.conf &
sleep 2
ps -ef|grep redis
else
echo "请把相应的包上传到/root目录,再进行下一步!"
exit 0
fi
echo "三个节点配置完成之后启动哨兵验证
		$maindir/redis/bin/redis-sentinel $maindir/redis/etc/sentinel.conf
		redis-cli -h $masterip -p 26379 #登录 检查哨兵数量是否正确
			info 命令查看"

 

以上是关于安装redis-5.0.9版本,一主二从三哨兵集群的主要内容,如果未能解决你的问题,请参考以下文章

三台服务器上离线安装redis哨兵集群,一主二从三哨兵

三台服务器上离线安装redis哨兵集群,一主二从三哨兵

Redis安装部署(一主二从三哨兵)

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

Redis安装部署(一主二从三哨兵)

centos7案例实战——redis一主二从三哨兵高可用服务搭建