CentOS 1908 配置 Redis 5.0.7 四(集群配置)

忘是亡心i 2023-07-04 08:50 88阅读 0赞

CentOS 下载:http://mirrors.aliyun.com/centos/

Redis:http://download.redis.io/releases/

CentOS 1908 配置 Redis 5.0.7 一(单节点)

CentOS 1908 配置 Redis 5.0.7 二(主从复制)

CentOS 1908 配置 Redis 5.0.7 三(哨兵模式)

CentOS 1908 配置 Redis 5.0.7 五(集群新增 主从节点)​​​​​​​


  1. 安装 Redis 参见:CentOS 1908 配置 Redis 5.0.7 一(单节点)

  2. 进入 Redis 文件夹:

    1. [root@192 ~]# cd redis-5.0.7/
    2. [root@192 redis-5.0.7]#
  3. 创建集群文件夹并复制集群配置文件:

    1. mkdir cluster
    2. cd cluster
    3. cp ../redis.conf ./redis-6001.conf
    4. cp ../redis.conf ./redis-6002.conf
    5. cp ../redis.conf ./redis-6003.conf
    6. cp ../redis.conf ./redis-6004.conf
    7. cp ../redis.conf ./redis-6005.conf
    8. cp ../redis.conf ./redis-6006.conf
  4. 修改配置文件:

    1. 修改 redis6001.conf 文件:

      1. # 注释掉(远程连接)
      2. # bind 127.0.0.1
      3. # 将 yes 改为 no(取消保护)
      4. protected-mode no
      5. # 将端口改为 6001
      6. port 6001
      7. # 开启后台运行
      8. daemonize yes
      9. # 修改 pid 文件名
      10. pidfile /var/run/redis_6001.pid
      11. # 取消注释
      12. cluster-enabled yes
      13. # 集群配置文件
      14. cluster-config-file nodes-6001.conf
    2. 其他文件修改内容参看上面。
  5. 创建启动、停止 Redis 脚本:

    1. 启动脚本:

      1. vim start-all.sh

      内容如下:

      1. ../src/redis-server redis-6001.conf
      2. ../src/redis-server redis-6002.conf
      3. ../src/redis-server redis-6003.conf
      4. ../src/redis-server redis-6004.conf
      5. ../src/redis-server redis-6005.conf
      6. ../src/redis-server redis-6006.conf
    2. 停止脚本:

      1. vim stop-all.sh

      内容如下:

      1. ../src/redis-cli -p 6001 shutdown
      2. ../src/redis-cli -p 6002 shutdown
      3. ../src/redis-cli -p 6003 shutdown
      4. ../src/redis-cli -p 6004 shutdown
      5. ../src/redis-cli -p 6005 shutdown
      6. ../src/redis-cli -p 6006 shutdown
  6. 给启动脚本授权:

    1. chmod +x start-all.sh
    2. chmod +x stop-all.sh
  7. 启动:

    1. [root@192 cluster]# ./start-all.sh
    2. 12163:C 17 Feb 2020 19:20:37.432 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    3. 12163:C 17 Feb 2020 19:20:37.432 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12163, just started
    4. 12163:C 17 Feb 2020 19:20:37.432 # Configuration loaded
    5. 12165:C 17 Feb 2020 19:20:37.438 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    6. 12165:C 17 Feb 2020 19:20:37.438 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12165, just started
    7. 12165:C 17 Feb 2020 19:20:37.438 # Configuration loaded
    8. 12170:C 17 Feb 2020 19:20:37.445 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    9. 12170:C 17 Feb 2020 19:20:37.445 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12170, just started
    10. 12170:C 17 Feb 2020 19:20:37.445 # Configuration loaded
    11. 12175:C 17 Feb 2020 19:20:37.453 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12. 12175:C 17 Feb 2020 19:20:37.453 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12175, just started
    13. 12175:C 17 Feb 2020 19:20:37.453 # Configuration loaded
    14. 12180:C 17 Feb 2020 19:20:37.459 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    15. 12180:C 17 Feb 2020 19:20:37.459 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12180, just started
    16. 12180:C 17 Feb 2020 19:20:37.459 # Configuration loaded
    17. 12185:C 17 Feb 2020 19:20:37.464 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    18. 12185:C 17 Feb 2020 19:20:37.464 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12185, just started
    19. 12185:C 17 Feb 2020 19:20:37.464 # Configuration loaded
    20. [root@192 cluster]#
  8. 开通端口:

    1. firewall-cmd --zone=public --add-port=6001/tcp --permanent
    2. firewall-cmd --zone=public --add-port=6002/tcp --permanent
    3. firewall-cmd --zone=public --add-port=6003/tcp --permanent
    4. firewall-cmd --zone=public --add-port=6004/tcp --permanent
    5. firewall-cmd --zone=public --add-port=6005/tcp --permanent
    6. firewall-cmd --zone=public --add-port=6006/tcp --permanent
    7. firewall-cmd --reload
    8. firewall-cmd --list-all
  9. 创建集群:
    必须使用 IP(否则远程连接不上):

    1. ../src/redis-cli --cluster create --cluster-replicas 1 192.168.8.133:6001 192.168.8.133:6002 192.168.8.133:6003 192.168.8.133:6004 192.168.8.133:6005 192.168.8.133:6006

    信息如下:
    中间有提示,输入:yes

    1. >>> Performing hash slots allocation on 6 nodes...
    2. Master[0] -> Slots 0 - 5460
    3. Master[1] -> Slots 5461 - 10922
    4. Master[2] -> Slots 10923 - 16383
    5. Adding replica 192.168.8.133:6005 to 192.168.8.133:6001
    6. Adding replica 192.168.8.133:6006 to 192.168.8.133:6002
    7. Adding replica 192.168.8.133:6004 to 192.168.8.133:6003
    8. >>> Trying to optimize slaves allocation for anti-affinity
    9. [WARNING] Some slaves are in the same host as their master
    10. M: 027e733678b9ccfc8b6d858d2870a6334916935f 192.168.8.133:6001
    11. slots:[0-5460] (5461 slots) master
    12. M: 37487e6b499a3df65a7310bf5e4f4f001f89f135 192.168.8.133:6002
    13. slots:[5461-10922] (5462 slots) master
    14. M: b4aead46397e77100c4ddc185e851d2d3ec7cf6d 192.168.8.133:6003
    15. slots:[10923-16383] (5461 slots) master
    16. S: 1c5d1767aa7aff049d9cfd025d153e5f430ef8cc 192.168.8.133:6004
    17. replicates 027e733678b9ccfc8b6d858d2870a6334916935f
    18. S: eb8a86ac1243a325605022e332f278405ea72143 192.168.8.133:6005
    19. replicates 37487e6b499a3df65a7310bf5e4f4f001f89f135
    20. S: 0c747138624559b89876b9b7a9309ff2d5540f1a 192.168.8.133:6006
    21. replicates b4aead46397e77100c4ddc185e851d2d3ec7cf6d
    22. Can I set the above configuration? (type 'yes' to accept): yes
    23. >>> Nodes configuration updated
    24. >>> Assign a different config epoch to each node
    25. >>> Sending CLUSTER MEET messages to join the cluster
    26. Waiting for the cluster to join
    27. ....
    28. >>> Performing Cluster Check (using node 192.168.8.133:6001)
    29. M: 027e733678b9ccfc8b6d858d2870a6334916935f 192.168.8.133:6001
    30. slots:[0-5460] (5461 slots) master
    31. 1 additional replica(s)
    32. S: 1c5d1767aa7aff049d9cfd025d153e5f430ef8cc 192.168.8.133:6004
    33. slots: (0 slots) slave
    34. replicates 027e733678b9ccfc8b6d858d2870a6334916935f
    35. S: 0c747138624559b89876b9b7a9309ff2d5540f1a 192.168.8.133:6006
    36. slots: (0 slots) slave
    37. replicates b4aead46397e77100c4ddc185e851d2d3ec7cf6d
    38. S: eb8a86ac1243a325605022e332f278405ea72143 192.168.8.133:6005
    39. slots: (0 slots) slave
    40. replicates 37487e6b499a3df65a7310bf5e4f4f001f89f135
    41. M: 37487e6b499a3df65a7310bf5e4f4f001f89f135 192.168.8.133:6002
    42. slots:[5461-10922] (5462 slots) master
    43. 1 additional replica(s)
    44. M: b4aead46397e77100c4ddc185e851d2d3ec7cf6d 192.168.8.133:6003
    45. slots:[10923-16383] (5461 slots) master
    46. 1 additional replica(s)
    47. [OK] All nodes agree about slots configuration.
    48. >>> Check for open slots...
    49. >>> Check slots coverage...
    50. [OK] All 16384 slots covered.
    51. [root@192 cluster]#
  10. 查看集群状态:

    1. [root@192 cluster]# ../src/redis-cli --cluster info 192.168.8.133:6001
    2. 192.168.8.133:6001 (027e7336...) -> 0 keys | 5461 slots | 1 slaves.
    3. 192.168.8.133:6002 (37487e6b...) -> 0 keys | 5462 slots | 1 slaves.
    4. 192.168.8.133:6003 (b4aead46...) -> 0 keys | 5461 slots | 1 slaves.
    5. [OK] 0 keys in 3 masters.
    6. 0.00 keys per slot on average.
    7. [root@192 cluster]#

发表评论

表情:
评论列表 (有 0 条评论,88人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Redis配置

    Redis集群向导   本文不打算介绍复杂的分布式系统的概念,而仅作为一个入门介绍。旨在从用户的角度提供如何进行redis的配置,测试和操作。详细的配置参照[https://

    相关 redis配置

    在两台服务器redis实现集群 在两台服务器redis实现集群: 描述 1. 服务器列表: — A服务器:192.168.4.254 —

    相关 Redis配置

    1、集群规划 要让Redis4.0.1集群正常工作至少需要3个Master节点,每个 Master 节点要配备至少 1 个 Slave 节点。 根据以上特点和要求, 进行如下