redis集群搭建实战

安装好redis版本5.0.8,保证能用

创建redis各实例目录[启6台机,假设ip尾号:136,137,138,140,141,142]
//分别在各机上创建集群目录:
mkdir /usr/local/redis-cluster
cd /usr/local/redis-cluster
//创建放置配置,数据,日志目录,如果创建集群失败了,这三个目录下的文件全部删除
//具体详细如在data下创建redis-136等就不详述
mkdir conf data log

分别进到5.0.8下配置redis.conf
###1###配置redis-136.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.136
dir /usr/local/redis-cluster/data/redis-136
pidfile /var/run/redis-cluster/redis-136.pid
logfile /usr/local/redis-cluster/log/redis-136.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-136.conf
cluster-node-timeout 10000
appendonly yes

###2###配置redis-137.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.137
dir /usr/local/redis-cluster/data/redis-137
pidfile /var/run/redis-cluster/redis-137.pid
logfile /usr/local/redis-cluster/log/redis-137.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-137.conf
cluster-node-timeout 10000
appendonly yes

###3###配置redis-138.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.138
dir /usr/local/redis-cluster/data/redis-138
pidfile /var/run/redis-cluster/redis-138.pid
logfile /usr/local/redis-cluster/log/redis-138.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-138.conf
cluster-node-timeout 10000
appendonly yes

###4###配置redis-140.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.140
dir /usr/local/redis-cluster/data/redis-140
pidfile /var/run/redis-cluster/redis-140.pid
logfile /usr/local/redis-cluster/log/redis-140.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-140.conf
cluster-node-timeout 10000
appendonly yes

###5###配置redis-141.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.141
dir /usr/local/redis-cluster/data/redis-141
pidfile /var/run/redis-cluster/redis-141.pid
logfile /usr/local/redis-cluster/log/redis-141.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-141.conf
cluster-node-timeout 10000
appendonly yes

###6###配置redis-142.conf

daemonize yes
bind 0.0.0.0 #或者 bind 192.x.x.142
dir /usr/local/redis-cluster/data/redis-142
pidfile /var/run/redis-cluster/redis-142.pid
logfile /usr/local/redis-cluster/log/redis-142.log
port 6379
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-142.conf
cluster-node-timeout 10000
appendonly yes


分别启动各节点
./redis-server redis-136.conf
./redis-server redis-137.conf
./redis-server redis-138.conf
./redis-server redis-140.conf
./redis-server redis-141.conf
./redis-server redis-142.conf

可以在以上配置的log/redis-136.log…看各个服务是启正常启动

外网访问要开放端口 (对这个不熟,有简单的,麻烦告知下)
开放6379端口 : /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
开放16379端口 : /sbin/iptables -I INPUT -p tcp --dport 16379 -j ACCEPT

firewall-cmd --zone=public --add-port=6379 /tcp --permanent
firewall-cmd --zone=public --add-port=16379 /tcp --permanent
firewall-cmd --reload

启动集群(先贴下老的)
./redis-trib.rb create --replicas 1
192.x.x.136:6379
192.x.x.137:6379
192.x.x.138:6379
192.x.x.140:6379
192.x.x.141:6379
192.x.x.142:6379

(这个是新的,以这个启动)
./redis-cli --cluster create
192.x.x.136:6379
192.x.x.138:6379
192.x.x.139:6379
192.x.x.143:6379
192.x.x.141:6379
192.x.x.142:6379
–cluster-replicas 1

出现以下信息:

Performing hash slots allocation on 6 nodes…
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.x.x.x:6379 to 192.x.x.136:6379
Adding replica 192.x.x.142:6379 to 192.x.x.138:6379
Adding replica 192.x.x.143:6379 to 192.x.x.139:6379
M: c8735cb5cfd830a6d1b52b436b30a3b68f8485a2 192.x.x.136:6379
slots:[0-5460] (5461 slots) master
M: 1d1c4d4419ec764d2386e8747e98af2c76d574d6 192.x.x.138:6379
slots:[5461-10922] (5462 slots) master
M: 0d60991f44147d80544a7691356b73ef27216dbb 192.x.x.139:6379
slots:[10923-16383] (5461 slots) master
S: 7bcfcf98b7896c1971856a626b7a6b3c4e279673 192.x.x.143:6379
replicates 0d60991f44147d80544a7691356b73ef27216dbb
S: 8a66bad5e754f33615e6d136d4a4980f7d5f69f6 192.x.x.141:6379
replicates c8735cb5cfd830a6d1b52b436b30a3b68f8485a2
S: 7a5f3e9b0d26628c7f0979dab0531c9d9cb04aa8 192.x.x.142:6379
replicates 1d1c4d4419ec764d2386e8747e98af2c76d574d6
Can I set the above configuration? (type ‘yes’ to accept): yes ///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.x.x.136:6379)
M: c8735cb5cfd830a6d1b52b436b30a3b68f8485a2 192.x.x.136:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 7bcfcf98b7896c1971856a626b7a6b3c4e279673 192.x.x.143:6379
slots: (0 slots) slave
replicates 0d60991f44147d80544a7691356b73ef27216dbb
M: 0d60991f44147d80544a7691356b73ef27216dbb 192.x.x.139:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 8a66bad5e754f33615e6d136d4a4980f7d5f69f6 192.x.x.141:6379
slots: (0 slots) slave
replicates c8735cb5cfd830a6d1b52b436b30a3b68f8485a2
S: 7a5f3e9b0d26628c7f0979dab0531c9d9cb04aa8 192.x.x.142:6379
slots: (0 slots) slave
replicates 1d1c4d4419ec764d2386e8747e98af2c76d574d6
M: 1d1c4d4419ec764d2386e8747e98af2c76d574d6 192.x.x.138:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

第一次写,本人水平有限,不足之处共勉!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值