安装rubygems:yum install rubygems
安装ruby的redis驱动:gem install redis
参考:http://www.cnblogs.com/rwxwsblog/p/5285732.html
pidfile /var/run/redis_6379.pid
logfile /var/log/redis_6379.log
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
复制相应的配置文件并按上述配置文件修改相应的配置(注意端口和路径)
依次修改相应的配置文件6380.conf、6381.conf、6382.conf、6383.conf、6384.conf、6385.conf
mkdir -p /var/lib/redis/6380 /var/lib/redis/6381 /var/lib/redis/6382 /var/lib/redis/6383 /var/lib/redis/6384 /var/lib/redis/6385
安装并配置完后6379端口的redis实例需要重启,否则会报错
cp redis-3.0.7/src/redis-trib.rb /usr/local/bin/
redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
[root@cas ~]# redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
[ERR] Node 127.0.0.1:6379 is not configured as a cluster node.
[root@cas ~]# ps -ef|grep redis
root 22342 1 0 10:29 ? 00:00:03 /usr/local/bin/redis-server *:6379
root 22456 1 0 10:51 ? 00:00:00 redis-server *:6380 [cluster]
root 22460 1 0 10:51 ? 00:00:00 redis-server *:6381 [cluster]
root 22464 1 0 10:52 ? 00:00:00 redis-server *:6382 [cluster]
root 22470 1 0 10:52 ? 00:00:00 redis-server *:6383 [cluster]
root 22474 1 0 10:52 ? 00:00:00 redis-server *:6384 [cluster]
root 22478 1 0 10:52 ? 00:00:00 redis-server *:6385 [cluster]
root 23530 22364 0 10:58 pts/1 00:00:00 grep --color=auto redis
[root@cas ~]# redis-server /etc/redis/6379.conf
[root@cas ~]# ps -ef|grep redis
root 22456 1 0 10:51 ? 00:00:00 redis-server *:6380 [cluster]
root 22460 1 0 10:51 ? 00:00:00 redis-server *:6381 [cluster]
root 22464 1 0 10:52 ? 00:00:00 redis-server *:6382 [cluster]
root 22470 1 0 10:52 ? 00:00:00 redis-server *:6383 [cluster]
root 22474 1 0 10:52 ? 00:00:00 redis-server *:6384 [cluster]
root 22478 1 0 10:52 ? 00:00:00 redis-server *:6385 [cluster]
root 23534 1 0 10:59 ? 00:00:05 redis-server *:6379 [cluster]
root 23532 22364 0 10:59 pts/1 00:00:00 grep --color=auto redis
[root@cas ~]# redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
>>> Performing hash slots allocation on 7 nodes...
Adding replica 127.0.0.1:6382 to 127.0.0.1:6379
Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
Adding replica 127.0.0.1:6385 to 127.0.0.1:6379
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
S: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
S: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
S: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
S: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
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 127.0.0.1:6379)
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
M: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
M: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
M: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
M: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@cas ~]# redis-trib.rb check 127.0.0.1:6379
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
S: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
S: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
S: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
S: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
add-node的使用方法为new_host:new_port existing_host:existing_port,前面是新添加的节点信息,后面是已存在的节点信息
redis-trib.rb add-node 192.168.3.61:6379 192.168.3.88:6379
本文转自秋楓博客园博客,原文链接:http://www.cnblogs.com/rwxwsblog/p/6030606.html,如需转载请自行联系原作者