Redis集群部署

采用三主三从,6节点集群模式,版本5.0.9

安装脚本如下,脚本是采用三主机,6节点模式,每台主机运行主从两个redis节点,端口分别是7001,7002(默认7001是主,7002是从)

#!/bin/bash
echo "本地yum源是否配置完毕,是请忽略,否请按CTRL+C退出!"
sleep 3
echo "自动化安装redis-5.0.9版本3台服务器集群:"
read -p "请根据实际数据挂载盘输入redis-cluster安装的主目录(譬如/wls或是/data):" maindir
echo "---使用3台机6节点的交叉部署模式,3台机均需执行该脚本---"
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

dir=$maindir/redis-cluster
mkdir -p $dir/bin 

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
cd src
cp redis-server redis-cli redis-check-aof redis-check-rdb redis-sentinel redis-benchmark $dir/bin
echo "如有异常,请按CTRL+C退出!如正常,将继续执行下一步!"
sleep 2

ip addr
echo "redis5集群配置:"
read -p "请输入本地内网IP地址(参考上面输出信息,非127.0.0.1):" ip
read -p "请输入节点端口1(3台机一致):" port1
read -p "请输入节点端口2(3台机一致):" port2
read -p "请输入加密密码(3台机一致):" password
echo "redis节点端口为:${port1}和${port2}"
mkdir $dir/{$port1,$port2}

cat >$dir/$port1/redis.conf <$dir/$port2/redis.conf </dev/null|grep -v Performing |awk -F ' ' '{print $2}'`
	string2=`$maindir/redis-cluster/bin/redis-cli -a $password --cluster check $ip1:$port1|grep " $ip2:$port1" 2>/dev/null|grep -v Performing |awk -F ' ' '{print $2}'`
	string3=`$maindir/redis-cluster/bin/redis-cli -a $password --cluster check $ip1:$port1|grep " $ip3:$port1" 2>/dev/null|grep -v Performing |awk -F ' ' '{print $2}'`
    $maindir/redis-cluster/bin/redis-cli -a $password --cluster add-node $ip2:$port2 $ip1:$port1 --cluster-slave --cluster-master-id $string1
    $maindir/redis-cluster/bin/redis-cli -a $password --cluster add-node $ip3:$port2 $ip2:$port1 --cluster-slave --cluster-master-id $string2
    $maindir/redis-cluster/bin/redis-cli -a $password --cluster add-node $ip1:$port2 $ip3:$port1 --cluster-slave --cluster-master-id $string3
	echo "以下为集群创建后的最终状态信息:"
	$maindir/redis-cluster/bin/redis-cli -a $password --cluster check $ip1:$port1
	echo "###已完成3台机6个redis节点的集群模式部署###"
    echo "注意:如果6个节点交叉分布在3台机(主主和主从节点均不在同1台出现),这样的话,挂掉其中任何1台服务器将不会影响集群使用,但是需要在机器恢复后,须把主节点还原回去,办法就是:停止新的主节点,此时新从节点会变成原先旧主节点,再开启刚刚关闭的节点,让其变成从节点。"
   	else
	echo "退出集群创建!"
	fi
  else
  echo "请继续安装redis节点并启动!"
  exit 0
  fi 

else
echo "请把相应的包上传到/root目录,再进行下一步!"
exit 0
fi

 

你可能感兴趣的:(Linux,linux,redis,shell)