Redis集群部署(二)

数据库干货铺

共 4863字,需浏览 10分钟

 ·

2022-03-05 01:50

点击上方蓝字关注我

经历了redis5.x之前(redis3.x或redis4.x)集群部署过程中ruby版本及各种依赖包蹂躏后,再感受一下redis5.x之后集群部署的便捷。

Redis4 Cluster部署

1、安装redis集群节点

因本次为伪分布式部署,生产环境部署时建议至少3台机器部署(其中每台机器1主1从),依旧和redis4.0.14的方式一样部署

ip
port
192.168.56.101
7000
192.168.56.101
7001
192.168.56.1017002
192.168.56.1017003
192.168.56.101
7004
192.168.56.101
7005

1.1 启动cluster各节点

创建数据目录

mkdir -p  /data/redis/cluster/{7000,7001,7002,7003,7004,7005}

配置文件中主要修改如下内容,其他的可按需调整,也可保持默认值,各节点中注意修改对应的端口号

bind 192.168.56.103port 7000daemonize yespidfile /data/redis/cluster/7000/redis_7000.pidlogfile "/data/redis/cluster/7000/redis_7000.log"appendonly yesappendfilename "appendonly.aof"appendfsync everyseccluster-enabled yescluster-config-file nodes-7000.conf     #注意此文件自动生成,且初始化时不要有和此重名的文件cluster-node-timeout 5000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage yescluster-slave-no-failover no

启动各节点,建议用redis用户启动

useradd redischown -R  redis:redis  /data/redis/su - rediscd /data/redis/cluster/7001cp /data/redis/cluster/7000/redis.conf . sed -i "s#7000#7001#g" redis.confredis-server redis.conf

其他节点和7001类似启动,启动后进程中会标记redis节点以cluster模式启动

2.  初始化集群

redis5.x之后的版本初始化集群相当便捷,命令及过程如下

redis-cli --cluster create --cluster-replicas 1 192.168.56.103:7000 192.168.56.103:7001 192.168.56.103:7002 192.168.56.103:7003 192.168.56.103:7004 192.168.56.103:7005>>> Performing hash slots allocation on 6 nodes...Master[0] -> Slots 0 - 5460Master[1] -> Slots 5461 - 10922Master[2] -> Slots 10923 - 16383Adding replica 192.168.56.103:7004 to 192.168.56.103:7000Adding replica 192.168.56.103:7005 to 192.168.56.103:7001Adding replica 192.168.56.103:7003 to 192.168.56.103:7002>>> Trying to optimize slaves allocation for anti-affinity[WARNING] Some slaves are in the same host as their masterM: 84ea774c08450db01bf5a518e3b9e55fd26d4d34 192.168.56.103:7000   slots:[0-5460] (5461 slots) masterM: eb98e53273fd348deb5eabcc6bfffc20484749b1 192.168.56.103:7001   slots:[5461-10922] (5462 slots) masterM: e059d418c11401189558d0f33bd5658297c10939 192.168.56.103:7002   slots:[10923-16383] (5461 slots) masterS: 23eed1c27ad11c685e5a226e2f82d5c0b6384c79 192.168.56.103:7003   replicates e059d418c11401189558d0f33bd5658297c10939S: cfa2549ea7782bb4f0ed6d45e9e3704a7d38d540 192.168.56.103:7004   replicates 84ea774c08450db01bf5a518e3b9e55fd26d4d34S: c3e14c4139bfa88af03ea97679715f051a122806 192.168.56.103:7005   replicates eb98e53273fd348deb5eabcc6bfffc20484749b1Can 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 clusterWaiting for the cluster to join.>>> Performing Cluster Check (using node 192.168.56.103:7000)M: 84ea774c08450db01bf5a518e3b9e55fd26d4d34 192.168.56.103:7000   slots:[0-5460] (5461 slots) master   1 additional replica(s)S: 23eed1c27ad11c685e5a226e2f82d5c0b6384c79 192.168.56.103:7003   slots: (0 slots) slave   replicates e059d418c11401189558d0f33bd5658297c10939M: eb98e53273fd348deb5eabcc6bfffc20484749b1 192.168.56.103:7001   slots:[5461-10922] (5462 slots) master   1 additional replica(s)S: c3e14c4139bfa88af03ea97679715f051a122806 192.168.56.103:7005   slots: (0 slots) slave   replicates eb98e53273fd348deb5eabcc6bfffc20484749b1S: cfa2549ea7782bb4f0ed6d45e9e3704a7d38d540 192.168.56.103:7004   slots: (0 slots) slave   replicates 84ea774c08450db01bf5a518e3b9e55fd26d4d34M: e059d418c11401189558d0f33bd5658297c10939 192.168.56.103:7002   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.

看到如下结果,代表成功配置并分配slot完成

查看各节点信息也可以用如下命令

[redis@localhost 7005]$ redis-cli -h 192.168.56.103 -p 7000 cluster nodes23eed1c27ad11c685e5a226e2f82d5c0b6384c79 192.168.56.103:7003@17003 slave e059d418c11401189558d0f33bd5658297c10939 0 1646118171000 4 connectedeb98e53273fd348deb5eabcc6bfffc20484749b1 192.168.56.103:7001@17001 master - 0 1646118171604 2 connected 5461-10922c3e14c4139bfa88af03ea97679715f051a122806 192.168.56.103:7005@17005 slave eb98e53273fd348deb5eabcc6bfffc20484749b1 0 1646118171000 6 connectedcfa2549ea7782bb4f0ed6d45e9e3704a7d38d540 192.168.56.103:7004@17004 slave 84ea774c08450db01bf5a518e3b9e55fd26d4d34 0 1646118170000 5 connectede059d418c11401189558d0f33bd5658297c10939 192.168.56.103:7002@17002 master - 0 1646118169590 3 connected 10923-1638384ea774c08450db01bf5a518e3b9e55fd26d4d34 192.168.56.103:7000@17000 myself,master - 0 1646118171000 1 connected 0-5460
往期精彩回顾

1.  MySQL高可用之MHA集群部署

2.  mysql8.0新增用户及加密规则修改的那些事

3.  比hive快10倍的大数据查询利器-- presto

4.  监控利器出鞘:Prometheus+Grafana监控MySQL、Redis数据库

5.  PostgreSQL主从复制--物理复制

6.  MySQL传统点位复制在线转为GTID模式复制

7.  MySQL敏感数据加密及解密

8.  MySQL数据备份及还原(一)

9.  MySQL数据备份及还原(二)

扫码关注     
浏览 46
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报