文章目录
1、三主三从集群搭建
第一步: 各节点说明
RedisCluster最少需要三台主服务器,三台从服务器,效果图如下;
主节点对应点的端口号:7001、7002、7003;
从节点对应点的端口号:7004、7005、7006;
第二步: 集群搭建
1:创建7001实例:
-
创建安装目录:
[root@10 7001]# pwd /home/laosan/redis/redis-cluster/7001
-
安装redis
[root@10 src]# pwd /home/laosan/redis/redis-5.0.5/src [root@10 src]# make install PREFIX=/home/laosan/redis/redis-cluster/7001 CC Makefile.dep Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
-
拷贝redis.conf配置文件到7001/bin目录下
[root@10 bin]# cp /home/laosan/redis/redis-5.0.5/redis.conf /home/laosan/redis/redis-cluster/7001/bin/ [root@10 bin]# ls redis-benchmark redis-check-aof redis-check-rdb redis-cli redis.conf redis-sentinel redis-server
-
修改redis.conf配置文件
#注释掉 #bind 127.0.0.1 #是否开启保护模式,由yes该为no protected-mode no #端口改为7001 port 7001 #将`daemonize`由`no`改为`yes` daemonize yes #集群模式取消注释,改为yes cluster-enabled yes
2:复制7001到7002~7006实例:
-
拷贝实例:
[root@10 redis-cluster]# pwd /home/laosan/redis/redis-cluster [root@10 redis-cluster]# ls 7001 [root@10 redis-cluster]# cp -r 7001 7002 [root@10 redis-cluster]# cp -r 7001 7003 [root@10 redis-cluster]# cp -r 7001 7004 [root@10 redis-cluster]# cp -r 7001 7005 [root@10 redis-cluster]# cp -r 7001 7006 [root@10 redis-cluster]# ls 7001 7002 7003 7004 7005 7006
-
分别修改每一个实例中redis.conf端口
[root@10 redis-cluster]# vim 7002/bin/redis.conf port 7002 port 7003 port 7004 port 7005 port 7006
3:创建start.sh,启动所有的实例:
[root@10 redis-cluster]# vim start.sh
cd 7001/bin
./redis-server redis.conf
cd ..
cd ..
cd 7002/bin
./redis-server redis.conf
cd ..
cd ..
cd 7003/bin
./redis-server redis.conf
cd ..
cd ..
cd 7004/bin
./redis-server redis.conf
cd ..
cd ..
cd 7005/bin
./redis-server redis.conf
cd ..
cd ..
cd 7006/bin
./redis-server redis.conf
cd ..
cd ..
1.赋写和执行的权限
[root@10 redis-cluster]# chmod u+x start.sh
2.启动:
[root@10 redis-cluster]# ./start.sh
3.查看启动情况:
[root@10 redis-cluster]# ps -ef|grep redis
root 6661 1 0 01:20 ? 00:00:00 ./redis-server *:7001 [cluster]
root 6666 1 0 01:20 ? 00:00:00 ./redis-server *:7002 [cluster]
root 6668 1 0 01:20 ? 00:00:00 ./redis-server *:7003 [cluster]
root 6670 1 0 01:20 ? 00:00:00 ./redis-server *:7004 [cluster]
root 6675 1 0 01:20 ? 00:00:00 ./redis-server *:7005 [cluster]
root 6680 1 0 01:20 ? 00:00:00 ./redis-server *:7006 [cluster]
root 6691 3518 0 01:21 pts/1 00:00:00 grep --color=auto redis
4:创建Redis集群(redis里不要有数据):
1.创建集群:前三个ip加端口为master机器(此处将命令中127.0.0.1改为真是ip:192.168.0.106)
[root@10 bin]# ./redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7006 to 127.0.0.1:7002
Adding replica 127.0.0.1:7004 to 127.0.0.1:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 43e54e8b7fac43e6453316f43e7c60d4a605f5d2 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
M: 3454af47a2d7d8d64e5988ddefe2618ba09bc563 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
M: 8609afdfaff49639f77895ed7e6d3337df7e7412 127.0.0.1:7003
slots:[10923-16383] (5461 slots)<