1、環境node
ubuntu 14.04 LTS、 redis 3.0.2redis
2、redis cluster 搭建 (單機測試)ubuntu
一、redis的安裝c#
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
二、安裝rubyruby
sudo apt-get install ruby sudo gem install redis #ruby的redis驅動
三、在單機測試的話,咱們用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
四、檢測進程spa
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]
五、用redis-trib.rb來建立redis cluster集羣,下面是成功的提示。3d
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.
六、開啓集羣模式code
root@Gangli:/tmp/soft/redis-3.0.2/src# redis-cli -c -p 7001 -h 127.0.0.1