1、创建redis集群
(1)安装ruby
查看默认安装的ruby
-->ruby -v
如果有输出则卸载
-->rpm -qa|grep ruby
-->rpm -e ruby.... --nodeps
。安装ruby
-->yum install -y zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel
-->cd /data/soft
-->wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
-->tar -zxf ruby-2.5.1.tar.gz
-->cd ruby-2.5.1
-->./configure
-->make
-->make install
重新登录终端
-->ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
(2)安装ruby-redis.gem
添加国内源
-->gem source -a https://gems.ruby-china.com/
https://gems.ruby-china.com/ added to sources
删除国外源并添加国内源:
-->gem sources --add gem source -a https://gems.ruby-china.com/ \--remove https://rubygems.org/
source https://gems.ruby-china.com/ already present in the cache
https://rubygems.org/ removed from sources
-->gem source -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
安装redis
-->gem install redis
Fetching: redis-4.1.0.gem (100%)
Successfully installed redis-4.1.0
Parsing documentation for redis-4.1.0
Installing ri documentation for redis-4.1.0
Done installing documentation for redis after 0 seconds
1 gem installed
================================================================
(3)创建集群
确保7001-7006服务都起来,且相互都能端口访问,启动服务用户为redis
-->cd /data/soft
-->chown -R redis:redis redis-4.0.11
-->su - redis
-->cd /data/soft/redis-4.0.11/src/
-->cp redis-trib.rb /data/app/redis/bin/
任意节点执行:
-->./redis-trib.rb create --replicas 1 192.168.1.100:7001 192.168.1.100:7002 192.168.1.101:7003 \
> 192.168.1.101:7004 192.168.1.102:7005 192.168.1.102:7006
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.100:7001
192.168.1.101:7003
192.168.1.102:7005
Adding replica 192.168.1.101:7004 to 192.168.1.100:7001
Adding replica 192.168.1.102:7006 to 192.168.1.101:7003
Adding replica 192.168.1.100:7002 to 192.168.1.102:7005
M: f8500eca0b64482c400cb26722d18a95ef38aefd 192.168.1.100:7001
slots:0-5460 (5461 slots) master
S: c7e754721ddc740531ed14b1d6f403e40873720c 192.168.1.100:7002
replicates a3af09cdce3e0862509676c9cb08a2e63cd1ba4e
M: 82e0c724c3014da773de0557ea1f49198eb7c675 192.168.1.101:7003
slots:5461-10922 (5462 slots) master
S: 1f67016ccc2952bdd92890f5b309a2863079c3b8 192.168.1.101:7004
replicates f8500eca0b64482c400cb26722d18a95ef38aefd
M: a3af09cdce3e0862509676c9cb08a2e63cd1ba4e 192.168.1.102:7005
slots:10923-16383 (5461 slots) master
S: b8eaa9d8833e2a9e0f99f9d9e9d2db129b19f7c8 192.168.1.102:7006
replicates 82e0c724c3014da773de0557ea1f49198eb7c675
Can I set the above configuration? (type 'yes' to accept): yes #输入yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join......
>>> Performing Cluster Check (using node 192.168.1.100:7001)
M: f8500eca0b64482c400cb26722d18a95ef38aefd 192.168.1.100:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: b8eaa9d8833e2a9e0f99f9d9e9d2db129b19f7c8 192.168.1.102:7006
slots: (0 slots) slave
replicates 82e0c724c3014da773de0557ea1f49198eb7c675
M: 82e0c724c3014da773de0557ea1f49198eb7c675 192.168.1.101:7003
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: c7e754721ddc740531ed14b1d6f403e40873720c 192.168.1.100:7002
slots: (0 slots) slave
replicates a3af09cdce3e0862509676c9cb08a2e63cd1ba4e
M: a3af09cdce3e0862509676c9cb08a2e63cd1ba4e 192.168.1.102:7005
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 1f67016ccc2952bdd92890f5b309a2863079c3b8 192.168.1.101:7004
slots: (0 slots) slave
replicates f8500eca0b64482c400cb26722d18a95ef38aefd
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
注意:redis-trib.rb create --replicas 1表示一个master对应几个slave
此处的参数为1,表示master和slave一一对应。
主从是redis-trib.rb自动分配的
可以看到
master: 192.168.1.100:7001
192.168.1.101:7003
192.168.1.102:7005
slave: 192.168.1.102:7006
192.168.1.100:7002
192.168.1.101:7004
=====================================================================================
网友评论