21.22 redis集羣介紹html
多個redis節點網絡互聯,數據共享node
全部的節點都是一主一從(能夠是多個從),其中從不提供服務,僅做爲備用linux
不支持同時處理多個鍵(如mset/mget),由於redis須要把鍵均勻分佈在各個節點上,併發量很高的狀況下同時建立鍵值會下降性能並致使不可預測的行爲。git
支持在線增長、刪除節點github
客戶端能夠連任何一個主節點進行讀寫redis
21.23/21.24 redis集羣搭建配置shell
一、場景設置:vim
兩臺機器,分別開啓三個 Redis 服務(端口)segmentfault
A機器上三個端口7000,7002,7004,所有爲主windows
B機器上三個端口7001,7003,7005,所有爲從
兩臺機器上都要編譯安裝redis,而後編輯並複製 3 個不一樣的 redis.conf,分別設置不一樣的端口號、dir等參數,還須要增長 cluster 相關參數,而後分別啓動6個 redis 服務
三、在 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
三、建立目錄
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}
四、在 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」
五、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]
六、關閉防火牆
七、安裝組 (只需在一臺機器上安裝便可)
[root@arslinux-01 ~]# yum -y groupinstall "Development Tools"
過程省略
八、安裝相關的包
[root@arslinux-01 ~]# yum -y install gdbm-devel libdb4-devel libffi-devel libyaml libyaml-devel ncurses-devel openssl-devel readline-devel tcl-deve
九、建立目錄,下載源碼包
[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
十、下載 Ruby2x.spec 的文件
[root@arslinux-01 ~]# wget https://raw.githubusercontent.com/tjinjin/automate-ruby-rpm/master/ruby22x.spec -P rpmbuild/SPECS
十一、編譯製做 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
十二、yum 安裝本地 rpm 包(避免依賴的問題)
[root@arslinux-01 ~]# yum -y localinstall rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
1三、安裝出錯,版本不對
[root@arslinux-01 ~]# gem install redis Fetching: redis-4.1.2.gem (100%) ERROR: Error installing redis: redis requires Ruby version >= 2.3.0.
1四、安裝 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]
1五、從新 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
1六、建立 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>
添加節點
一、在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
二、在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已經添加進節點
三、在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
四、添加節點後,發現新加入的也是做爲 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 基礎知識前半部分:http://www.javashuo.com/article/p-mfujleiu-bb.html
擴展
redis 哨兵https://segmentfault.com/a/1190000002680804
http://www.cnblogs.com/jaycekon/p/6237562.html