Redis3配置Cluster

1、redis3的cluster是基于ruby的,所以要安装好ruby,然后安装redis的gem

gem install redis

2、然后配置6份redis,修改配置如下

节点
dbm6379 dbm6380 dbm6381 dbs6382 dbm6383 dbm6384
配置文件 dbm6379/conf/redis.conf dbm6380/conf/redis.conf dbm6381/conf/redis.conf dbs6382/conf/redis.conf dbm6383/conf/redis.conf dbm6384/conf/redis.conf
port 6379 6380 6381 6382 6383 6384
logfile “/home/neohope/DB/redis-3.0.4/cluster/dbm6379/logs/redis_log.log” “/home/neohope/DB/redis-3.0.4/cluster/dbm6380/logs/redis_log.log” “/home/neohope/DB/redis-3.0.4/cluster/dbm6381/logs/redis_log.log” “/home/neohope/DB/redis-3.0.4/cluster/dbm6382/logs/redis_log.log” “/home/neohope/DB/redis-3.0.4/cluster/dbm6383/logs/redis_log.log” “/home/neohope/DB/redis-3.0.4/cluster/dbm6384/logs/redis_log.log”
dir “/home/neohope/DB/redis-3.0.4/cluster/dbm6379/data” “/home/neohope/DB/redis-3.0.4/cluster/dbm6380/data” “/home/neohope/DB/redis-3.0.4/cluster/dbm6381/data” “/home/neohope/DB/redis-3.0.4/cluster/dbm6382/data” “/home/neohope/DB/redis-3.0.4/cluster/dbm6383/data” “/home/neohope/DB/redis-3.0.4/cluster/dbm6384/data”
cluster-enabled yes yes yes yes yes yes
cluster-config-file nodes-6379.conf nodes-6380.conf nodes-6381.conf nodes-6382.conf nodes-6383.conf nodes-6384.conf
cluster-node-timeout 15000 15000 15000 15000 15000 15000
cluster-migration-barrier 1 1 1 1 1 1
cluster-require-full-coverage yes yes yes yes yes yes

3、启动redis

#!/bin/sh
~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbm6379/conf/redis.conf & echo $! & ~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbm6380/conf/redis.conf & echo $! & ~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbm6381/conf/redis.conf & echo $! & ~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbs6382/conf/redis.conf & echo $! & ~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbs6383/conf/redis.conf & echo $! & ~/DB/redis-3.0.4/bin/redis-server ~/DB/redis-3.0.4/cluster/dbs6384/conf/redis.conf & echo $!

4、配置cluster

#!/bin/sh
#这里最好不要用127.0.0.1做地址
~/DB/redis-3.0.4/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      

5、测试redis cluster

~/DB/redis-3.0.4/bin/redis-cli -c -p 6379 
set key01 a
set key02 b
set key03 c
set key04 d
dbsize
keys *
get key03

6、关闭redis

#!/bin/sh
~/DB/redis-3.0.4/bin/redis-cli -p 6379 shutdown
~/DB/redis-3.0.4/bin/redis-cli -p 6380 shutdown
~/DB/redis-3.0.4/bin/redis-cli -p 6381 shutdown
~/DB/redis-3.0.4/bin/redis-cli -p 6382 shutdown
~/DB/redis-3.0.4/bin/redis-cli -p 6383 shutdown
~/DB/redis-3.0.4/bin/redis-cli -p 6384 shutdown

参考:
redis cluster tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

*