系統環境node
[root@node ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@node ~]# uname -a Linux node 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [root@node ~]# ifconfig eno16777736 eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.72 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:fec2:e84b prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c2:e8:4b txqueuelen 1000 (Ethernet) RX packets 115015 bytes 88316137 (84.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 35683 bytes 4729443 (4.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@node ~]#
Redis版本:linux
[root@node tools]# ls -l redis-3.2.12.tar.gz -rw-r--r-- 1 root root 1551468 Jun 14 00:51 redis-3.2.12.tar.gz [root@node tools]#
Redis集羣介紹:git
Redis 是一個開源的 key-value 存儲系統,因爲出衆的性能,大部分互聯網企業都用來作服務器端緩存。Redis 在3.0版本前只支持單實例模式,雖然支持主從模式、哨兵模式部署來解決單點故障,可是如今互聯網企業動輒大幾百G的數據,可徹底是無法知足業務的需求,因此,
Redis 在 3.0 版本之後就推出了集羣模式。Redis 集羣採用了P2P的模式,徹底去中心化。Redis 把全部的 Key 分紅了 16384 個 slot,每一個 Redis 實例負責其中一部分 slot 。集羣中的全部信息(節點、端口、slot等),都經過節點之間按期的數據交換而更新。
Redis 客戶端能夠在任意一個 Redis 實例發出請求,若是所需數據不在該實例中,經過重定向命令引導客戶端訪問所需的實例。下面說一下 Redis 集羣搭建規劃,因爲集羣至少須要6個節點(3主3從模式),因此,沒有這麼多機器給我玩,我本地也起不了那麼多虛擬機(電腦太爛),如今計劃是在一臺機器上模擬一個集羣,固然,這和生產環境的集羣搭建沒本質區別。
我如今就要在已經有安裝了 Redis 的一個 CentOS 下開始進行集羣搭建,若是你還不是很清楚 Linux 下如何安裝 Redis 。請注意,下面全部集羣搭建環境都基於已安裝好的 Redis 作的。github
部署過程:redis
[root@node tools]# tar xf redis-3.2.12.tar.gz [root@node tools]# ll total 1520 drwxrwxr-x 6 root root 4096 Jun 13 18:47 redis-3.2.12 -rw-r--r-- 1 root root 1551468 Jun 14 00:51 redis-3.2.12.tar.gz [root@node tools]#
這裏咱們以端口進行區分實例,分別是7001~7006,建立對應項目目錄sql
[root@node tools]# mkdir -p /application/redis/700{1,2,3,4,5,6}/{conf,data,log,run} [root@node tools]# tree /application/redis/ /application/redis/ ├── 7001 │ ├── conf │ ├── data │ ├── log │ └── run ├── 7002 │ ├── conf │ ├── data │ ├── log │ └── run ├── 7003 │ ├── conf │ ├── data │ ├── log │ └── run ├── 7004 │ ├── conf │ ├── data │ ├── log │ └── run ├── 7005 │ ├── conf │ ├── data │ ├── log │ └── run └── 7006 ├── conf ├── data ├── log └── run 30 directories, 0 files [root@node tools]#
[root@node tools]# tar xf redis-3.2.12.tar.gz [root@node tools]# cd redis-3.2.12 [root@node redis-3.2.12]# make MALLOC=jemalloc [root@node redis-3.2.12]# make PREFIX=/application/redis/7001/ install [root@node redis-3.2.12]# tree /application/redis/7001/ /application/redis/7001/ ├── bin │ ├── redis-benchmark │ ├── redis-check-aof │ ├── redis-check-rdb │ ├── redis-cli │ ├── redis-sentinel -> redis-server │ └── redis-server ├── conf ├── data ├── log └── run 5 directories, 6 files [root@node redis-3.2.12]# [root@node redis-3.2.12]# pwd /root/tools/redis-3.2.12 [root@node redis-3.2.12]# cp redis.conf /application/redis/7001/conf/ [root@node redis-3.2.12]#
拷貝/application/redis/7001目錄下的內容到 700二、700三、700四、700五、7006目錄下;json
[root@node redis-3.2.12]# \cp -rf /application/redis/7001/* /application/redis/7002/ [root@node redis-3.2.12]# \cp -rf /application/redis/7001/* /application/redis/7003/ [root@node redis-3.2.12]# \cp -rf /application/redis/7001/* /application/redis/7004/ [root@node redis-3.2.12]# \cp -rf /application/redis/7001/* /application/redis/7005/ [root@node redis-3.2.12]# \cp -rf /application/redis/7001/* /application/redis/7006/ [root@node redis-3.2.12]#
配置文件redis.conf中對應的配置項根據實際路徑修改以下所示:centos
daemonize yes (以守護進程模式啓動)
bind 127.0.0.1 192.168.0.72 (綁定本地127.0.0.1和對外網卡192。168.0.72兩個ip上)
pidfile /application/redis/7001/run/redis_7001.pid (定義啓動redis的pid進程文件存放路徑)
logfile "/application/redis/7001/log/redis_7001.log" (定義日誌存放路徑)
dir /application/redis/7001/data/ (定義數據存放路徑)
cluster-enabled yes (啓動集羣功能支持集羣)
cluster-config-file /application/redis/7001/conf/nodes-7001.conf (集羣配置文件存放路徑)
cluster-node-timeout 15000 (集羣節點之間通訊超時時間)緩存
啓動Redis實例ruby
[root@node ~]# /application/redis/7001/bin/redis-server /application/redis/7001/conf/redis.conf [root@node ~]# /application/redis/7002/bin/redis-server /application/redis/7002/conf/redis.conf [root@node ~]# /application/redis/7003/bin/redis-server /application/redis/7003/conf/redis.conf [root@node ~]# /application/redis/7004/bin/redis-server /application/redis/7004/conf/redis.conf [root@node ~]# /application/redis/7005/bin/redis-server /application/redis/7005/conf/redis.conf [root@node ~]# /application/redis/7006/bin/redis-server /application/redis/7006/conf/redis.conf [root@node ~]# [root@node ~]# ps xua|grep redis root 13802 0.2 0.2 138964 9816 ? Ssl 09:12 0:12 /application/redis/7001/bin/redis-server 127.0.0.1:7001 [cluster] root 13806 0.2 0.2 138964 9820 ? Ssl 09:12 0:12 /application/redis/7002/bin/redis-server 127.0.0.1:7002 [cluster] root 13810 0.2 0.2 138964 9812 ? Ssl 09:12 0:12 /application/redis/7003/bin/redis-server 127.0.0.1:7003 [cluster] root 13814 0.2 0.2 136916 7768 ? Ssl 09:12 0:12 /application/redis/7004/bin/redis-server 127.0.0.1:7004 [cluster] root 13818 0.2 0.2 136916 7772 ? Ssl 09:12 0:12 /application/redis/7005/bin/redis-server 127.0.0.1:7005 [cluster] root 13822 0.2 0.2 136916 7760 ? Ssl 09:13 0:12 /application/redis/7006/bin/redis-server 127.0.0.1:7006 [cluster] root 35592 0.0 0.0 112648 952 pts/0 S+ 10:49 0:00 grep --color=auto redis [root@node ~]# [root@node ~]# netstat -lnupt|grep redis|grep 192.168.0.72 tcp 0 0 192.168.0.72:17001 0.0.0.0:* LISTEN 13802/redis-server tcp 0 0 192.168.0.72:17002 0.0.0.0:* LISTEN 13806/redis-server tcp 0 0 192.168.0.72:17003 0.0.0.0:* LISTEN 13810/redis-server tcp 0 0 192.168.0.72:17004 0.0.0.0:* LISTEN 13814/redis-server tcp 0 0 192.168.0.72:17005 0.0.0.0:* LISTEN 13818/redis-server tcp 0 0 192.168.0.72:17006 0.0.0.0:* LISTEN 13822/redis-server tcp 0 0 192.168.0.72:7001 0.0.0.0:* LISTEN 13802/redis-server tcp 0 0 192.168.0.72:7002 0.0.0.0:* LISTEN 13806/redis-server tcp 0 0 192.168.0.72:7003 0.0.0.0:* LISTEN 13810/redis-server tcp 0 0 192.168.0.72:7004 0.0.0.0:* LISTEN 13814/redis-server tcp 0 0 192.168.0.72:7005 0.0.0.0:* LISTEN 13818/redis-server tcp 0 0 192.168.0.72:7006 0.0.0.0:* LISTEN 13822/redis-server [root@node ~]#
驗證是否能夠進行寫入:
[root@node src]# /root/tools/redis-3.2.12/src/redis-cli -h 127.0.0.1 -p 7006 127.0.0.1:7006> keys * (empty list or set) 127.0.0.1:7006> set name redis (error) CLUSTERDOWN Hash slot not served 127.0.0.1:7006> 127.0.0.1:7006> set name redis (error) CLUSTERDOWN Hash slot not served 127.0.0.1:7006>
鏈接成功了,可是寫入報錯,集羣處於down狀態,Hash slot not served,沒有存儲的位置,其實就是沒有slot(也就是前面說的slot槽)
因此咱們解決這個問題
yum install ruby yum install rubygems gem install redis
[root@node redis]# yum install ruby rubygems Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.cn99.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package ruby.x86_64 0:2.0.0.648-33.el7_4 will be installed --> Processing Dependency: ruby-libs(x86-64) = 2.0.0.648-33.el7_4 for package: ruby-2.0.0.648-33.el7_4.x86_64 --> Processing Dependency: rubygem(bigdecimal) >= 1.2.0 for package: ruby-2.0.0.648-33.el7_4.x86_64 --> Processing Dependency: libruby.so.2.0()(64bit) for package: ruby-2.0.0.648-33.el7_4.x86_64 ---> Package rubygems.noarch 0:2.0.14.1-33.el7_4 will be installed --> Processing Dependency: rubygem(rdoc) >= 4.0.0 for package: rubygems-2.0.14.1-33.el7_4.noarch --> Processing Dependency: rubygem(psych) >= 2.0.0 for package: rubygems-2.0.14.1-33.el7_4.noarch --> Processing Dependency: rubygem(io-console) >= 0.4.2 for package: rubygems-2.0.14.1-33.el7_4.noarch --> Running transaction check ---> Package ruby-libs.x86_64 0:2.0.0.648-33.el7_4 will be installed --> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: ruby-libs-2.0.0.648-33.el7_4.x86_64 ---> Package rubygem-bigdecimal.x86_64 0:1.2.0-33.el7_4 will be installed ---> Package rubygem-io-console.x86_64 0:0.4.2-33.el7_4 will be installed ---> Package rubygem-psych.x86_64 0:2.0.0-33.el7_4 will be installed --> Processing Dependency: libyaml-0.so.2()(64bit) for package: rubygem-psych-2.0.0-33.el7_4.x86_64 ---> Package rubygem-rdoc.noarch 0:4.0.0-33.el7_4 will be installed --> Processing Dependency: ruby(irb) = 2.0.0.648 for package: rubygem-rdoc-4.0.0-33.el7_4.noarch --> Processing Dependency: rubygem(json) >= 1.7.7 for package: rubygem-rdoc-4.0.0-33.el7_4.noarch --> Running transaction check ---> Package libyaml.x86_64 0:0.1.4-11.el7_0 will be installed ---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated --> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64 ---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update ---> Package ruby-irb.noarch 0:2.0.0.648-33.el7_4 will be installed ---> Package rubygem-json.x86_64 0:1.7.7-33.el7_4 will be installed --> Running transaction check ---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated ---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================================================================================================================= Installing: ruby x86_64 2.0.0.648-33.el7_4 base 71 k rubygems noarch 2.0.14.1-33.el7_4 base 219 k Installing for dependencies: libyaml x86_64 0.1.4-11.el7_0 base 55 k ruby-irb noarch 2.0.0.648-33.el7_4 base 92 k ruby-libs x86_64 2.0.0.648-33.el7_4 base 2.8 M rubygem-bigdecimal x86_64 1.2.0-33.el7_4 base 83 k rubygem-io-console x86_64 0.4.2-33.el7_4 base 54 k rubygem-json x86_64 1.7.7-33.el7_4 base 79 k rubygem-psych x86_64 2.0.0-33.el7_4 base 82 k rubygem-rdoc noarch 4.0.0-33.el7_4 base 322 k Updating for dependencies: openssl x86_64 1:1.0.2k-12.el7 base 492 k openssl-libs x86_64 1:1.0.2k-12.el7 base 1.2 M Transaction Summary ========================================================================================================================================================================================================================================================= Install 2 Packages (+8 Dependent packages) Upgrade ( 2 Dependent packages) Total download size: 5.5 M Is this ok [y/d/N]: y Installed: ruby.x86_64 0:2.0.0.648-33.el7_4 rubygems.noarch 0:2.0.14.1-33.el7_4 Dependency Installed: libyaml.x86_64 0:0.1.4-11.el7_0 ruby-irb.noarch 0:2.0.0.648-33.el7_4 ruby-libs.x86_64 0:2.0.0.648-33.el7_4 rubygem-bigdecimal.x86_64 0:1.2.0-33.el7_4 rubygem-io-console.x86_64 0:0.4.2-33.el7_4 rubygem-json.x86_64 0:1.7.7-33.el7_4 rubygem-psych.x86_64 0:2.0.0-33.el7_4 rubygem-rdoc.noarch 0:4.0.0-33.el7_4 Dependency Updated: openssl.x86_64 1:1.0.2k-12.el7 openssl-libs.x86_64 1:1.0.2k-12.el7 Complete! [root@node redis]# [root@node redis]# gem install redis Fetching: redis-4.0.1.gem (100%) ERROR: Error installing redis: redis requires Ruby version >= 2.2.2. [root@node redis]#
提示Ruby版本太低,至少要求2.2.2版本,解決版本問題
[root@node redis]# ruby --version ruby 2.0.0p648 (2015-12-16) [x86_64-linux] [root@node redis]# rvm remove 2.0.0 awk: fatal: cannot open file `/usr/local/rvm/config/alias' for reading (No such file or directory) ruby-2.0.0-p648 - #already gone Now using system ruby. [root@node redis]# rvm remove 2.0.0p648 awk: fatal: cannot open file `/usr/local/rvm/config/alias' for reading (No such file or directory) ruby-2.0.0p648 - #already gone Now using system ruby. [root@node redis]# 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[.7] [ruby-]2.4[.4] [ruby-]2.5[.1] [ruby-]2.6[.0-preview2] ruby-head # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2 # JRuby jruby-1.6[.8] jruby-1.7[.27] jruby-9.1[.17.0] jruby[-9.2.0.0] jruby-head # Rubinius rbx-1[.4.3] rbx-2.3[.0] rbx-2.4[.1] rbx-2[.5.8] rbx-3[.100] rbx-head # TruffleRuby truffleruby[-1.0.0-rc2] # Opal opal # Minimalistic ruby implementation - ISO 30170:2012 mruby-1.0.0 mruby-1.1.0 mruby-1.2.0 mruby-1.3.0 mruby-1[.4.0] mruby[-head] # Ruby Enterprise Edition ree-1.8.6 ree[-1.8.7][-2012.02] # Topaz topaz # MagLev maglev-1.0.0 maglev-1.1[RC1] maglev[-1.2Alpha4] maglev-head # Mac OS X Snow Leopard Or Newer macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head # IronRuby ironruby[-1.1.3] ironruby-head [root@node redis]# [root@node redis]# rvm install ruby-2.3.3 Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.3.3.tar.bz2 Checking requirements for centos. Installing requirements for centos. Installing required packages: libffi-devel, readline-devel, sqlite-devel, zlib-devel, openssl-devel.................................. Requirements installation successful. ruby-2.3.3 - #configure ruby-2.3.3 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 25.2M 100 25.2M 0 0 338k 0 0:01:16 0:01:16 --:--:-- 332k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.3.3 - #validate archive ruby-2.3.3 - #extract ruby-2.3.3 - #validate binary ruby-2.3.3 - #setup ruby-2.3.3 - #gemset created /usr/local/rvm/gems/ruby-2.3.3@global ruby-2.3.3 - #importing gemset /usr/local/rvm/gemsets/global.gems............................................. ruby-2.3.3 - #generating global wrappers....... ruby-2.3.3 - #gemset created /usr/local/rvm/gems/ruby-2.3.3 ruby-2.3.3 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.3.3 - #generating default wrappers....... [root@node redis]# 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[.7] [ruby-]2.4[.4] [ruby-]2.5[.1] [ruby-]2.6[.0-preview2] ruby-head # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2 # JRuby jruby-1.6[.8] jruby-1.7[.27] jruby-9.1[.17.0] jruby[-9.2.0.0] jruby-head # Rubinius rbx-1[.4.3] rbx-2.3[.0] rbx-2.4[.1] rbx-2[.5.8] rbx-3[.100] rbx-head # TruffleRuby truffleruby[-1.0.0-rc2] # Opal opal # Minimalistic ruby implementation - ISO 30170:2012 mruby-1.0.0 mruby-1.1.0 mruby-1.2.0 mruby-1.3.0 mruby-1[.4.0] mruby[-head] # Ruby Enterprise Edition ree-1.8.6 ree[-1.8.7][-2012.02] # Topaz topaz # MagLev maglev-1.0.0 maglev-1.1[RC1] maglev[-1.2Alpha4] maglev-head # Mac OS X Snow Leopard Or Newer macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head # IronRuby ironruby[-1.1.3] ironruby-head [root@node redis]# rvm use 2.3.3 --default Using /usr/local/rvm/gems/ruby-2.3.3 [root@node redis]# gem install redis Fetching: redis-4.0.1.gem (100%) Successfully installed redis-4.0.1 Parsing documentation for redis-4.0.1 Installing ri documentation for redis-4.0.1 Done installing documentation for redis after 0 seconds 1 gem installed [root@node redis]# [root@node redis]# ruby --version ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] [root@node redis]# gem install redis Successfully installed redis-4.0.1 Parsing documentation for redis-4.0.1 Done installing documentation for redis after 0 seconds 1 gem installed [root@node redis]#
啓動redis實例:
[root@node redis]# /application/redis/7002/bin/redis-server /application/redis/7002/conf/redis.conf [root@node redis]# /application/redis/7003/bin/redis-server /application/redis/7003/conf/redis.conf [root@node redis]# /application/redis/7004/bin/redis-server /application/redis/7004/conf/redis.conf [root@node redis]# /application/redis/7005/bin/redis-server /application/redis/7005/conf/redis.conf [root@node redis]# /application/redis/7006/bin/redis-server /application/redis/7006/conf/redis.conf [root@node redis]# ps xua|grep redis root 35684 0.2 0.7 136916 7572 ? Ssl 22:31 0:00 /application/redis/7001/bin/redis-server 127.0.0.1:7001 [cluster] root 35688 0.1 0.7 136916 7572 ? Ssl 22:31 0:00 /application/redis/7002/bin/redis-server 127.0.0.1:7002 [cluster] root 35692 0.2 0.7 136916 7572 ? Ssl 22:31 0:00 /application/redis/7003/bin/redis-server 127.0.0.1:7003 [cluster] root 35696 0.2 0.7 136916 7568 ? Ssl 22:31 0:00 /application/redis/7004/bin/redis-server 127.0.0.1:7004 [cluster] root 35700 0.2 0.7 136916 7568 ? Ssl 22:31 0:00 /application/redis/7005/bin/redis-server 127.0.0.1:7005 [cluster] root 35704 0.1 0.7 136916 7572 ? Ssl 22:31 0:00 /application/redis/7006/bin/redis-server 127.0.0.1:7006 [cluster] root 35708 0.0 0.0 112648 952 pts/0 S+ 22:31 0:00 grep --color=auto redis [root@node redis]#
經過以下命令建立集羣:
S: aec9e99f007c811cb45bce171dcc0352beae2d55 192.168.0.198:7006 replicates 66ecedcca2644618bac596cce8ecdb930970dc11 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.0.198:7001) M: c29de69492d3555afe0438ed5ed7cfa30d7cd360 192.168.0.198:7001 slots:0-5460 (5461 slots) master 1 additional replica(s) S: 7d8dc86edf72436a64c63e296c96663993aa4add 127.0.0.1:7005 slots: (0 slots) slave replicates 907d8a3ed18d1365035063908266ac6ea49c765e M: 907d8a3ed18d1365035063908266ac6ea49c765e 127.0.0.1:7002 slots:5461-10922 (5462 slots) master 1 additional replica(s) S: 9a586eb27ffdc6d5a50ff1810c0b24684baf2dbb 127.0.0.1:7004 slots: (0 slots) slave replicates c29de69492d3555afe0438ed5ed7cfa30d7cd360 S: aec9e99f007c811cb45bce171dcc0352beae2d55 127.0.0.1:7006 slots: (0 slots) slave replicates 66ecedcca2644618bac596cce8ecdb930970dc11 M: 66ecedcca2644618bac596cce8ecdb930970dc11 127.0.0.1:7003 slots:10923-16383 (5461 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@node redis]#
看到沒有報錯,提示ALL 16384個slotscoverd表示集羣建立完成,能夠查看集羣狀態:
簡要說明:
從以上能夠看到7001~7003是主節點,也就是master節點,7004~7006是從節點,其中經過字母M和S來表示
M:表示master節點,其中後面長串字母 「c29de69492d3555afe0438ed5ed7cfa30d7cd360」 表示id,
S:表示slave節點
建立集羣,經過調用 ruby 命令來進行建立,--replicas 1 表示主從複製比例爲 1:1,即一個主節點對應一個從節點;而後,默認給咱們分配好了每一個主節點和對應從節點服務,以及 solt 的大小,由於在 Redis 集羣中有且僅有 16383 個 solt ,默認狀況會給咱們平均分配,固然你能夠指定,後續的增減節點也能夠從新分配。
登陸集羣查看集羣信息並驗證是否以寫入和讀取數據:
[root@node redis]# /root/tools/redis-3.2.12/src/redis-cli -c -h 127.0.0.1 -p 7001 127.0.0.1:7001> 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_sent:879 cluster_stats_messages_received:879 127.0.0.1:7001> cluster nodes 7d8dc86edf72436a64c63e296c96663993aa4add 127.0.0.1:7005 slave 907d8a3ed18d1365035063908266ac6ea49c765e 0 1532788809741 5 connected 907d8a3ed18d1365035063908266ac6ea49c765e 127.0.0.1:7002 master - 0 1532788809237 2 connected 5461-10922 9a586eb27ffdc6d5a50ff1810c0b24684baf2dbb 127.0.0.1:7004 slave c29de69492d3555afe0438ed5ed7cfa30d7cd360 0 1532788807724 4 connected aec9e99f007c811cb45bce171dcc0352beae2d55 127.0.0.1:7006 slave 66ecedcca2644618bac596cce8ecdb930970dc11 0 1532788806714 6 connected c29de69492d3555afe0438ed5ed7cfa30d7cd360 192.168.0.198:7001 myself,master - 0 0 1 connected 0-5460 66ecedcca2644618bac596cce8ecdb930970dc11 127.0.0.1:7003 master - 0 1532788808734 3 connected 10923-16383 127.0.0.1:7001>
127.0.0.1:7001> set name keys -> Redirected to slot [5798] located at 127.0.0.1:7002 OK 127.0.0.1:7002> get name "keys" 127.0.0.1:7001> exit [root@node redis]# /root/tools/redis-3.2.12/src/redis-cli -c -h 127.0.0.1 -p 7002 127.0.0.1:7002> get name "keys" 127.0.0.1:7002>
發現能夠正常讀寫數據,說明redis集羣搭建成功。接下來可能就是動態擴容、增長節點和減小節點,從新分配槽大小等,固然,還有最重要的就是怎麼和咱們程序結合起來,以及如何更好的把 Redis 緩存集羣發揮出應有的效果,這些纔是最重要的。