redis三主三从部署集群以及动态添加节点和删除节点

redis三主三从部署集群以及动态添加节点和删除节点,第1张

redis三主三从部署集群以及动态添加节点和删除节点 redis安装过程:

redis6.2.6安装与学习_wtl1992的博客-CSDN博客_redis6安装1、redis在Linux上的安装github地址:Releases · redis/redis · GitHubhttps://github.com/redis/redis/releases下载后,解压:yum install -y gcc然后:cd redis-6.2.6makemake install PREFIX=/data/soft/redis-6.2.6make的时候报错:致命错误:jemalloc/jemalloc.h:没有那个文件或目录解https://blog.csdn.net/wtl1992/article/details/121727360

主机分配: 主机IP192.168.233.201192.168.233.202192.168.233.203192.168.233.204192.168.233.205192.168.233.206 所有IP主机进行以下 *** 作:  编辑redis.conf:

 启动redis-server:
/etc/init.d/redis_init_script start

然后: 在其中一个主机节点上运行:
 ./redis-cli -a wtl1992 --cluster create  192.168.233.201:6379 192.168.233.202:6379 192.168.233.203:6379 192.168.233.204:6379 192.168.233.205:6379  192.168.233.206:6379 --cluster-replicas 1
[root@192 bin]# ./redis-cli -a wtl1992 --cluster create  192.168.233.201:6379 192.168.233.202:6379 192.168.233.203:6379 192.168.233.204:6379 192.168.233.205:6379  192.168.233.206:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.233.205:6379 to 192.168.233.201:6379
Adding replica 192.168.233.206:6379 to 192.168.233.202:6379
Adding replica 192.168.233.204:6379 to 192.168.233.203:6379
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379
   slots:[0-5460] (5461 slots) master
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379
   slots:[5461-10922] (5462 slots) master
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379
   slots:[10923-16383] (5461 slots) master
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379
   replicates c6b66129b403c69d8a4cdefba835d230e642bd1b
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379
   replicates a3af0897c202515165659b21478405c01b87e2af
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379
   replicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.233.201:6379)
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379
   slots: (0 slots) slave
   replicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379
   slots: (0 slots) slave
   replicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379
   slots: (0 slots) slave
   replicates c6b66129b403c69d8a4cdefba835d230e642bd1b
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
检查健康状态:
 ./redis-cli -a wtl1992 --cluster  check 192.168.233.202:6379

check后面的IP可以是以上的IP中的一个。

集群连接:
./redis-cli -c -a wtl1992 -h 192.168.233.202 -p 6379
查看状态:
./redis-cli -a wtl1992 cluster nodes

 -a 是auth的意思,意思是授权密码。

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

动态添加一对主从节点: 主机IP192.168.233.207192.168.233.208 查看状态:
./redis-cli -a wtl1992 cluster nodes

 -a 是auth的意思,意思是授权密码。

添加一组集群节点:

方法:先添加主节点,然后添加从节点

添加主节点:
redis-cli --cluster add-node 新节点IP:端口 已存在节点IP:端口 
./redis-cli -a wtl1992 --cluster add-node 192.168.233.207:6379 192.168.233.205:6379
[root@192 bin]# ./redis-cli -a wtl1992 --cluster add-node 192.168.233.207:6379 192.168.233.205:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.233.207:6379 to cluster 192.168.233.205:6379
>>> Performing Cluster Check (using node 192.168.233.205:6379)
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379
   slots: (0 slots) slave
   replicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379
   slots: (0 slots) slave
   replicates c6b66129b403c69d8a4cdefba835d230e642bd1b
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379
   slots: (0 slots) slave
   replicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.233.207:6379 to make it join the cluster.
[OK] New node added correctly.

 添加新节点 (添加从节点):

--slave:设置该参数,则新节点以slave的角色加入集群 
--master-id:这个参数需要设置了--slave才能生效,--master-id用来指定新节点的master节点。如果不设置该参数,则会随机为节点选择master节点。

