1,官网下载redis5,并make编译,并执行make test是否ok,无问题执行下一步。 2,创建下面内容的模板文件redis-cluster.tmpl port ${PORT} protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 你电脑的ip cluster-announce-port ${PORT} cluster-announce-bus-port 1${PORT} appendonly yes
3,根据模板文件,执行shell生成目标配置文件
for port in `seq 8000 8005` do mkdir -p ./${port}/conf && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf && mkdir -p ./${port}/data done
4,根据配置文件,执行下面shell命令启动6个节点的redis for port in `seq 8000 8005` do cd ${port} && /root/software/redis-5.0.5/src/redis-server ./conf/redis.conf & done
如果有报错,查看原因解决,否则进行下一步
5,执行生成集群的命令 /root/software/redis-5.0.5/src/redis-cli --cluster create 172.16.0.9:8000 172.16.0.9:8001 172.16.0.9:8002 172.16.0.9:8003 172.16.0.9:8004 172.16.0.9:8005 --cluster-replicas 1
注:172.16.0.9是内网ip,改成外网ip(即你电脑的ip)应该也可以,
6,正常情况下可以看到如下打印:
>>> 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.16.0.9:8004 to 172.16.0.9:8000 Adding replica 172.16.0.9:8005 to 172.16.0.9:8001 Adding replica 172.16.0.9:8003 to 172.16.0.9:8002 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 5c789b5929a06c20c42659498f7c63cedcccb90c 172.16.0.9:8000 slots:[0-5460] (5461 slots) master M: 940d5148878cfc851e9f0ea7452cd04be0d7cde9 172.16.0.9:8001 slots:[5461-10922] (5462 slots) master M: 70c86a36c011a068a2f49f7900874248d8bc5049 172.16.0.9:8002 slots:[10923-16383] (5461 slots) master S: d61acdd2b8d913af0f122423399f4bdfb7d73454 172.16.0.9:8003 replicates 940d5148878cfc851e9f0ea7452cd04be0d7cde9 S: 99238accbf371374d7fd08c7573c06812b8e39fc 172.16.0.9:8004 replicates 70c86a36c011a068a2f49f7900874248d8bc5049 S: c3ad6ae487d4704a8a604fb6b2a6e784034060f5 172.16.0.9:8005 replicates 5c789b5929a06c20c42659498f7c63cedcccb90c Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated
. . . 最终如下就是其成功了 27552:C 26 May 2019 14:03:48.388 * Parent agreed to stop sending diffs. Finalizing AOF... 27552:C 26 May 2019 14:03:48.388 * Concatenating 0.00 MB of AOF diff received from parent. 27552:C 26 May 2019 14:03:48.389 * SYNC append only file rewrite performed 27552:C 26 May 2019 14:03:48.389 * AOF rewrite: 4 MB of memory used by copy-on-write 27364:S 26 May 2019 14:03:48.422 * Background AOF rewrite terminated with success 27364:S 26 May 2019 14:03:48.422 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 27364:S 26 May 2019 14:03:48.422 * Background AOF rewrite finished successfully 27370:S 26 May 2019 14:03:48.431 * Background AOF rewrite terminated with success 27370:S 26 May 2019 14:03:48.431 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 27370:S 26 May 2019 14:03:48.431 * Background AOF rewrite finished successfully 27368:S 26 May 2019 14:03:48.432 * Background AOF rewrite terminated with success 27368:S 26 May 2019 14:03:48.432 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 27368:S 26 May 2019 14:03:48.432 * Background AOF rewrite finished successfully 27352:M 26 May 2019 14:03:48.723 # Cluster state changed: ok 27360:M 26 May 2019 14:03:48.724 # Cluster state changed: ok 27356:M 26 May 2019 14:03:48.725 # Cluster state changed: ok