redis-cluster集群搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis-cluster集群搭建相关的知识,希望对你有一定的参考价值。
1、环境
2、安装ruby
最新ruby源码ruby
安装三连:
tar -zxvf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --prefix=/usr/local/ruby-2.3.1
make && make install
ln -s /usr/local/ruby-2.3.1/bin/gem /usr/bin/gem
ln -s /usr/local/ruby-2.3.1/bin/ruby /usr/bin/ruby
gem install redis
3、下载redis
redis
安装三连
tar zxf redis-4.0.9.tar.gz
cd redis-4.0.9
make
make test
配置redis.conf
[[email protected] redis-4.0.9-6379]# cat redis.conf
daemonize yes
port 7001 #不同节点的端口不同
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
appendonly yes
copy redis目录为6份,
依此启动:
./src/redis-server redis.conf
查看启动状态
copy redis-trib.rb
创建集群。并测试
python测试
pip install redis-py-cluster
vim redis_cluster_test.py
from rediscluster import StrictRedisCluster
import sys
def redis_cluster():
redis_nodes = [{‘host‘:‘127.0.0.1‘,‘port‘:7001},
{‘host‘:‘127.0.0.1‘,‘port‘:7002},
{‘host‘:‘127.0.0.1‘,‘port‘:7003},
{‘host‘:‘127.0.0.1‘,‘port‘:7004},
{‘host‘:‘127.0.0.1‘,‘port‘:7005},
{‘host‘:‘127.0.0.1‘,‘port‘:7006}
]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
except Exception,e:
print "Connect Error!"
sys.exit(1)
redisconn.set(‘name‘,‘chen‘)
redisconn.set(‘age‘,59)
print "name is: ", redisconn.get(‘name‘)
print "age is: ", redisconn.get(‘age‘)
if __name__=="__main__":
redis_cluster()
以上是关于redis-cluster集群搭建的主要内容,如果未能解决你的问题,请参考以下文章