基于Centos7.9部署Redis集群环境

时间:2023年6月3日
Linux版本:Centos 7.9

1.集群网络配置

准备6台虚拟机,配置同一个网段,IP地址如下:

Redis集群-测试库
Redis连接:
192.168.10.71:6379
192.168.10.72:6379
192.168.10.73:6379
192.168.10.91:6379
192.168.10.92:6379
192.168.10.93:6379

Redis密码:
86a1b907d54bf7010394bf316e183e67

2.安装redis

每台机器均执行以下操作,安装redis和放开防火墙端口

yum install epel-release -y
yum install redis -y

systemctl restart redis
systemctl enable redis
systemctl status redis


firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --add-port=6380/tcp --permanent
firewall-cmd --add-port=16379/tcp --permanent
firewall-cmd --reload

3.修改配置文件

路径:/etc/redis.conf每个节点都需修改,bind ip以实际为准

bind 192.168.10.71
cluster-enabled yes
masterauth '86a1b907d54bf7010394bf316e183e67'
requirepass '86a1b907d54bf7010394bf316e183e67'

修改完后执行重启服务
systemctl restart redis

4.配置集群

redis-cli -h 192.168.10.71 -p 6379 -a 86a1b907d54bf7010394bf316e183e67 cluster nodes

[root@node71 ~]# redis-cli -h 192.168.10.71 -p 6379 -a 86a1b907d54bf7010394bf316e183e67 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
ab5b9040aa84704aa44e977b410ecd9f86227987 :6379 myself,master - 0 0 0 connected

[root@node71 mysqld_exporter]# redis-cli --cluster create 192.168.10.71:6379 192.168.10.72:6379 192.168.10.73:6379 192.168.10.91:6379 192.168.10.92:6379 192.168.10.93:6379 --cluster-replicas 1 -a 86a1b907d54bf7010394bf316e183e67
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.10.92:6379 to 192.168.10.71:6379
Adding replica 192.168.10.93:6379 to 192.168.10.72:6379
Adding replica 192.168.10.91:6379 to 192.168.10.73:6379
M: ab5b9040aa84704aa44e977b410ecd9f86227987 192.168.10.71:6379
   slots:[0-5460] (5461 slots) master
M: d9a7b832cb43346df9406b640dc1590cbce35dbb 192.168.10.72:6379
   slots:[5461-10922] (5462 slots) master
M: cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb 192.168.10.73:6379
   slots:[10923-16383] (5461 slots) master
S: 00d82af292410901b8afda616188c5d706cf7aa1 192.168.10.91:6379
   replicates cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb
S: 781262f783c114a27b12db5fb563ea4a2e74d4e2 192.168.10.92:6379
   replicates ab5b9040aa84704aa44e977b410ecd9f86227987
S: c53e8ac7858b8892f6e8aafc7d4334ef3f451f94 192.168.10.93:6379
   replicates d9a7b832cb43346df9406b640dc1590cbce35dbb
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.10.71:6379)
M: ab5b9040aa84704aa44e977b410ecd9f86227987 192.168.10.71:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 781262f783c114a27b12db5fb563ea4a2e74d4e2 192.168.10.92:6379
   slots: (0 slots) slave
   replicates ab5b9040aa84704aa44e977b410ecd9f86227987
M: d9a7b832cb43346df9406b640dc1590cbce35dbb 192.168.10.72:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 00d82af292410901b8afda616188c5d706cf7aa1 192.168.10.91:6379
   slots: (0 slots) slave
   replicates cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb
M: cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb 192.168.10.73:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: c53e8ac7858b8892f6e8aafc7d4334ef3f451f94 192.168.10.93:6379
   slots: (0 slots) slave
   replicates d9a7b832cb43346df9406b640dc1590cbce35dbb
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

5.查看节点

[root@node71 mysqld_exporter]# redis-cli -h 192.168.10.71 -p 6379 -a 86a1b907d54bf7010394bf316e183e67 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.10.71:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:1753
cluster_stats_messages_received:1753

192.168.10.71:6379> cluster nodes
781262f783c114a27b12db5fb563ea4a2e74d4e2 192.168.10.92:6379 slave ab5b9040aa84704aa44e977b410ecd9f86227987 0 1686623763541 5 connected
d9a7b832cb43346df9406b640dc1590cbce35dbb 192.168.10.72:6379 master - 0 1686623765546 2 connected 5461-10922
00d82af292410901b8afda616188c5d706cf7aa1 192.168.10.91:6379 slave cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb 0 1686623759523 4 connected
cf991d4a6fb1ed70764fa9d46c25b3f07e070bdb 192.168.10.73:6379 master - 0 1686623760526 3 connected 10923-16383
ab5b9040aa84704aa44e977b410ecd9f86227987 192.168.10.71:6379 myself,master - 0 0 1 connected 0-5460
c53e8ac7858b8892f6e8aafc7d4334ef3f451f94 192.168.10.93:6379 slave d9a7b832cb43346df9406b640dc1590cbce35dbb 0 1686623764546 6 connected
192.168.10.71:6379> exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值