redis cluster 集群搭建
环境信息
主机IP 操作系统 实例端口
192.168.10.10 Suse12 Sp3 9001-9006
创建用户
useradd -d /opt/redis -m redis
安装redis
切换到redis用户,上传文件到/opt/redis目录下解压
tar xvf redis-5.0.6.tar.gz
cd redis-5.0.6
编译安装
make -j4
make install PREFIX=/opt/redis/cluster
创建目录
mkdir -p /opt/redis/cluster/{9001/{data,logs},9002/{data,logs},9003/{data,logs},9004/{data,logs},9005/{data,logs},9006/{data,logs}}
复制配置文件
for i in $(seq 9001 9006);
do
cp /opt/redis/redis-5.0.6/redis.conf /opt/redis/cluster/${i}/redis_${i}.conf
done
修改配置文件
#注意修改IP
for i in $(seq 9001 9006)
do
sed -i "s#6379#$i#g" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^bind.*#bind 192.168.10.10#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^daemonize.*#daemonize yes#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^pidfile.*#pidfile /opt/redis/cluster/${i}/logs/redis_${i}.pid#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^logfile.*#logfile /opt/redis/cluster/${i}/logs/redis_${i}.log#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^dir.*#dir /opt/redis/cluster/${i}/data#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "s#^appendonly no#appendonly yes#" /opt/redis/cluster/${i}/redis_${i}.conf
sed -i "\$acluster-enabled yes\ncluster-config-file /opt/redis/cluster/${i}/data/nodes-${i}.conf\ncluster-node-timeout 15000\nrequirepass abc@123\nmasterauth abc@123" /opt/redis/cluster/${i}/redis_${i}.conf
done
启动实例
for i in $(seq 9001 9006);
do
/opt/redis/cluster/bin/redis-server /opt/redis/cluster/${i}/redis_${i}.conf
done
创建集群 (--cluster-replicas 1 表示一个master后有几个slave,1代表为1个slave节点)
/opt/redis/cluster/bin/redis-cli -a abc@123 --cluster create 192.168.10.10:9001 192.168.10.10:9002 192.168.10.10:9003 192.168.10.10:9004 192.168.10.10:9005 192.168.10.10:9006 --cluster-replicas 1
#yes 回车
验证集群
/opt/redis/cluster/bin/redis-cli -a abc@123 -h 192.168.10.10 -c -p 9001 set redis cluster
OK
redis使用
登录:/opt/redis/cluster/bin/redis-cli -h 192.168.10.10 -p 9001 -a abc@123
查看各节点状态:cluster nodes
- 点赞
- 收藏
- 关注作者
评论(0)