DEFAULTS = {
:url => lambda { ENV["REDIS_URL"] },
:scheme => "redis",
:host => "127.0.0.1",
:port => 6379,
:path => nil,
:timeout => 5.0,
:password => 123456, #登录密码改为123456
:db => 0,
:driver => nil,
……
10.使用redis-trib.rb命令创建集群环境,会自动分配主从服务
[root@localhost ~]# redis-trib.rb create --replicas 1 192.168.1.9:6379 192.168.1.9:6380 192.168.1.106:6379
192.168.1.106:6380 192.168.1.110:6379 192.168.1.110:6380
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.9:6379
192.168.1.106:6379
192.168.1.110:6379
Adding replica 192.168.1.106:6380 to 192.168.1.9:6379
Adding replica 192.168.1.110:6380 to 192.168.1.106:6379
Adding replica 192.168.1.9:6380 to 192.168.1.110:6379
M: eed2e22136cbdca6770a46bbb2e137ab693dd16b 192.168.1.9:6379
slots:0-5460 (5461 slots) master
#主服务:M
#主服务id:eed2e22136cbdca6770a46bbb2e137ab693dd16b
#主服务ip和端口:192.168.1.9:6379
#分得的槽位区间:0-5460
#一共分得的槽:5460
S: 8efbcf7fdd4675c77199a2a1206f0209ac2255f3 192.168.1.9:6380
replicates e387a0ba7c95d0c27d7e28a9b57d23117711eadc
#从服务:S
#从服务id:8efbcf7fdd4675c77199a2a1206f0209ac2255f3
#从服务ip和端口:192.168.1.9:6380
#从服务所属的主服务id:e387a0ba7c95d0c27d7e28a9b57d23117711eadc
M: c922b4bf56f0086609fd4fb23d987df0a77bec22 192.168.1.106:6379
slots:5461-10922 (5462 slots) master
S: a4fd89d79cdd27698bc394134b2df25b63ddb4c5 192.168.1.106:6380
replicates eed2e22136cbdca6770a46bbb2e137ab693dd16b
M: e387a0ba7c95d0c27d7e28a9b57d23117711eadc 192.168.1.110:6379
slots:10923-16383 (5461 slots) master
S: 34549b777963b16e65125def8d9a8e50e27ed2a4 192.168.1.110:6380
replicates c922b4bf56f0086609fd4fb23d987df0a77bec22
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.1.9:6379)
M: eed2e22136cbdca6770a46bbb2e137ab693dd16b 192.168.1.9:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: a4fd89d79cdd27698bc394134b2df25b63ddb4c5 192.168.1.106:6380
slots: (0 slots) slave
replicates eed2e22136cbdca6770a46bbb2e137ab693dd16b
S: 8efbcf7fdd4675c77199a2a1206f0209ac2255f3 192.168.1.9:6380
slots: (0 slots) slave
replicates e387a0ba7c95d0c27d7e28a9b57d23117711eadc
M: c922b4bf56f0086609fd4fb23d987df0a77bec22 192.168.1.106:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: e387a0ba7c95d0c27d7e28a9b57d23117711eadc 192.168.1.110:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 34549b777963b16e65125def8d9a8e50e27ed2a4 192.168.1.110:6380
slots: (0 slots) slave
replicates c922b4bf56f0086609fd4fb23d987df0a77bec22
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
11.查看slave从服务的连接状态,可以看到还未建立主从连接