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

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 文件夹:
    [root@192 ~]# cd redis-5.0.7/
    [root@192 redis-5.0.7]# 
    
  3. 创建集群文件夹并复制集群配置文件:
    mkdir cluster
    cd cluster
    cp ../redis.conf ./redis-6001.conf
    cp ../redis.conf ./redis-6002.conf
    cp ../redis.conf ./redis-6003.conf
    cp ../redis.conf ./redis-6004.conf
    cp ../redis.conf ./redis-6005.conf
    cp ../redis.conf ./redis-6006.conf
  4. 修改配置文件:
    1. 修改 redis6001.conf 文件:
      # 注释掉(远程连接)
      # bind 127.0.0.1
      
      # 将 yes 改为 no(取消保护)
      protected-mode no
      
      # 将端口改为 6001
      port 6001
      
      # 开启后台运行
      daemonize yes
      
      # 修改 pid 文件名
      pidfile /var/run/redis_6001.pid
      
      # 取消注释
      cluster-enabled yes
      
      # 集群配置文件
      cluster-config-file nodes-6001.conf
    2. 其他文件修改内容参看上面。
  5. 创建启动、停止 Redis 脚本:
    1. 启动脚本:
      vim start-all.sh
      内容如下:
      ../src/redis-server redis-6001.conf
      ../src/redis-server redis-6002.conf
      ../src/redis-server redis-6003.conf
      ../src/redis-server redis-6004.conf
      ../src/redis-server redis-6005.conf
      ../src/redis-server redis-6006.conf
    2. 停止脚本:
      vim stop-all.sh
      内容如下:
      ../src/redis-cli -p 6001 shutdown
      ../src/redis-cli -p 6002 shutdown
      ../src/redis-cli -p 6003 shutdown
      ../src/redis-cli -p 6004 shutdown
      ../src/redis-cli -p 6005 shutdown
      ../src/redis-cli -p 6006 shutdown
  6. 给启动脚本授权:
    chmod +x start-all.sh
    chmod +x stop-all.sh
  7. 启动:
    [root@192 cluster]# ./start-all.sh 
    12163:C 17 Feb 2020 19:20:37.432 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12163:C 17 Feb 2020 19:20:37.432 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12163, just started
    12163:C 17 Feb 2020 19:20:37.432 # Configuration loaded
    12165:C 17 Feb 2020 19:20:37.438 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12165:C 17 Feb 2020 19:20:37.438 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12165, just started
    12165:C 17 Feb 2020 19:20:37.438 # Configuration loaded
    12170:C 17 Feb 2020 19:20:37.445 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12170:C 17 Feb 2020 19:20:37.445 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12170, just started
    12170:C 17 Feb 2020 19:20:37.445 # Configuration loaded
    12175:C 17 Feb 2020 19:20:37.453 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12175:C 17 Feb 2020 19:20:37.453 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12175, just started
    12175:C 17 Feb 2020 19:20:37.453 # Configuration loaded
    12180:C 17 Feb 2020 19:20:37.459 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12180:C 17 Feb 2020 19:20:37.459 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12180, just started
    12180:C 17 Feb 2020 19:20:37.459 # Configuration loaded
    12185:C 17 Feb 2020 19:20:37.464 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    12185:C 17 Feb 2020 19:20:37.464 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12185, just started
    12185:C 17 Feb 2020 19:20:37.464 # Configuration loaded
    [root@192 cluster]# 
    
  8. 开通端口:
    firewall-cmd --zone=public --add-port=6001/tcp --permanent
    firewall-cmd --zone=public --add-port=6002/tcp --permanent
    firewall-cmd --zone=public --add-port=6003/tcp --permanent
    firewall-cmd --zone=public --add-port=6004/tcp --permanent
    firewall-cmd --zone=public --add-port=6005/tcp --permanent
    firewall-cmd --zone=public --add-port=6006/tcp --permanent
    
    firewall-cmd --reload
    
    firewall-cmd --list-all
  9. 创建集群:
    必须使用 IP(否则远程连接不上):
     ../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
    >>> 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.8.133:6005 to 192.168.8.133:6001
    Adding replica 192.168.8.133:6006 to 192.168.8.133:6002
    Adding replica 192.168.8.133:6004 to 192.168.8.133:6003
    >>> Trying to optimize slaves allocation for anti-affinity
    [WARNING] Some slaves are in the same host as their master
    M: 027e733678b9ccfc8b6d858d2870a6334916935f 192.168.8.133:6001
       slots:[0-5460] (5461 slots) master
    M: 37487e6b499a3df65a7310bf5e4f4f001f89f135 192.168.8.133:6002
       slots:[5461-10922] (5462 slots) master
    M: b4aead46397e77100c4ddc185e851d2d3ec7cf6d 192.168.8.133:6003
       slots:[10923-16383] (5461 slots) master
    S: 1c5d1767aa7aff049d9cfd025d153e5f430ef8cc 192.168.8.133:6004
       replicates 027e733678b9ccfc8b6d858d2870a6334916935f
    S: eb8a86ac1243a325605022e332f278405ea72143 192.168.8.133:6005
       replicates 37487e6b499a3df65a7310bf5e4f4f001f89f135
    S: 0c747138624559b89876b9b7a9309ff2d5540f1a 192.168.8.133:6006
       replicates b4aead46397e77100c4ddc185e851d2d3ec7cf6d
    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.8.133:6001)
    M: 027e733678b9ccfc8b6d858d2870a6334916935f 192.168.8.133:6001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    S: 1c5d1767aa7aff049d9cfd025d153e5f430ef8cc 192.168.8.133:6004
       slots: (0 slots) slave
       replicates 027e733678b9ccfc8b6d858d2870a6334916935f
    S: 0c747138624559b89876b9b7a9309ff2d5540f1a 192.168.8.133:6006
       slots: (0 slots) slave
       replicates b4aead46397e77100c4ddc185e851d2d3ec7cf6d
    S: eb8a86ac1243a325605022e332f278405ea72143 192.168.8.133:6005
       slots: (0 slots) slave
       replicates 37487e6b499a3df65a7310bf5e4f4f001f89f135
    M: 37487e6b499a3df65a7310bf5e4f4f001f89f135 192.168.8.133:6002
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: b4aead46397e77100c4ddc185e851d2d3ec7cf6d 192.168.8.133:6003
       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.
    [root@192 cluster]# 
    
  10. 查看集群状态:
    [root@192 cluster]# ../src/redis-cli --cluster info 192.168.8.133:6001
    192.168.8.133:6001 (027e7336...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.133:6002 (37487e6b...) -> 0 keys | 5462 slots | 1 slaves.
    192.168.8.133:6003 (b4aead46...) -> 0 keys | 5461 slots | 1 slaves.
    [OK] 0 keys in 3 masters.
    0.00 keys per slot on average.
    [root@192 cluster]# 
    
  • 1
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值