1. 程式人生 > >CentOS7安裝Redis4.0叢集

CentOS7安裝Redis4.0叢集

環境

CentOS 7, Redis 4.0.6, Oracle VM VirtualBox

Redis叢集要求最少3主3從,主機使用虛擬主機(192.168.1.81 - 192.168.1.86)

備註:使用redis-trib安裝reids4.0.6叢集需要ruby版本>2.2.2,但是yum源預設是2.0版本,所以需要修改yum源安裝2.3版本

配置一臺虛擬機器

IP:192.168.1.81

安裝 gcc wget

yum install wget gcc -y

安裝redis

wget http://download.redis.io/releases/redis-4.0.6.tar.gz
tar xzf redis-4.0.6.tar.gz
mv redis-4.0.6 /usr/local/redis
cd redis-4.0.6 /usr/local/redis
mv redis.conf redis.conf.bak
vi redis.conf
redis.conf中新增如下內容
port 6379
bind 192.168.1.81 //不同主機IP不同
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
pidfile /var/run/redis_6379.pid
appendonly yes

安裝好後複製5臺虛擬機器(192.168.1.82-192.168.1.86)

啟動6臺虛擬機器的redis

[[email protected] ~]# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf

安裝ruby

備註:一臺安裝即可,我是在192.168.1.81上安裝

yum install centos-release-scl-rh
yum install rh-ruby23  -y
scl  enable  rh-ruby23 bash

組成叢集

gem install redis
/usr/local/redis/src/redis-trib.rb create --replicas 1 192.168.1.81:6379 192.168.1.82:6379 192.168.1.83:6379 192.168.1.84:6379 192.168.1.85:6379 192.168.1.86:6379
顯示資訊如下
 
[[email protected] local]# /usr/local/redis/src/redis-trib.rb create --replicas 1 192.168.1.81:6379 192.168.1.82:6379 192.168.1.83:6379 192.168.1.84:6379 192.168.1.85:6379 192.168.1.86:6379 
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.81:6379
192.168.1.82:6379
192.168.1.83:6379
Adding replica 192.168.1.84:6379 to 192.168.1.81:6379
Adding replica 192.168.1.85:6379 to 192.168.1.82:6379
Adding replica 192.168.1.86:6379 to 192.168.1.83:6379
M: d303fbc7f6f7d216e7eb3bdbbe1a136123fe78ab 192.168.1.81:6379
   slots:0-5460 (5461 slots) master
M: 6b413b265a5574c675085c1d37eea7ffd2935919 192.168.1.82:6379
   slots:5461-10922 (5462 slots) master
M: a121164f525855ae7d6b5e95911f9f6639f3b38a 192.168.1.83:6379
   slots:10923-16383 (5461 slots) master
S: b34636a7a84357a3c069d6c75efc3f1c7b9be7c2 192.168.1.84:6379
   replicates d303fbc7f6f7d216e7eb3bdbbe1a136123fe78ab
S: 21cf50a1d11233c4963f156a0dc0e4b24db34f8e 192.168.1.85:6379
   replicates 6b413b265a5574c675085c1d37eea7ffd2935919
S: d512b1467a1f7a91e953660f7302a1952ea1afe2 192.168.1.86:6379
   replicates a121164f525855ae7d6b5e95911f9f6639f3b38a
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 192.168.1.81:6379)
M: d303fbc7f6f7d216e7eb3bdbbe1a136123fe78ab 192.168.1.81:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: a121164f525855ae7d6b5e95911f9f6639f3b38a 192.168.1.83:6379
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: d512b1467a1f7a91e953660f7302a1952ea1afe2 192.168.1.86:6379
   slots: (0 slots) slave
   replicates a121164f525855ae7d6b5e95911f9f6639f3b38a
S: b34636a7a84357a3c069d6c75efc3f1c7b9be7c2 192.168.1.84:6379
   slots: (0 slots) slave
   replicates d303fbc7f6f7d216e7eb3bdbbe1a136123fe78ab
M: 6b413b265a5574c675085c1d37eea7ffd2935919 192.168.1.82:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 21cf50a1d11233c4963f156a0dc0e4b24db34f8e 192.168.1.85:6379
   slots: (0 slots) slave
   replicates 6b413b265a5574c675085c1d37eea7ffd2935919
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.