一、集羣組件安裝node
EPEL源安裝ruby支持 yum install ruby rubygems -y 使用國內源 gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ 若是沒法使用,能夠使用aliyun gem sources -a http://mirrors.aliyun.com/rubygems/ gem sources --remove http://rubygems.org/ gem sources -l gem install redis -v 3.3.3
二、集羣節點準備python
規劃: 端口:7000-7005 路徑: /application/data/7000 /application/data/7001 /application/data/7002 /application/data/7003 /application/data/7004 /application/data/7005 日誌路徑: /var/log/redis7000.log /var/log/redis7001.log /var/log/redis7002.log /var/log/redis7003.log /var/log/redis7004.log /var/log/redis7005.log pid文件 /application/data/7000/redis.pid /application/data/7001/redis.pid /application/data/7002/redis.pid /application/data/7003/redis.pid /application/data/7004/redis.pid /application/data/7005/redis.pid 建立節點目錄: mkdir -p /application/data/7000 mkdir -p /application/data/7001 mkdir -p /application/data/7002 mkdir -p /application/data/7003 mkdir -p /application/data/7004 mkdir -p /application/data/7005 配置文件添加: ------------------------- vim /application/data/7000/redis.conf port 7000 daemonize yes pidfile /application/data/7000/redis.pid logfile "/var/log/redis7000.log" dbfilename dump.rdb dir /application/data/7000 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes vim /application/data/7001/redis.conf port 7001 daemonize yes pidfile /application/data/7001/redis.pid logfile "/var/log/redis7001.log" dbfilename dump.rdb dir /application/data/7001 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes vim /application/data/7002/redis.conf port 7002 daemonize yes pidfile /application/data/7002/redis.pid logfile "/var/log/redis7002.log" dbfilename dump.rdb dir /application/data/7002 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes vim /application/data/7003/redis.conf port 7003 daemonize yes pidfile /application/data/7003/redis.pid logfile "/var/log/redis7003.log" dbfilename dump.rdb dir /application/data/7003 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes vim /application/data/7004/redis.conf port 7004 daemonize yes pidfile /application/data/7004/redis.pid logfile "/var/log/redis7004.log" dbfilename dump.rdb dir /application/data/7004 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes vim /application/data/7005/redis.conf port 7005 daemonize yes pidfile /application/data/7005/redis.pid logfile "/var/log/redis7005.log" dbfilename dump.rdb dir /application/data/7005 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes 啓動全部節點 redis-server /application/data/7000/redis.conf redis-server /application/data/7001/redis.conf redis-server /application/data/7002/redis.conf redis-server /application/data/7003/redis.conf redis-server /application/data/7004/redis.conf redis-server /application/data/7005/redis.conf ps -ef |grep 700
三、集羣建立git
redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \ 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
四、集羣狀態查看github
redis-cli -p 7000 cluster nodes | grep master
五、Python 鏈接 redis clusterredis
+++++++++++++++Python 鏈接 redis cluster+++++++++++++++++ (1) redis-py並無提供redis-cluster的支持,去github找了一下,有個叫redis-py-cluster的源碼, 可是和redis-py不是一個做者,地址爲:https://github.com/Grokzen/redis-py-cluster watch,star,fork還算能夠。 (2) 安裝 Latest stable release from pypi $ pip install redis-py-cluster or from source $ python setup.py install (3) 使用 >>> from rediscluster import StrictRedisCluster >>> startup_nodes = [{"host": "127.0.0.1", "port": "7000"}] >>> # Note: decode_responses must be set to True when used with python3 >>> rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True) >>> rc.set("foo", "bar") True >>> print(rc.get("foo")) 'bar'