标签:
一、环境
ubuntu 14.04 LTS、 redis 3.0.2
二、redis cluster 搭建 (单机测试)
1、redis的安装
wget http://download.redis.io/releases/redis-3.0.2.tar.gz
tar zxvf redis-3.0.2.tar.gz
cd redis-3.0.2/
make
make install
2、安装ruby
sudo apt-get install ruby
sudo gem install redis #ruby的redis驱动
3、在单机测试的话,我们用redis-server分别启动多个文件就可以了,我这里采用的是6个端口,在redis cluster 里是三主、三从…. 当时也可以按照自己的情况设立主从…. 需要注意的是redis.conf要开发cluster的选项。 我简单写了一个批量修改redis.conf的脚本.
for i in `seq -w 0 5`;do
cp redis.conf 700$i.conf
sed -i "s/6379/700$i/g" 700$i.conf
sed -i ‘s/daemonize no/daemonize yes/g‘ 700$i.conf
sed -i ‘s/# cluster-enabled yes/cluster-enabled yes/g‘ 700$i.conf
sed -i ‘s/# cluster-node-timeout 15000/cluster-node-timeout 15000/g‘ 700$i.conf
sed -i "s/# cluster-config-file nodes-700*/cluster-config-file nodes-700$i.conf/g" 700$i.conf
redis-server 700$i.conf
done
4、检测进程
root@Gangli:/etc/redis$ ps aux | grep redis
root 8913 0.1 1.0 38508 10948 ? Ssl 10:27 0:02 redis-server *:7000 [cluster]
root 8923 0.1 1.0 38508 10972 ? Ssl 10:27 0:02 redis-server *:7001 [cluster]
root 8933 0.1 1.0 38508 11016 ? Ssl 10:27 0:02 redis-server *:7002 [cluster]
root 8943 0.1 0.8 38508 8868 ? Ssl 10:27 0:02 redis-server *:7003 [cluster]
root 8953 0.1 0.9 38508 9196 ? Ssl 10:27 0:02 redis-server *:7004 [cluster]
root 8963 0.1 0.8 38508 8972 ? Ssl 10:27 0:02 redis-server *:7005 [cluster]
5、用redis-trib.rb来创建redis cluster集群,下面是成功的提示。
root@Gangli:/tmp/soft/redis-3.0.2/src# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
M: d3784c3de3546438f2661716fead057836c23339 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: c0c222727190c4199025b4b93a23efc0f616923c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: fa23538ba7566bdc3694629978fc370c9f3610e7 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
S: 5f619a08a6302431909a54938b4f1d92538ea1a7 127.0.0.1:7003
replicates d3784c3de3546438f2661716fead057836c23339
S: 8203207d38d5a073dbd1cb339ea6e07f218579f4 127.0.0.1:7004
replicates c0c222727190c4199025b4b93a23efc0f616923c
S: 7b623f983f578f0bdda7d994a34c879f799aaf75 127.0.0.1:7005
replicates fa23538ba7566bdc3694629978fc370c9f3610e7
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:7000)
M: d3784c3de3546438f2661716fead057836c23339 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: c0c222727190c4199025b4b93a23efc0f616923c 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: fa23538ba7566bdc3694629978fc370c9f3610e7 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
M: 5f619a08a6302431909a54938b4f1d92538ea1a7 127.0.0.1:7003
slots: (0 slots) master
replicates d3784c3de3546438f2661716fead057836c23339
M: 8203207d38d5a073dbd1cb339ea6e07f218579f4 127.0.0.1:7004
slots: (0 slots) master
replicates c0c222727190c4199025b4b93a23efc0f616923c
M: 7b623f983f578f0bdda7d994a34c879f799aaf75 127.0.0.1:7005
slots: (0 slots) master
replicates fa23538ba7566bdc3694629978fc370c9f3610e7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
6、开启集群模式
root@Gangli:/tmp/soft/redis-3.0.2/src# redis-cli -c -p 7001 -h 127.0.0.1
标签:
原文地址:http://www.cnblogs.com/chrisDuan/p/4615560.html