redis3官方出的cluster方案,比较完善。看文章时,自己部署学习了下。
参考:https://blog.youkuaiyun.com/men_wen/article/details/72853078
部署的时候发现操作起来很麻烦,于是写个python脚本自动化部署,脚本比较简单。由于后面项目需要做工业级redis cluster自动化部署,这里暂作记录已备使用。
# -*- coding: UTF-8 -*-
import os
import sys
#redis端口起始值
port = 7000
#redis 集群node个数
count = 6
config = """#端口
port {
{port}}
#开启集群模式
cluster-enabled yes
#集群内部的配置文件
cluster-config-file {
{port}}/nodes.conf
#节点超时时间,单位毫秒
cluster-node-timeout 15000
logfile {
{port}}/redis.log
loglevel notice
"""
slot_size = 16384
#生成集群配置文件
def conf():
for i in xrange(count):
curr = port + i
os.mkdir(str(curr))
content = config.replace("{
{port}}", str(curr))
file = open("%s/redis-%d.conf" % (curr, curr), "w")
file.write(content)