最新版redis5.0.5集群搭建( 4主5从Centos7)
admin
2023-03-01 19:22:26
0

最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
redis集群是一个无中心的分布式redis存储架构,可以在多个节点之间进行数据共享,解决了redis高可用、可扩展等问题,redis集群提供了以下两个好处: 1)将数据自动切分(split)到多个节点 2)当集群中的某一个节点故障时,redis还可以继续处理客户端的请求。
Redis Cluster的特点如下:
• 节点自动发现
• slave->master选举,集群容错
• Hot resharding:在线分片
• 集群管理:clusterxxx
• 基于配置(nodes-port.conf)的集群管理
• ASK 转向/MOVED转向机制
• 布署无需指定master
• 可以支持超过1,000台节点的集群
服务器IP 主机名|安装组件 备注
192.168.27.211 Client1 redis-5.0.5 集群各结点,单个结点开三个服务进程模拟三台服务器。
192.168.27.212 Client2 redis-5.0.5
192.168.27.213 Client3 redis-5.0.5
192.168.27.210 master ansible 堡垒机
官方最新版下载地址:http://download.redis.io/releases/redis-5.0.5.tar.gz
解压并编译安装:
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
192.168.27.211配置文件配置:(切换用户后注意权限sudo chown jerry.root -R redis-5.0.5所有结点)
mkdir /data/redis-5.0.5/redis-cluster/{7000,7001,7002} -pv
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client1 redis-cluster]$ cat 7000/redis.conf
port 7000
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7000.pid
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 10100
appendonly yes

[jerry@client1 redis-cluster]$ cat 7001/redis.conf
port 7001
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7001.pid
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 10100
appendonly yes

[jerry@client1 redis-cluster]$ cat 7002/redis.conf
port 7002
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7002.pid
cluster-enabled yes
cluster-config-file nodes_7002.conf
cluster-node-timeout 10100
appendonly yes

服务器:192.168.27.212:
[jerry@client2 redis-5.0.5]$ mkdir /data/redis-5.0.5/redis-cluster/{7003,7004,7005} -pv
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client2 redis-cluster]$ for i in {3,4,5} ; do cat ./700$i/redis.conf ; done
最新版redis5.0.5集群搭建( 4主5从Centos7)
port 7003
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7003.pid
cluster-enabled yes
cluster-config-file nodes_7003.conf
cluster-node-timeout 10100
appendonly yes
port 7004
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7004.pid
cluster-enabled yes
cluster-config-file nodes_7004.conf
cluster-node-timeout 10100
appendonly yes
port 7005
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7005.pid
cluster-enabled yes
cluster-config-file nodes_7005.conf
cluster-node-timeout 10100
appendonly yes

192.168.27.213配置文件:
[jerry@client3 redis-5.0.5]$ mkdir /data/redis-5.0.5/redis-cluster/{7006,7007,7008} -pv
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
port 7006
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7006.pid
cluster-enabled yes
cluster-config-file nodes_7006.conf
cluster-node-timeout 10100
appendonly yes
port 7007
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7007.pid
cluster-enabled yes
cluster-config-file nodes_7007.conf
cluster-node-timeout 10100
appendonly yes
port 7008
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7008.pid
cluster-enabled yes
cluster-config-file nodes_7008.conf
cluster-node-timeout 10100
appendonly yes

启动各结点上的redis
[jerry@client1 redis-cluster]$ for i in {0..2}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client2 redis-cluster]$ for i in {3..5}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client3 redis-cluster]$ for i in {6..8}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
用堡垒机查看下各结点启动情况:
[root@master ~]# ansible k8s -m shell -a'ps -ef |grep redis'
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client1 src]$ ./redis-trib.rb create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
报错:
最新版redis5.0.5集群搭建( 4主5从Centos7)
安装ruby组件:https://centos.pkgs.org/7/centos-sclo-rh-x86_64/rh-ruby22-ruby-devel-2.2.2-16.el7.x86_64.rpm.html(集群中某一结点安装即可)

yum install centos-release-scl-rh
yum install rh-ruby22-ruby-devel

[jerry@client1 src]$ sudo yum -y install ruby ruby-devel rubygems rpm-build
最新版redis5.0.5集群搭建( 4主5从Centos7)
[jerry@client1 src]$ sudo ./redis-trib.rb create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
提示5.0.5版本命令已经更换.
最新版redis5.0.5集群搭建( 4主5从Centos7)
格式不对:
[jerry@client1 src]$ sudo ./redis-cli create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
Could not connect to Redis at 127.0.0.1:6379: Connection refused

新版正确格式:
[jerry@client1 src]$ sudo ./redis-cli --cluster create 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008 --cluster-replicas 1

最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
访问:
最新版redis5.0.5集群搭建( 4主5从Centos7)
测试观察集群:
211上连接设置一个键值name,值设置为jerry
最新版redis5.0.5集群搭建( 4主5从Centos7)
尝试212上获取键值
最新版redis5.0.5集群搭建( 4主5从Centos7)
213服务器上更改name值
最新版redis5.0.5集群搭建( 4主5从Centos7)
211上再次攻取其值:
最新版redis5.0.5集群搭建( 4主5从Centos7)
212上再次获取其值:
最新版redis5.0.5集群搭建( 4主5从Centos7)
集群信息查看:
192.168.27.211:7000> cluster info

最新版redis5.0.5集群搭建( 4主5从Centos7)
最新版redis5.0.5集群搭建( 4主5从Centos7)
注意新版命令有所变化:
最新版redis5.0.5集群搭建( 4主5从Centos7)
参考文献:https://redis.io/topics/cluster-tutorial
https://blog.serverdensity.com/monitor-redis/

相关内容

热门资讯

我来教教您“十三十三水经典比鸡... 您好:十三十三水经典比鸡这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家...
玩家分享攻略“掌中乐游戏中心.... 您好:掌中乐游戏中心这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这...
最新引进“新皇豪炸金花.到底是... 有 亲,根据资深记者爆料新皇豪炸金花是可以开挂的,确实有挂(咨询软件无需...
终于懂了“新猴王牛牛.是不是有... 终于懂了“新猴王牛牛.是不是有挂?”详细开挂教程您好,新猴王牛牛这个游戏其实有挂的,确实是有挂的,需...
【第一资讯】“微友山西麻将.究... 有 亲,根据资深记者爆料微友山西麻将是可以开挂的,确实有挂(咨询软件无需...
终于明白“福州十八扑.怎么开挂... 终于明白“福州十八扑.怎么开挂?”太坑了果然有挂您好,福州十八扑这个游戏其实有挂的,确实是有挂的,需...
玩家分享攻略“新海贝之城拼三张... 有 亲,根据资深记者爆料新海贝之城拼三张是可以开挂的,确实有挂(咨询软件...
【第一资讯】“,17好友麻将.... 您好:,17好友麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这...
重磅消息“麦穗app推筒子.开... 有 亲,根据资深记者爆料麦穗app推筒子是可以开挂的,确实有挂(咨询软件...
我来教教您“问鼎娱乐.开挂神器... 有 亲,根据资深记者爆料问鼎娱乐是可以开挂的,确实有挂(咨询软件无需打开...