企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
## redis 5.0集群部署步骤 ## 1. 下载源码编译 ``` # wget http://download.redis.io/releases/redis-5.0.0.tar.gz # tar xzf redis-5.0.0.tar.gz # cd redis-5.0.0/ # make ``` 编译源码报以下失败信息 ``` cc: error: ../deps/hiredis/libhiredis.a: No such file or directory cc: error: ../deps/lua/src/liblua.a: No such file or directory cc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directory ``` 先进入deps目录编译依赖库 ``` # cd deps/ # make hiredis jemalloc linenoise lua # cd .. # make ``` 编译成功 ## 2. 创建六个集群的配置文件 ``` # mkdir cluster && cd cluster # mkdir 7001 7002 7003 7004 7005 7006 ``` 分别将项目根目录的redis.conf的配置文件复制到上面六个目录下。 修改配置文件以下内容(其中 port 和 pidfile 需要随着 文件夹的不同调增): ``` port 7001 #端口 # bind 127.0.0.1 cluster-enabled yes #启用集群模式 cluster-config-file nodes-7001.conf cluster-node-timeout 5000 #超时时间 appendonly yes daemonize yes #后台运行 protected-mode no #非保护模式 pidfile /var/run/redis_7001.pid ``` ## 3. 启动节点 ``` ./src/redis-server cluster/7001/redis.conf ./src/redis-server cluster/7002/redis.conf ./src/redis-server cluster/7003/redis.conf ./src/redis-server cluster/7004/redis.conf ./src/redis-server cluster/7005/redis.conf ./src/redis-server cluster/7006/redis.conf ``` ## 启动集群 ``` ./src/redis-cli --cluster create 192.168.4.64:7001 192.168.4.64:7002 192.168.4.64:7003 192.168.4.64:7004 192.168.4.64:7005 192.168.4.64: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 192.168.4.64:7004 to 192.168.4.64:7001 Adding replica 192.168.4.64:7005 to 192.168.4.64:7002 Adding replica 192.168.4.64:7006 to 192.168.4.64:7003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 18593987417ba8e6fc259bfd06f07b06f9a35cde 192.168.4.64:7001 slots:[0-5460] (5461 slots) master M: 2d07d29e4dfc55148e52030365daf0f42def9aae 192.168.4.64:7002 slots:[5461-10922] (5462 slots) master M: 29b9b7b226555116475027599e22b285503afe42 192.168.4.64:7003 slots:[10923-16383] (5461 slots) master S: 4286d9bef7c523fd822340e1c265afe2a31bd804 192.168.4.64:7004 replicates 2d07d29e4dfc55148e52030365daf0f42def9aae S: 64b9ddb34174ed8a17ee44b640c046f56a70bdca 192.168.4.64:7005 replicates 29b9b7b226555116475027599e22b285503afe42 S: 05defa184e44d771143a3272f57da38d4b06df03 192.168.4.64:7006 replicates 18593987417ba8e6fc259bfd06f07b06f9a35cde 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.4.64:7001) M: 18593987417ba8e6fc259bfd06f07b06f9a35cde 192.168.4.64:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 05defa184e44d771143a3272f57da38d4b06df03 192.168.4.64:7006 slots: (0 slots) slave replicates 18593987417ba8e6fc259bfd06f07b06f9a35cde M: 2d07d29e4dfc55148e52030365daf0f42def9aae 192.168.4.64:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 29b9b7b226555116475027599e22b285503afe42 192.168.4.64:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: 64b9ddb34174ed8a17ee44b640c046f56a70bdca 192.168.4.64:7005 slots: (0 slots) slave replicates 29b9b7b226555116475027599e22b285503afe42 S: 4286d9bef7c523fd822340e1c265afe2a31bd804 192.168.4.64:7004 slots: (0 slots) slave replicates 2d07d29e4dfc55148e52030365daf0f42def9aae [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. ``` 至此,redis集群部署成功