两台服务器实现 多节点集群
server:192.168.142.136
server:192.168.142.137
步骤:
1.下载编译redis
wget http://download.redis.io/releases/redis-4.0.12.tar.gz
cd $redis_home
make && make install
2.配置多个节点
mkdir /usr/lcoal/redis_cluster/{7000,7001,7002} -p
cp /usr/local/reids/redis.cfg /usr/local/redis_cluster/{7000,7001,7002}
daemonize yes
pidfile /var/run/redis_7000.pid
port 7000
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 5000
appendonly yes
3.启动
/usr/local/redis/src/redis-server /usr/local/redis_cluster/7000/redis.cfg
/usr/local/redis/src/redis-server /usr/local/redis_cluster/7001/redis.cfg
/usr/local/redis/src/redis-server /usr/local/redis_cluster/7002/redis.cfg
另外一台服务器配置基本相同
4.在每台服务器安装ruby
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - //导入公钥
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
curl -L get.rvm.io | bash -s stable //安装
source /usr/local/rvm/scripts/rvm
rvm install 2.3.3
rvm use 2.3.3 --default
rvm remove 2.0.0
gem install redis
/usr/local/redis-4.0.12/src/redis-trib.rb create --replicas 1 192.168.142.137:7000 192.168.142.137:7001 192.168.142.137:7002 192.168.142.136:7003 192.168.142.136:7004 192.168.142.136:7005
5测试:
nc -w 10 -v -z 192.168.142.137 7000/7001/7002 //测试端口连通性
redis-cli -c -h 192.168.142.137 -p 7000
set name tglmm
redis-cli -c -h 192.168.142.136 -p 7005
get name
tglmm
6注意:
--replicas 1 表示自动为每个master节点分配一个slave
在配置redis.cfg时将bind 127.0.0.1,修改成192.168.142.136/192.168.142.137