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

[root@redis01 ~]# /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
显示信息如下
 
[root@redis01 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值