Talk Is Cheap!!!✨|

Journey&Flower

园龄:7年3个月粉丝:40关注:121

Redis集群启动

要设置 Redis 集群启动,可以遵循以下步骤:

步骤 1: 下载和安装 Redis

首先,需要下载并安装 Redis。可以从 Redis 官方网站下载适合您系统的 Redis 版本。

步骤 2: 配置 Redis 节点

  1. 在每个节点上编辑 Redis 配置文件(redis.conf),确保配置文件启用集群模式(cluster-enabled yes)。
  2. 设置节点的端口号(cluster-node-port)和初始主节点槽分配。

步骤 3: 启动 Redis 节点

  1. 启动每个 Redis 节点,可以使用以下命令启动 Redis: redis-server /path/to/redis.conf

步骤 4: 创建 Redis 集群

  1. 在其中一个节点上运行以下命令来创建 Redis 集群:
redis-cli --cluster create <node1_ip>:<port> <node2_ip>:<port> ... --cluster-replicas <number_of_replicas>

请替换 <node1_ip>:<port>, <node2_ip>:<port>等为实际节点的 IP 地址和端口号,<number_of_replicas> 替换为集群数量,根据集群中实例个数指定。

步骤 5: 验证集群

  1. 使用以下命令检查集群的状态:
redis-cli -c -h <any_node_ip> -p <port> cluster info

步骤 6: 实操记录

问题 1:
# export REDISCLI_AUTH=你的redis密码
# redis-cli --cluster create 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 --cluster-replicas 3
[ERR] Node 192.168.40.128:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
# redis-cli --cluster create 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 --cluster-replicas 3
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 3 replicas per node.
*** At least 12 nodes are required.
# redis-cli --cluster create 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 --cluster-replicas 2
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 2 replicas per node.
*** At least 9 nodes are required.
# redis-cli --cluster create 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 --cluster-replicas 1
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 1 replicas per node.
*** At least 6 nodes are required.
# redis-cli --cluster create 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 --cluster-replicas 0
>>> Performing hash slots allocation on 3 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: fbb08b2669a46f9590d0eca0d5e8abc86627e7f2 192.168.40.128:7001
   slots:[0-5460] (5461 slots) master
M: 1f523d416b0cf931e6cba250b37dccdafadce0a3 192.168.40.128:7002
   slots:[5461-10922] (5462 slots) master
M: a77d78c5429a25d7cc78859c0fae7ce0106be65a 192.168.40.128:7003
   slots:[10923-16383] (5461 slots) master
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
........................

如果以上永远等待加入集群,不能成功,请检查集群成员之间的通讯

问题 2:
# export REDISCLI_AUTH=你的redis密码
# redis-cli --cluster create 172.18.0.3:7001 172.18.0.6:7002 172.18.0.5:7003 172.18.0.8:7004 172.18.0.9:7005 172.18.0.10:7006 --cluster-replicas 1
[ERR] Node 172.18.0.3:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

解决方案:

1 remove the aof/rdb backup file
1 删除 AOF/RDB 备份文件
2 remove the node_conf file
2 删除node_conf文件
3 flushdb if necessary
3 flushdb(如有必要)
https://github.com/redis/redis/issues/3154

搭建成功

# export REDISCLI_AUTH=你的密码
# redis-cli --cluster create 172.18.0.3:7001 172.18.0.6:7002 172.18.0.5:7003 172.18.0.8:7004 172.18.0.9:7005 172.18.0.10:7006 --cluster-replicas 1
Could not connect to Redis at 172.18.0.10:7006: Connection refused
# redis-cli --cluster create 172.18.0.3:7001 172.18.0.6:7002 172.18.0.5:7003 172.18.0.8:7004 172.18.0.9:7005 172.18.0.10: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 172.18.0.9:7005 to 172.18.0.3:7001
Adding replica 172.18.0.10:7006 to 172.18.0.6:7002
Adding replica 172.18.0.8:7004 to 172.18.0.5:7003
M: ab9f9a5abcfcd35e9b48a19a7d760e653270e8ca 172.18.0.3:7001
   slots:[0-5460] (5461 slots) master
