1.根据《redis设计与实现》中搭建集群的方式,cluster meet后是主备master-slave,不是master-master
2.第二个slave加入集群时,需要另起cluster-config-file文件,不然起不来server
3 cluster meet后需要分配slot
4 redis-trib.rb脚本需要ruby环境
我的环境有一个6379端口的redis实例,想要创建redis,需要在本机上启动6381端口的实例,并开启集群功能
关键步骤
1.开启cluster-enabled
2.cluster meet <ip> <port>
测试过程
1.启动6381端口的redis实例
1.1配置文件。修改端口,开启cluster功能
[root@lzl redis-5.0.3]# cp redis6380.conf redis6381.conf
[root@lzl redis-5.0.3]# vi redis6381.conf
port修改为6381
cluster-enabled yes
1.2 开启6381端口的redis
/usr/local/redis-5.0.3/src/redis-server /usr/local/redis-5.0.3/redis6381.conf &
[1] 15408
[root@lzl redis-5.0.3]# 15408:C 29 Oct 2020 17:03:52.577 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15408:C 29 Oct 2020 17:03:52.577 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=15408, just started
15408:C 29 Oct 2020 17:03:52.577 # Configuration loaded
15408:M 29 Oct 2020 17:03:52.578 * Increased maximum number of open files to 10032 (it was originally set to 1024).
。。。
15408:M 29 Oct 2020 17:03:52.579 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
15408:M 29 Oct 2020 17:03:52.579 * DB loaded from disk: 0.000 seconds
15408:M 29 Oct 2020 17:03:52.580 * Ready to accept connections
1.3 验证6381是否开启集群功能
[root@lzl redis-5.0.3]# redis-cli -c -p 6381
127.0.0.1:6381> ping
PONG
127.0.0.1:6381> cluster nodes –仅有自己在集群中
f0e401c0b974fbaedb721e9c5827c7cbed5a9990 :6381@16381 myself,master – 0 0 0 connected 9394
2. 6379端口redis开启集群功能
2.1 开启cluster-enabled
[root@lzl ~]# redis-cli -c -p 6379
127.0.0.1:6379> cluster nodes
ERR This instance has cluster support disabled –默认redis没有开启集群功能,需要取消cluster-enabled yes的注释,并重启redis
127.0.0.1:6379> shutdown
not connected>
vi /usr/local/redis-5.0.3/redis.conf
cluster-enabled yes
[root@lzl ~]# redis-server /usr/local/redis-5.0.3/redis.conf &
[1] 15484
[root@lzl ~]# 15484:C 29 Oct 2020 17:16:42.672 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15484:C 29 Oct 2020 17:16:42.672 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=15484, just started
15484:C 29 Oct 2020 17:16:42.672 # Configuration loaded
15484:M 29 Oct 2020 17:16:42.673 * Increased maximum number of open files to 10032 (it was originally set to 1024).
…
9394. Taking responsibility for it.
15484:M 29 Oct 2020 17:16:42.697 * Ready to accept connections
[root@lzl ~]# 15484:M 29 Oct 2020 17:16:43.415 * Replica 127.0.0.1:6380 asks for synchronization
15484:M 29 Oct 2020 17:16:43.415 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '944904c9bf97e4be5e594e3458825b3323af931a', my replication IDs are 'f821378144a7c0e93c21aa0e47599d49c67fc0c5' and '0000000000000000000000000000000000000000')
15484:M 29 Oct 2020 17:16:43.415 * Starting BGSAVE for SYNC with target: disk
15484:M 29 Oct 2020 17:16:43.416 * Background saving started by pid 15488
15488:C 29 Oct 2020 17:16:43.424 * DB saved on disk
15488:C 29 Oct 2020 17:16:43.424 * RDB: 0 MB of memory used by copy-on-write
15484:M 29 Oct 2020 17:16:43.502 * Background saving terminated with success
15484:M 29 Oct 2020 17:16:43.502 * Synchronization with replica 127.0.0.1:6380 succeeded
2.2 检查6379是否开启cluster-enabled
[root@lzl ~]# redis-cli -p 6379
127.0.0.1:6379> cluster nodes
bcfcaa6308ede0cabcb8d192cd4b8b6327b5e9cc :6379@16379 myself,master – 0 0 0 connected 9394
127.0.0.1:6379> cluster meet 127.0.0.1 6381 –命令运行的同时添加节点的信息也打印在另一个节点上,敲meet命令的节点为cluster中的master。集群信息最好用cluster nodes看。role会看到主备信息。
127.0.0.1:6379> 15484:M 29 Oct 2020 17:21:05.738 # IP address for this node updated to 127.0.0.1 –自动输出的
15484:M 29 Oct 2020 17:21:06.141 * Replica 127.0.0.1:6381 asks for synchronization
15484:M 29 Oct 2020 17:21:06.141 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '439f66b6890df7430297509173dfc3737e02a7ca', my replication IDs are 'db5d1526eb65d0d662d3d4ab95a683584b18aad2' and '0000000000000000000000000000000000000000')
15484:M 29 Oct 2020 17:21:06.141 * Starting BGSAVE for SYNC with target: disk
15484:M 29 Oct 2020 17:21:06.141 * Background saving started by pid 15517
15517:C 29 Oct 2020 17:21:06.156 * DB saved on disk
15517:C 29 Oct 2020 17:21:06.156 * RDB: 0 MB of memory used by copy-on-write
15484:M 29 Oct 2020 17:21:06.171 * Background saving terminated with success
15484:M 29 Oct 2020 17:21:06.171 * Synchronization with replica 127.0.0.1:6381 succeeded
127.0.0.1:6379> cluster nodes
bcfcaa6308ede0cabcb8d192cd4b8b6327b5e9cc 127.0.0.1:6379@16379 myself,master – 0 0 1 connected 9394
f0e401c0b974fbaedb721e9c5827c7cbed5a9990 127.0.0.1:6381@16381 slave bcfcaa6308ede0cabcb8d192cd4b8b6327b5e9cc 0 1603963403179 1 connected
原文链接:https://blog.csdn.net/qq_40687433/article/details/110223225
原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/16575