您好,登录后才能下订单哦!
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
解压并编译安装:
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
[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
[jerry@client2 redis-cluster]$ for i in {3,4,5} ; do cat ./700$i/redis.conf ; done
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
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
[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
[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
用堡垒机查看下各结点启动情况:
[root@master ~]# ansible k8s -m shell -a'ps -ef |grep redis'
[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
报错:
安装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
[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版本命令已经更换.
格式不对:
[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
访问:
测试观察集群:
211上连接设置一个键值name,值设置为jerry
尝试212上获取键值
213服务器上更改name值
211上再次攻取其值:
212上再次获取其值:
集群信息查看:
192.168.27.211:7000> cluster info
注意新版命令有所变化:
参考文献:https://redis.io/topics/cluster-tutorial
https://blog.serverdensity.com/monitor-redis/
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。