• redis集群的安装部署


    1.下载redis的稳定版本

    wget https://download.redis.io/redis-stable.tar.gz

    2..安装redis软件

    1. tar -xzvf redis-stable.tar.gz
    2. cd redis-stable
    3. make
    4. make install

    编译过程中提示报错,需要安装gcc

    3.编译配置文件

    7001服务

    1. port 7001 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7001.pid #修改PID文件名
    5. dir /opt/redis-cluster/7001/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7001.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    7002服务

    1. port 7002 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7002.pid #修改PID文件名
    5. dir /opt/redis-cluster/7002/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7002.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    7003服务

    1. port 7003 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7003.pid #修改PID文件名
    5. dir /opt/redis-cluster/7003/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7003.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    7004服务

    1. port 7004 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7004.pid #修改PID文件名
    5. dir /opt/redis-cluster/7004/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7004.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    7005服务

    1. port 7005 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7005.pid #修改PID文件名
    5. dir /opt/redis-cluster/7005/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7005.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    7006服务

    1. port 7006 #修改端口
    2. bind 10.3.10.20 #修改为对应主机IP地址
    3. daemonize yes
    4. pidfile /var/run/redis_7006.pid #修改PID文件名
    5. dir /opt/redis-cluster/7006/data #定义存储文件夹
    6. cluster-enabled yes
    7. cluster-config-file nodes-7006.conf #修改集群文件名
    8. cluster-node-timeout 5000
    9. appendonly yes

    4.启动服务

    1. 1.拷贝redis-server到服务目录
    2. cd /opt/redis-cluster
    3. cp /opt/redis-cluster/redis-stable/src/redis-server 7001
    4. cp /opt/redis-cluster/redis-stable/src/redis-server 7002
    5. cp /opt/redis-cluster/redis-stable/src/redis-server 7003
    6. cp /opt/redis-cluster/redis-stable/src/redis-server 7004
    7. cp /opt/redis-cluster/redis-stable/src/redis-server 7005
    8. cp /opt/redis-cluster/redis-stable/src/redis-server 7006
    9. 2.启动服务
    10. ./redis-server redis-7001.conf
    11. ./redis-server redis-7002.conf
    12. ./redis-server redis-7003.conf
    13. ./redis-server redis-7004.conf
    14. ./redis-server redis-7005.conf
    15. ./redis-server redis-7006.conf

    5.安装集群所需的软件

    1. yum install ruby rubygems -y
    2. gem install redis
    3. 升级rubygems gem
    4. curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    5. curl -sSL https://get.rvm.io | bash -s stable
    6. source /etc/profile.d/rvm.sh
    7. rvm requirements
    8. source /usr/local/rvm/scripts/rvm
    9. rvm install 2.4.0
    10. rvm use 2.4.0
    11. gem install redis

    6.组建集群

    1. cd /opt/redis-cluster/redis-stable/src
    2. ./redis-cli --cluster create 10.3.10.20:7001 10.3.10.20:7002 10.3.10.20:7003 10.3.10.20:7004 10.3.10.20:7005 10.3.10.20:7006 --cluster-replicas 1

    集群输出如下

    1. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    2. >>> Performing hash slots allocation on 6 nodes...
    3. Master[0] -> Slots 0 - 5460
    4. Master[1] -> Slots 5461 - 10922
    5. Master[2] -> Slots 10923 - 16383
    6. Adding replica 10.3.10.20:7005 to 10.3.10.20:7001
    7. Adding replica 10.3.10.20:7006 to 10.3.10.20:7002
    8. Adding replica 10.3.10.20:7004 to 10.3.10.20:7003
    9. >>> Trying to optimize slaves allocation for anti-affinity
    10. [WARNING] Some slaves are in the same host as their master
    11. M: cf656ddf619b566a48d15b7f076e6d773d646895 10.3.10.20:7001
    12. slots:[0-5460] (5461 slots) master
    13. M: acb4146d7e15c2799cc1c9bb0d34d02e568bde13 10.3.10.20:7002
    14. slots:[5461-10922] (5462 slots) master
    15. M: 419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3 10.3.10.20:7003
    16. slots:[10923-16383] (5461 slots) master
    17. S: 8345ec77e8795dcce9dde5c61bf10939150c290a 10.3.10.20:7004
    18. replicates acb4146d7e15c2799cc1c9bb0d34d02e568bde13
    19. S: 66c43b50c6e8fc8101502d7466379899305df17f 10.3.10.20:7005
    20. replicates 419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3
    21. S: ab8f6e8c1ffcf48d6903b15fbe58e6ce4e2ad117 10.3.10.20:7006
    22. replicates cf656ddf619b566a48d15b7f076e6d773d646895
    23. Can I set the above configuration? (type 'yes' to accept): yes
    24. >>> Nodes configuration updated
    25. >>> Assign a different config epoch to each node
    26. >>> Sending CLUSTER MEET messages to join the cluster
    27. Waiting for the cluster to join
    28. .
    29. >>> Performing Cluster Check (using node 10.3.10.20:7001)
    30. M: cf656ddf619b566a48d15b7f076e6d773d646895 10.3.10.20:7001
    31. slots:[0-5460] (5461 slots) master
    32. 1 additional replica(s)
    33. S: 8345ec77e8795dcce9dde5c61bf10939150c290a 10.3.10.20:7004
    34. slots: (0 slots) slave
    35. replicates acb4146d7e15c2799cc1c9bb0d34d02e568bde13
    36. M: acb4146d7e15c2799cc1c9bb0d34d02e568bde13 10.3.10.20:7002
    37. slots:[5461-10922] (5462 slots) master
    38. 1 additional replica(s)
    39. M: 419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3 10.3.10.20:7003
    40. slots:[10923-16383] (5461 slots) master
    41. 1 additional replica(s)
    42. S: ab8f6e8c1ffcf48d6903b15fbe58e6ce4e2ad117 10.3.10.20:7006
    43. slots: (0 slots) slave
    44. replicates cf656ddf619b566a48d15b7f076e6d773d646895
    45. S: 66c43b50c6e8fc8101502d7466379899305df17f 10.3.10.20:7005
    46. slots: (0 slots) slave
    47. replicates 419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3
    48. [OK] All nodes agree about slots configuration.
    49. >>> Check for open slots...
    50. >>> Check slots coverage...
    51. [OK] All 16384 slots covered.

    7.组建集群报错

    [ERR] Node 10.3.10.20:7001 DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. In this mode connections are only accepted from the loopback interface. If you want to connect from exters to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SUREt publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and thg the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a an authentication password for the default user. NOTE: You only need to do one of the above things in order for the servaccepting connections from the outside.
    

    解决方式

    在配置文件增加

    masterauth "redis"
    requirepass "redis"

    重启redis进程

    之后使用如下命令创建集群

    ./redis-cli --cluster create 10.3.10.20:7001 10.3.10.20:7002 10.3.10.20:7003 10.3.10.20:7004 10.3.10.20:7005 10.3.10.20:7006 --cluster-replicas 1 -a htjs 

    8.集群验证

     

    ./redis-cli -c -h 10.3.10.20 -p 7001 -a htjs
    

    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    10.3.10.20:7001> 
    10.3.10.20:7001> 
    10.3.10.20:7001> 
    10.3.10.20:7001> 
    10.3.10.20:7001> 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_ping_sent:480
    cluster_stats_messages_pong_sent:471
    cluster_stats_messages_sent:951
    cluster_stats_messages_ping_received:466
    cluster_stats_messages_pong_received:480
    cluster_stats_messages_meet_received:5
    cluster_stats_messages_received:951
    total_cluster_links_buffer_limit_exceeded:0

    10.3.10.20:7001> cluster nodes
    8345ec77e8795dcce9dde5c61bf10939150c290a 10.3.10.20:7004@17004 slave acb4146d7e15c2799cc1c9bb0d34d02e568bde13 0 1658303013066 2 connected
    acb4146d7e15c2799cc1c9bb0d34d02e568bde13 10.3.10.20:7002@17002 master - 0 1658303013568 2 connected 5461-10922
    419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3 10.3.10.20:7003@17003 master - 0 1658303014572 3 connected 10923-16383
    ab8f6e8c1ffcf48d6903b15fbe58e6ce4e2ad117 10.3.10.20:7006@17006 slave cf656ddf619b566a48d15b7f076e6d773d646895 0 1658303012564 1 connected
    66c43b50c6e8fc8101502d7466379899305df17f 10.3.10.20:7005@17005 slave 419bfdab0a4cfcfa3ee78ef8bfaad59f968cbee3 0 1658303014069 3 connected
    cf656ddf619b566a48d15b7f076e6d773d646895 10.3.10.20:7001@17001 myself,master - 0 1658303014000 1 connected 0-5460

    10.3.10.20:7001> 
     

  • 相关阅读:
    Java-多线程
    【MySQL从入门到精通】【高级篇】(三)MySQL用户的创建_修改_删除以及密码的设置
    leetcode 129
    【LeetCode】链表OJ题
    python开发工程师面试准备
    (高阶) Redis 7 第21讲 IO多路复用模型 完结篇
    树状数组——一个简单的整数问题
    分析数学笔记
    【前端】Vue+Element UI案例:通用后台管理系统-Header+导航栏折叠
    计算机毕业设计Java晶研电子公司业务网站(源码+mysql数据库+系统+lw文档)
  • 原文地址:https://blog.csdn.net/rendongxingzhe/article/details/125885436