M: b682c1da0f297046c9a263c7738badd2e71d3c0e 172.18.0.6:7002
   slots:[5461-10922] (5462 slots) master
M: 33a085f7652fe0e5d56727e72aafd7fc7bdc5a89 172.18.0.5:7003
   slots:[10923-16383] (5461 slots) master
S: 2b405e1f4da0392d26f78dc8359e8f45cc7139b7 172.18.0.8:7004
   replicates 33a085f7652fe0e5d56727e72aafd7fc7bdc5a89
S: c1cafc13edb73a27937db608557d160cf53f1524 172.18.0.9:7005
   replicates ab9f9a5abcfcd35e9b48a19a7d760e653270e8ca
S: ec85b1cb9543e7a735677cfd866e34931172d5e2 172.18.0.10:7006
   replicates b682c1da0f297046c9a263c7738badd2e71d3c0e
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 172.18.0.3:7001)
M: ab9f9a5abcfcd35e9b48a19a7d760e653270e8ca 172.18.0.3:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: c1cafc13edb73a27937db608557d160cf53f1524 172.18.0.9:7005
   slots: (0 slots) slave
   replicates ab9f9a5abcfcd35e9b48a19a7d760e653270e8ca
M: b682c1da0f297046c9a263c7738badd2e71d3c0e 172.18.0.6:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 2b405e1f4da0392d26f78dc8359e8f45cc7139b7 172.18.0.8:7004
   slots: (0 slots) slave
   replicates 33a085f7652fe0e5d56727e72aafd7fc7bdc5a89
M: 33a085f7652fe0e5d56727e72aafd7fc7bdc5a89 172.18.0.5:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: ec85b1cb9543e7a735677cfd866e34931172d5e2 172.18.0.10:7006
   slots: (0 slots) slave
   replicates b682c1da0f297046c9a263c7738badd2e71d3c0e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# 
问题 3:
1:S 20 Jun 2024 16:10:09.527 * MASTER <-> REPLICA sync started
1:S 20 Jun 2024 16:10:09.527 * Non blocking connect for SYNC fired the event.
1:S 20 Jun 2024 16:10:09.527 * Master replied to PING, replication can continue...
1:S 20 Jun 2024 16:10:09.528 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
1:S 20 Jun 2024 16:10:09.528 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
1:S 20 Jun 2024 16:10:09.528 * Trying a partial resynchronization (request 9567d66cf904b5cd195e2d0cbc403b56e45507d7:1).
1:S 20 Jun 2024 16:10:09.528 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
1:S 20 Jun 2024 16:10:09.528 * Retrying with SYNC...
1:S 20 Jun 2024 16:10:09.528 # MASTER aborted replication with an error: NOAUTH Authentication required.
1:S 20 Jun 2024 16:10:09.528 * Reconnecting to MASTER 172.18.0.6:7002 after failure

解决方案:

对 Redis 的配置文件 redis.conf 进行一些调整,以便节点键的身份验证通过,并启用部分同步。以下是一些关键的配置选项及其说明:

  1. requirepass: 设置密码,以便客户端在连接到 Redis 服务器时进行身份验证。

  2. cluster-require-full-coverage: 设置为 no,以允许 Redis 集群在部分节点不可用时继续运行。

  3. sync: 设置为 partial,以启用部分同步。
    修改 redis.conf 文件的示例:

# 设置密码
requirepass yourpassword
# 允许集群在部分节点不可用时继续运行
cluster-require-full-coverage no

注意事项:

  • 确保节点可以相互通信。
  • 了解 Redis 集群的故障转移和分片策略。
  • 定期进行监控和维护集群,以确保高可用性和性能。
  • 如果没有slave界面也就是 cluster-replicas 0 可能会失败

本文转载:https://blog.csdn.net/weixin_42759398/article/details/137406711

本文作者:Journey&Flower

