当前位置:主页 > 数据库 > Redis >

使用Ruby脚本部署Redis Cluster集群步骤讲解

时间:2020-12-11 21:51:56 | 栏目:Redis | 点击:

安装Ruby和Gem

下载ruby
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.8.tar.gz
解压
tar xvf ruby-2.3.8.tar.gz
生成Makefile并且后面会被安装到/usr/local/ruby目录下
./configure -prefix /usr/local/ruby
编译
make 
安装
make install
cd /usr/local/ruby
cp bin/ruby /usr/local/bin/
cp bin/gem /usr/local/bin/

安装Ruby和redis接口

下载

wget  https://rubygems.org/downloads/redis-4.1.0.gem

安装

gem install -l redis-4.1.0.gem

将脚本移动到/usr/local/bin/下,方便直接执行

cp /usr/local/redis/src/redis-trib.rb /usr/local/bin/

启动Redis节点

8000端口配置文件模板,其余节点只有端口不同

# redis-8000.conf
daemonize yes
port 8000
logfile "8000.log"
dir "/server/redis_data"
dbfilename "dump-8000.rdb"
cluster-enabled yes
cluster-config-file nodes-8000.conf
cluster-require-full-coverage no

启动节点

redis-server redis-8000.conf 
redis-server redis-8001.conf 
redis-server redis-8002.conf 
redis-server redis-8003.conf 
redis-server redis-8004.conf 
redis-server redis-8005.conf 

一键开启

redis-trib.rb create --replicas 1 10.238.162.34:8000 10.238.162.34:8001\
10.238.162.34:8002 10.238.162.34:8003\
10.238.162.34:8004 10.238.162.34:8005

# redis-cli -p 8000 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:695
cluster_stats_messages_received:695
# redis-cli -p 8000 cluster nodes
4dd758d1f84285cbe82cd51f4b1bdce08f10d067 10.238.162.34:8004 slave cbcb2f95d3c66c3ad2203fb268be39eef8567317 0 1547215299946 5 connected
860069c03aefeb7449aa6daf2f198d90f1f19b01 10.238.162.34:8002 master - 0 1547215297941 3 connected 10923-16383
cbcb2f95d3c66c3ad2203fb268be39eef8567317 10.238.162.34:8001 master - 0 1547215298944 2 connected 5461-10922
e84313e39765087ff8bfe4bf86b10717d82c9698 10.238.162.34:8003 slave 90d1c2da65f7ee8cd7d16a7790384903bd4ccc8e 0 1547215297440 4 connected
bc0e954a60920a24c2bfa351c042470f1d8dda07 10.238.162.34:8005 slave 860069c03aefeb7449aa6daf2f198d90f1f19b01 0 1547215296940 6 connected
90d1c2da65f7ee8cd7d16a7790384903bd4ccc8e 10.238.162.34:8000 myself,master - 0 0 1 connected 0-5460

总结

您可能感兴趣的文章:

相关文章