./redis-cli -a wtl1992 --cluster add-node  新节点IP地址:端口    存在节点IP:端口 --cluster-slave --cluster-master-id (master节点的ID)

./redis-cli -a wtl1992 --cluster add-node 192.168.233.208:6379 192.168.233.207:6379 --cluster-slave  --cluster-master-id 68df4ed4c8798625124bc13ce9671d4f6f85b345
[root@192 bin]# ./redis-cli -a wtl1992 --cluster add-node 192.168.233.208:6379 192.168.233.207:6379 --cluster-slave  --cluster-master-id 68df4ed4c8798625124bc13ce9671d4f6f85b345
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.233.208:6379 to cluster 192.168.233.207:6379
>>> Performing Cluster Check (using node 192.168.233.207:6379)
M: 68df4ed4c8798625124bc13ce9671d4f6f85b345 192.168.233.207:6379
   slots: (0 slots) master
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379
   slots: (0 slots) slave
   replicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379
   slots: (0 slots) slave
   replicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379
   slots: (0 slots) slave
   replicates c6b66129b403c69d8a4cdefba835d230e642bd1b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.233.208:6379 to make it join the cluster.
Waiting for the cluster to join

>>> Configure node as replica of 192.168.233.207:6379.
[OK] New node added correctly.
上面新增的master和slave不能分片,所以要重新集群内平衡!!!  rebalance平衡集群节点slot数量: 语法:
rebalance       host:port
                --weight 
                --auto-weights
                --threshold 
                --use-empty-masters
                --timeout 
                --simulate
                --pipeline 
 
host:port:这个是必传参数,用来从一个节点获取整个集群信息,相当于获取集群信息的入口。
--weight :节点的权重,格式为node_id=weight,如果需要为多个节点分配权重的话,需要添加多个--weight 参数,即--weight b31e3a2e=5 --weight 60b8e3a1=5,node_id可为节点名称的前缀,只要保证前缀位数能唯一区分该节点即可。没有传递–weight的节点的权重默认为1。
--auto-weights:这个参数在rebalance流程中并未用到。
--threshold :只有节点需要迁移的slot阈值超过threshold,才会执行rebalance *** 作。具体计算方法可以参考下面的rebalance命令流程的第四步。
--use-empty-masters:rebalance是否考虑没有节点的master,默认没有分配slot节点的master是不参与rebalance的,设置--use-empty-masters可以让没有分配slot的节点参与rebalance。
--timeout :设置migrate命令的超时时间。
--simulate:设置该参数,可以模拟rebalance *** 作,提示用户会迁移哪些slots,而不会真正执行迁移 *** 作。
--pipeline :与reshar的pipeline参数一样,定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10。
./redis-cli -a wtl1992 --cluster rebalance 192.168.233.207:6379 --cluster-threshold 1 --cluster-use-empty-masters --cluster-pipeline 10
[root@192 bin]# ./redis-cli -a wtl1992 --cluster rebalance 192.168.233.207:6379 --cluster-threshold 1 --cluster-use-empty-masters --cluster-pipeline 10
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.233.207:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 4 nodes. Total weight = 4.00
Moving 1366 slots from 192.168.233.202:6379 to 192.168.233.207:6379
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving 1365 slots from 192.168.233.201:6379 to 192.168.233.207:6379
#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving 1365 slots from 192.168.233.203:6379 to 192.168.233.207:6379
#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

 

 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

从集群彻底删除节点: 查看状态:
./redis-cli -a wtl1992 cluster nodes

 

 从集群中移除 node_id 指定的节点: 
redis-cli cluster forget 68df4ed4c8798625124bc13ce9671d4f6f85b345
 
返回
OK
 
### 从集群中删除节点 
del-node可以把某个节点从集群中删除。del-node只能删除没有分配slot的节点。删除命令传递两个参数:
 
host:port:从该节点获取集群信息。
node_id:需要删除的节点id。
 
redis-cli cluster del-node 192.168.233.207:6379  68df4ed4c8798625124bc13ce9671d4f6f85b345

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5715372.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存