本文链接:https://www.cnblogs.com/JourneyOfFlower/p/18143526

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Journey&Flower  阅读(361)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 Not Found REOL
  2. 2 白色恋人 游鸿明
  3. 3 盛夏的果实 莫文蔚
  4. 4 以父之名 周杰伦
  5. 5 晴天 周杰伦
  6. 6 简单爱 周杰伦
  7. 7 东风破 周杰伦
  8. 8 稻香 周杰伦
  9. 9 爱在西元前 周杰伦
  10. 10 千里之外 费玉清-周杰伦
  11. 11 偏爱 张芸京
  12. 12 大海 张雨生
  13. 13 月亮惹的祸 张宇
  14. 14 雨一直下 张宇
  15. 15 过火 张信哲
  16. 16 隐形的翅膀 张韶涵
  17. 17 天下 张杰
  18. 18 当你孤单你会想起谁 张栋梁
  19. 19 清明雨上 许嵩
  20. 20 玫瑰花的葬礼 许嵩
  21. 21 断桥残雪 许嵩
  22. 22 城府 许嵩
  23. 23 等一分钟 徐誉滕
  24. 24 客官不可以 徐良_小凌
  25. 25 坏女孩 徐良_小凌
  26. 26 犯贱 徐良
  27. 27 菠萝菠萝蜜 谢娜
  28. 28 贝多芬的悲伤 萧风
  29. 29 睫毛弯弯 王心凌
  30. 30 我不是黄蓉 王蓉
  31. 31 秋天不回来 王强
  32. 32 今天你要嫁给我 陶喆,蔡依林
  33. 33 丁香花 唐磊
  34. 34 绿光 孙燕姿
  35. 35 求佛 誓言
  36. 36 十一年 邱永传
  37. 37 下辈子如果我还记得你 马郁
  38. 38 一千年以后 林俊杰
  39. 39 江南 林俊杰
  40. 40 曹操 林俊杰
  41. 41 背对背拥抱 林俊杰
  42. 42 会呼吸的痛 梁静茹
  43. 43 勇气 梁静茹
  44. 44 爱你不是两三天 梁静茹
  45. 45 红日 李克勤
  46. 46 星月神话 金莎
  47. 47 嘻唰唰 花儿乐队
  48. 48 穷开心 花儿乐队
  49. 49 六月的雨-《仙剑奇侠传》电视剧插曲 胡歌
  50. 50 一个人的寂寞两个人的错 贺一航
  51. 51 好想好想-《情深深雨濛濛》电视剧片尾曲 古巨基
  52. 52 情人 刀郎
  53. 53 冲动的惩罚 刀郎
  54. 54 西海情歌 刀郎
  55. 55 2002年的第一场雪 刀郎
  56. 56 红玫瑰 陈奕迅
  57. 57 浮夸 陈奕迅
  58. 58 爱情转移 陈奕迅
  59. 59 独家记忆 陈小春
  60. 60 记事本 陈慧琳
  61. 61 看我72变 蔡依林
  62. 62 寂寞在唱歌 阿桑
  63. 63 樱花草 Sweety
  64. 64 中国话 S.H.E
  65. 65 波斯猫 S.H.E
  66. 66 杀破狼-《仙剑奇侠传》电视剧片头曲 JS
  67. 67 Lydia F.I.R.
  68. 68 I Miss You 罗百吉_青春美少女.
白色恋人 - 游鸿明
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : 林利南

作曲 : 游鸿明

编曲 : 涂惠源

冷空气 却清晰

你在南极冰山雪地里

极光中雪白的肌肤

是哀愁是美丽

为了要遇见你

我连呼吸都反复练习

兰伯特仁慈的冰川

带领我走向你

零下九十一度的酷寒

滚滚红尘千年的呼喊

藏在沃斯托克的湖岸

沉寂轻叹

撒哈拉漫天狂沙 金字塔谁能解答

兵马俑谁与争锋 长城万里相逢

人世间悲欢聚散 一页页写在心上

含着泪白色恋人 却有灰色的年轮

零下九十一度的酷寒

滚滚红尘千年的呼喊

藏在沃斯托克的湖岸

沉静轻叹

撒哈拉漫天狂沙 金字塔谁能解答

兵马俑谁与争锋 长城万里相逢

人世间悲欢聚散 一页页写在心上

含着泪白色恋人 却有灰色的年轮

撒哈拉漫天狂沙 金字塔谁能解答

兵马俑谁与争锋 长城万里相逢

人世间悲欢聚散 一页页写在心上

含着泪白色恋人 却有灰色的年轮