0713 预习任务2 redis 集群
作者:互联网
21.22 redis集群介绍
多个redis节点网络互联,数据共享
所有的节点都是一主一从(可以是多个从),其中从不提供服务,仅作为备用
不支持同时处理多个键(如mset/mget),因为redis需要把键均匀分布在各个节点上,并发量很高的情况下同时创建键值会降低性能并导致不可预测的行为。
支持在线增加、删除节点
客户端可以连任何一个主节点进行读写
21.23/21.24 redis集群搭建配置
1、场景设置:
两台机器,分别开启三个 Redis 服务(端口)
A机器上三个端口7000,7002,7004,全部为主
B机器上三个端口7001,7003,7005,全部为从
两台机器上都要编译安装redis,然后编辑并复制 3 个不同的 redis.conf,分别设置不同的端口号、dir等参数,还需要增加 cluster 相关参数,然后分别启动6个 redis 服务
3、在 A 机器编辑 redis_7000,redis_7002,redis_7004
[root@arslinux-01 ~]# vim redis_7000.conf port 7000 bind 192.168.194.130 daemonize yes pidfile /var/run/redis_7000.pid dir /data/redis_data/7000 cluster-enabled yes cluster-config-file nodes_7000.conf cluster-node-timeout 10100 appendonly yes
redis_7002 和 redis_7004 方法相同
B 机器上编辑 redis_7001,redis_7003,redis_7005
[root@arslinux-02 ~]# vim redis_7001.conf port 7001 bind 192.168.194.132 daemonize yes pidfile /var/run/redis_7001.pid dir /data/redis_data/7001 cluster-enabled yes cluster-config-file nodes_7001.conf cluster-node-timeout 10100 appendonly yes
redis_7003和 redis_7005 方法相同
参数可以参考 https://coding.net/u/aminglinux/p/yuanke_centos7/git/tree/master/21NOSQL
3、创建目录
A机器
[root@arslinux-01 ~]# mkdir /data/redis_data/ [root@arslinux-01 ~]# mkdir /data/redis_data/{7000,7002,7004}
B机器
[root@arslinux-02 ~]# mkdir /data/redis_data/ [root@arslinux-02 ~]# mkdir /data/redis_data/{7001,7003,7005}
4、在 B 机器上安装 redis
1)拷贝已经编译的源码包目录
[root@arslinux-01 src]# scp -r redis-4.0.1 192.168.194.132:/usr/local/src/
2)进入源码包目录,直接 make install
[root@arslinux-02 redis-4.0.1]# make install cd src && make install make[1]: 进入目录“/usr/local/src/redis-4.0.1/src” Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install make[1]: 离开目录“/usr/local/src/redis-4.0.1/src”
5、A、B机器分别启动 6 个 redis
[root@arslinux-01 ~]# redis-server /etc/redis_7000.conf 21160:C 15 Jul 12:47:55.370 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 21160:C 15 Jul 12:47:55.370 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21160, just started 21160:C 15 Jul 12:47:55.371 # Configuration loaded [root@arslinux-01 ~]# redis-server /etc/redis_7002.conf 21169:C 15 Jul 12:47:59.268 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 21169:C 15 Jul 12:47:59.268 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21169, just started 21169:C 15 Jul 12:47:59.268 # Configuration loaded [root@arslinux-01 ~]# redis-server /etc/redis_7004.conf 21174:C 15 Jul 12:48:02.023 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 21174:C 15 Jul 12:48:02.023 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21174, just started 21174:C 15 Jul 12:48:02.023 # Configuration loaded [root@arslinux-01 ~]# ps aux|grep redis root 8128 0.1 0.9 147348 9080 ? Ssl 12:03 0:04 redis-server 127.0.0.1:6379 root 8151 0.1 0.9 147348 9004 ? Ssl 12:03 0:04 redis-server 127.0.0.1:6380 root 21161 0.1 0.2 145304 2640 ? Ssl 12:47 0:00 redis-server 192.168.194.130:7000 [cluster] root 21170 0.1 0.2 145304 2636 ? Ssl 12:47 0:00 redis-server 192.168.194.130:7002 [cluster] root 21175 0.1 0.2 145304 2640 ? Ssl 12:48 0:00 redis-server 192.168.194.130:7004 [cluster] root 21216 0.0 0.0 112724 988 pts/0 R+ 12:49 0:00 grep --color=auto redis
[root@arslinux-02 ~]# redis-server /etc/redis_7001.conf 7773:C 15 Jul 12:48:59.676 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 7773:C 15 Jul 12:48:59.676 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7773, just started 7773:C 15 Jul 12:48:59.677 # Configuration loaded [root@arslinux-02 ~]# redis-server /etc/redis_7003.conf 7778:C 15 Jul 12:49:02.024 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 7778:C 15 Jul 12:49:02.024 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7778, just started 7778:C 15 Jul 12:49:02.024 # Configuration loaded [root@arslinux-02 ~]# redis-server /etc/redis_7005.conf 7783:C 15 Jul 12:49:04.469 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 7783:C 15 Jul 12:49:04.470 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7783, just started 7783:C 15 Jul 12:49:04.470 # Configuration loaded [root@arslinux-02 ~]# ps aux|grep redis root 7774 0.2 0.7 145304 7576 ? Ssl 12:48 0:00 redis-server 192.168.194.132:7001 [cluster] root 7779 0.3 0.7 145304 7576 ? Ssl 12:49 0:00 redis-server 192.168.194.132:7003 [cluster] root 7784 0.2 0.7 145304 7572 ? Ssl 12:49 0:00 redis-server 192.168.194.132:7005 [cluster]
6、关闭防火墙
7、安装 ruby (只需在一台机器上安装即可)
[root@arslinux-01 ~]# yum -y groupinstall "Development Tools"
过程省略
8、安装相关的包
[root@arslinux-01 ~]# yum -y install gdbm-devel libdb4-devel libffi-devel libyaml libyaml-devel ncurses-devel openssl-devel readline-devel tcl-deve
9、创建目录,下载源码包
[root@arslinux-01 ~]# cd /root/ [root@arslinux-01 ~]# mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} [root@arslinux-01 ~]# wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz -P rpmbuild/SOURCES
10、下载 Ruby2x.spec 的文件
[root@arslinux-01 ~]# wget https://raw.githubusercontent.com/tjinjin/automate-ruby-rpm/master/ruby22x.spec -P rpmbuild/SPECS
11、编译制作 rpm 包
[root@arslinux-01 ~]# rpmbuild -bb rpmbuild/SPECS/ruby22x.spec [root@arslinux-01 ~]# ls rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm [root@arslinux-01 ~]# du -sh rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm 10Mrpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
12、yum 安装本地 rpm 包(避免依赖的问题)
[root@arslinux-01 ~]# yum -y localinstall rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
13、安装出错
[root@arslinux-01 ~]# gem install redis Fetching: redis-4.1.2.gem (100%) ERROR: Error installing redis: redis requires Ruby version >= 2.3.0.
14、安装 rvm 来更新 ruby 版本到 2.3.0
1)下载
[root@arslinux-01 ~]# gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB [root@arslinux-01 ~]# \curl -sSL https://get.rvm.io | bash -s stable Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc gpg: 于 2019年07月10日 星期三 16时31分02秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB gpg: 完好的签名,来自于“Piotr Kuczynski <piotr.kuczynski@gmail.com>” gpg: 警告:这把密钥未经受信任的签名认证! gpg: 没有证据表明这个签名属于它所声称的持有者。 主钥指纹: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows. * Please do NOT forget to add your users to the rvm group. The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect! Thanks for installing RVM
2)根据提示添加 rvm 用户到 rvm 组
[root@arslinux-01 ~]# useradd -g rvm rvm
运行
[root@arslinux-01 ~]# source /etc/profile.d/rvm.sh
3)改rvm下载 ruby 的源,到镜像 ruby china
[root@arslinux-01 ~]# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ https://gems.ruby-china.com/ added to sources https://rubygems.org/ removed from sources
4)重新 \curl
[root@arslinux-01 ~]# \curl -sSL https://get.rvm.io | bash -s stable
5)安装完成后的 rvm 的版本
[root@arslinux-01 ~]# rvm -v rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
6)查看 rvm 库已知 ruby 版本
[root@arslinux-01 ~]# rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.10] [ruby-]2.2[.10] [ruby-]2.3[.8] [ruby-]2.4[.6] [ruby-]2.5[.5] [ruby-]2.6[.3] [ruby-]2.7[.0-preview1] ruby-head
7)安装 ruby 2.3.0
[root@arslinux-01 ~]# rvm install 2.3.0
8)安装完后 ruby 版本
[root@arslinux-01 ~]# ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
15、重新 gem install redis
[root@arslinux-01 ~]# gem install redis Fetching redis-4.1.2.gem Successfully installed redis-4.1.2 Parsing documentation for redis-4.1.2 Installing ri documentation for redis-4.1.2 Done installing documentation for redis after 2 seconds 1 gem installed
16、创建 cluster 主从
[root@arslinux-01 ~]# cp /usr/local/src/redis-4.0.1/src/redis-trib.rb /usr/bin/ [root@arslinux-01 ~]# redis-trib.rb create --replicas 1 192.168.194.130:7000 192.168.194.130:7002 192.168.194.130:7004 192.168.194.132:7001 192.168.194.132:7003 192.168.194.132:7005 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.194.130:7000 192.168.194.132:7001 192.168.194.130:7002 Adding replica 192.168.194.132:7003 to 192.168.194.130:7000 Adding replica 192.168.194.130:7004 to 192.168.194.132:7001 Adding replica 192.168.194.132:7005 to 192.168.194.130:7002 M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000 slots:0-5460 (5461 slots) master M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002 slots:10923-16383 (5461 slots) master S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004 replicates 62f3b3275922753035007d4dcc272c839baf45fd M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001 slots:5461-10922 (5462 slots) master S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003 replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005 replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 Can I set the above configuration? (type 'yes' to accept):
如果不满意配置,可以取消,重新更改后再配置,从分配规律上来看,应该是按端口号来分配的
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.194.130:7000) M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003 slots: (0 slots) slave replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005 slots: (0 slots) slave replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004 slots: (0 slots) slave replicates 62f3b3275922753035007d4dcc272c839baf45fd M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001 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.
21.25 redis集群操作
连接 redis 集群
redis-cli -c 加 -c 进入集群
[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000 192.168.194.130:7000> set key1 123 -> Redirected to slot [9189] located at 192.168.194.132:7001 OK 192.168.194.132:7001> set key2 abc -> Redirected to slot [4998] located at 192.168.194.130:7000 OK 192.168.194.130:7000> set key3 asdfadf OK 192.168.194.130:7000> set key4 safasdfafafaf -> Redirected to slot [13120] located at 192.168.194.130:7002 OK 192.168.194.130:7002> get key3 -> Redirected to slot [935] located at 192.168.194.130:7000 "asdfadf" 192.168.194.130:7000> get key4 -> Redirected to slot [13120] located at 192.168.194.130:7002 "safasdfafafaf"
任意一个节点都可以创建 key,或者查看 key
查看集群状态
[root@arslinux-01 ~]# redis-trib.rb check 192.168.194.130:7000 >>> Performing Cluster Check (using node 192.168.194.130:7000) M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003 slots: (0 slots) slave replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005 slots: (0 slots) slave replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004 slots: (0 slots) slave replicates 62f3b3275922753035007d4dcc272c839baf45fd M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001 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.
列出节点
[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000 192.168.194.130:7000> cluster nodes aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563200390518 5 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563200391000 2 connected 10923-16383 bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563200389000 6 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563200391523 4 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563200389509 4 connected 5461-10922 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563200390000 1 connected 0-5460 192.168.194.130:7000>
查看集群信息
192.168.194.130:7000> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:590 cluster_stats_messages_pong_sent:564 cluster_stats_messages_sent:1154 cluster_stats_messages_ping_received:559 cluster_stats_messages_pong_received:590 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:1154 192.168.194.130:7000>
添加节点
1、在B机器上添加一个 redis_7007.conf,并启动
[root@arslinux-02 ~]# cp /etc/redis_7001.conf /etc/redis_7007.conf [root@arslinux-02 ~]# vim !$ vim /etc/redis_7007.conf [root@arslinux-02 ~]# vim /etc/redis_7007.conf :1,$s/7001/7007/g [root@arslinux-02 ~]# mkdir /data/redis_data/7007 [root@arslinux-02 ~]# redis-server /etc/redis_7007.conf 11778:C 15 Jul 22:25:53.285 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 11778:C 15 Jul 22:25:53.286 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=11778, just started 11778:C 15 Jul 22:25:53.286 # Configuration loaded
2、在A机器上添加节点 CLUSTER MEET IP PORT
192.168.194.130:7000> CLUSTER MEET 192.168.194.132 7007 OK 192.168.194.130:7000> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:7 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:887 cluster_stats_messages_pong_sent:840 cluster_stats_messages_meet_sent:1 cluster_stats_messages_sent:1728 cluster_stats_messages_ping_received:835 cluster_stats_messages_pong_received:888 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:1728 192.168.194.130:7000> cluster nodes aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563200827000 5 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563200827000 2 connected 10923-16383 5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563200827911 0 connected bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563200829925 6 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563200827000 4 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563200828917 4 connected 5461-10922 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563200828000 1 connected 0-5460
7007已经添加进节点
3、在A机器上添加 redis_7006.conf 并启动
[root@arslinux-01 ~]# cp /etc/redis_7000.conf /etc/redis_7006.conf [root@arslinux-01 ~]# vim /etc/redis_7006.conf :1,$s/7000/7006/g [root@arslinux-01 ~]# mkdir /data/redis redis/ redis2/ redis_data/ [root@arslinux-01 ~]# mkdir /data/redis_data/7006 [root@arslinux-01 ~]# redis-server /etc/redis_7006.conf 30733:C 15 Jul 22:31:09.999 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 30733:C 15 Jul 22:31:09.999 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=30733, just started 30733:C 15 Jul 22:31:09.999 # Configuration loaded
4、添加节点后,发现新加入的也是作为 master 存在
[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000 192.168.194.130:7000> CLUSTER MEET 192.168.194.130 7006 OK 192.168.194.130:7000> CLUSTER NODES aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201239936 5 connected 8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 master - 0 1563201240000 0 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201239000 2 connected 10923-16383 5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201238000 0 connected bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201240947 6 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201239000 4 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201238000 4 connected 5461-10922 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201238000 1 connected 0-5460
如何将某个节点设为从呢?
将当前节点设置为指定节点的从
可以进到某个想要做为 master 的节点中,然后做 slave 的配置
[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7006 192.168.194.130:7006> CLUSTER REPLICATE 5ab4b80953ffe946608f288dad1d75e6136c7642 OK 192.168.194.130:7006> CLUSTER NODES aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201511361 1 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201510347 4 connected 5461-10922 5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201509140 7 connected bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201509339 2 connected 8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 myself,slave 5ab4b80953ffe946608f288dad1d75e6136c7642 0 1563201509000 0 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201509000 4 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201508330 2 connected 10923-16383 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 master - 0 1563201508000 1 connected 0-5460
移除节点
可以移除 slave,需要到非移除节点的 redis 里去移除
192.168.194.130:7006> CLUSTER FORGET 8b689873117d639562fb33044f2904454e936d31 (error) ERR I tried hard but I can't forget myself... 192.168.194.130:7006> quit [root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000 192.168.194.130:7000> CLUSTER FORGET 8b689873117d639562fb33044f2904454e936d31 OK 192.168.194.130:7000> CLUSTER NODES aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201752000 5 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201751000 2 connected 10923-16383 5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201752000 7 connected bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201752812 6 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201753820 4 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201751000 4 connected 5461-10922 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201749000 1 connected 0-5460
保存配置文件
192.168.194.130:7000> CLUSTER SAVECONFIG OK 192.168.194.130:7000> quit [root@arslinux-01 ~]# cat /data/redis_data/7000/nodes_7000.conf aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201851698 5 connected 8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 slave 5ab4b80953ffe946608f288dad1d75e6136c7642 0 1563201849684 7 connected 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201849000 2 connected 10923-16383 5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201848675 7 connected bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201849000 6 connected 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201850690 4 connected 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201851000 4 connected 5461-10922 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201847000 1 connected 0-5460 vars currentEpoch 7 lastVoteEpoch 0
扩展
redis 哨兵https://segmentfault.com/a/1190000002680804
http://www.cnblogs.com/jaycekon/p/6237562.html
标签:194.130,redis,192.168,cluster,预习,arslinux,0713,root 来源: https://blog.51cto.com/11530642/2420511