Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、Ada以及 Lisp 语言。由 Ruby 语言本身还发展出了JRuby(Java平台)、IronRuby(.NET平台)等其他平台的 Ruby 语言替代品。Ruby的作者于1993年2月24日开始编写Ruby,直至1995年12月才正式公开发布于fj(新闻组)。因为Perl发音与6月诞生石pearl(珍珠)相同,因此Ruby以7月诞生石ruby(红宝石)命名。
./src/redis-trib.rb
在redis根目录下运行
Performing hash slots allocation on 9 nodes... 有九个节点
Using 3 masters:
192.168.161.135:7000
192.168.161.135:7001
192.168.161.135:7002
使用3个主机
下面是集群的划分
[root@localhost redis-3.2.8]# ./src/redis-trib.rb create --replicas 2 192.168.161.135:7000 192.168.161.135:7001 192.168.161.135:7002 192.168.161.135:7003 192.168.161.135:7004 192.168.161.135:7005 192.168.161.135:7006 192.168.161.135:7007 192.168.161.135:7008
>>> Creating cluster
>>> Performing hash slots allocation on 9 nodes...
Using 3 masters:
192.168.161.135:7000
192.168.161.135:7001
192.168.161.135:7002
Adding replica 192.168.161.135:7003 to 192.168.161.135:7000
Adding replica 192.168.161.135:7004 to 192.168.161.135:7000
Adding replica 192.168.161.135:7005 to 192.168.161.135:7001
Adding replica 192.168.161.135:7006 to 192.168.161.135:7001
Adding replica 192.168.161.135:7007 to 192.168.161.135:7002
Adding replica 192.168.161.135:7008 to 192.168.161.135:7002
M: ae670f256a5dee1d1996f5bf99c6bba6fa33709c 192.168.161.135:7000
slots:0-5460 (5461 slots) master
M: 6a2d87ee6c9400223bcbd446eb9ad91281eb3287 192.168.161.135:7001
slots:5461-10922 (5462 slots) master
M: 25a5f1cc8b57838283fd29845f9d4eaa46572439 192.168.161.135:7002
slots:10923-16383 (5461 slots) master
S: 6845a47050bd488b818d5414c47c0b3bb775d0d3 192.168.161.135:7003
replicates ae670f256a5dee1d1996f5bf99c6bba6fa33709c
S: 6495fa47f309259f4e094a2a71e95fe6fbfda2ce 192.168.161.135:7004
replicates ae670f256a5dee1d1996f5bf99c6bba6fa33709c
S: 3c1acd8ef7f4ce3bf3302bd1617b963219b31fa1 192.168.161.135:7005
replicates 6a2d87ee6c9400223bcbd446eb9ad91281eb3287
S: 1dd79cf7fbe6aecd479fd231fd21c567c12e3107 192.168.161.135:7006
replicates 6a2d87ee6c9400223bcbd446eb9ad91281eb3287
S: ea3143dce6f14c7101634caf2db60092c65d0ce7 192.168.161.135:7007
replicates 25a5f1cc8b57838283fd29845f9d4eaa46572439
S: 651682b93bf1f3e725cf882103b84bcadd0c77dd 192.168.161.135:7008
replicates 25a5f1cc8b57838283fd29845f9d4eaa46572439
Can I set the above configuration? (type 'yes' to accept):
输入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.161.135:7000)
M: ae670f256a5dee1d1996f5bf99c6bba6fa33709c 192.168.161.135:7000
slots:0-5460 (5461 slots) master
2 additional replica(s)
S: 1dd79cf7fbe6aecd479fd231fd21c567c12e3107 192.168.161.135:7006
slots: (0 slots) slave
replicates 6a2d87ee6c9400223bcbd446eb9ad91281eb3287
S: 3c1acd8ef7f4ce3bf3302bd1617b963219b31fa1 192.168.161.135:7005
slots: (0 slots) slave
replicates 6a2d87ee6c9400223bcbd446eb9ad91281eb3287
M: 6a2d87ee6c9400223bcbd446eb9ad91281eb3287 192.168.161.135:7001
slots:5461-10922 (5462 slots) master
2 additional replica(s)
S: 6845a47050bd488b818d5414c47c0b3bb775d0d3 192.168.161.135:7003
slots: (0 slots) slave
replicates ae670f256a5dee1d1996f5bf99c6bba6fa33709c
S: ea3143dce6f14c7101634caf2db60092c65d0ce7 192.168.161.135:7007
slots: (0 slots) slave
replicates 25a5f1cc8b57838283fd29845f9d4eaa46572439
M: 25a5f1cc8b57838283fd29845f9d4eaa46572439 192.168.161.135:7002
slots:10923-16383 (5461 slots) master
2 additional replica(s)
S: 6495fa47f309259f4e094a2a71e95fe6fbfda2ce 192.168.161.135:7004
slots: (0 slots) slave
replicates ae670f256a5dee1d1996f5bf99c6bba6fa33709c
S: 651682b93bf1f3e725cf882103b84bcadd0c77dd 192.168.161.135:7008
slots: (0 slots) slave
replicates 25a5f1cc8b57838283fd29845f9d4eaa46572439
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
出现两个[OK]表示搭建成功
测试一下
[root@localhost redis-3.2.8]# redis-cli -p 7000
127.0.0.1:7000> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.161.135,port=7003,state=online,offset=211,lag=1
slave1:ip=192.168.161.135,port=7004,state=online,offset=211,lag=1
master_repl_offset:211
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:210
127.0.0.1:7000> set aa aa
OK
127.0.0.1:7000> set qq qq
(error) MOVED 5598 192.168.161.135:7001
127.0.0.1:7000> exit
[root@localhost redis-3.2.8]# redis-cli -p 7001
127.0.0.1:7001> set qq qq
OK
127.0.0.1:7001> set ww ww
OK
127.0.0.1:7001> set ee ee
(error) MOVED 2268 192.168.161.135:7000
127.0.0.1:7001> exit
[root@localhost redis-3.2.8]# redis-cli -p 7000 shutdown
15s后
[root@localhost redis-3.2.8]# redis-cli -p 7003
127.0.0.1:7003> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.161.135,port=7004,state=online,offset=57,lag=1
master_repl_offset:57
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:56
重启7000
[root@localhost redis-3.2.8]# cd cluster/
[root@localhost cluster]# ls
7000 7001 7002 7003 7004 7005 7006 7007 7008 start.sh
[root@localhost cluster]# cd 7000
[root@localhost 7000]# ls
dump.rdb nodes-7000.conf redis.conf
[root@localhost 7000]# redis-server redis.conf
[root@localhost 7000]# redis-cli -p 7000
127.0.0.1:7000> info replication
# Replication
role:slave
master_host:192.168.161.135
master_port:7003
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:281
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:7000> exit