Redis集群安装

原创转载请注明出处:http://agilestyle.iteye.com/blog/2378272

 

Redis集群搭建,至少有3个节点,每个节点有一个备份节点,因此需要6台服务器

创建redis-cluster目录,拷贝redis安装目录到redis-cluster目录,修改别名,删除rdb

 

修改redis.conf,绑定IP为192.168.5.200,并且不要设置requirepass,否则将导致创建 [ERR] Sorry, can't connect to node,被坑了两天,虚耗生命


 

修改redis.conf,端口改为7001


 

开启集群


 

保存退出,拷贝5份,修改各自的port


 

拷贝redis源码文件夹下的src目录下的redis-trib.rb到redis-cluster目录


 

安装ruby和rubygems(需要连接外网)

sudo apt-get install software-properties-common

sudo apt-add-repository ppa:brightbox/ruby-ng

sudo apt-get update

sudo apt-get install ruby2.4

 

安装ruby和redis接口程序

sudo gem install redis

 

编写启动所有redis实例的脚本start-all-redis.sh

cd redis01/bin
./redis-server redis.conf
cd ../..
cd redis02/bin
./redis-server redis.conf
cd ../..
cd redis03/bin
./redis-server redis.conf
cd ../..
cd redis04/bin
./redis-server redis.conf
cd ../..
cd redis05/bin
./redis-server redis.conf
cd ../..
cd redis06/bin
./redis-server redis.conf

 

sudo chmod 744 start-all-redis.sh

./start-all-redis.sh


 ps -ef | grep redis

 

使用redis-trib.rb创建集群

./redis-trib.rb create --replicas 1 192.168.5.200:7001 192.168.5.200:7002 192.168.5.200:7003 192.168.5.200:7004 192.168.5.200:7005 192.168.5.200:7006 


 

使用redis-cli连接集群,需要加 -c 参数

 ./redis-cli -p 7001 -h 192.168.5.200 -c


 

 

Reference

https://www.brightbox.com/docs/ruby/ubuntu/#installation

 

 

 

猜你喜欢

转载自agilestyle.iteye.com/blog/2378272