博文目錄
創(chuàng)新互聯(lián)建站成立以來不斷整合自身及行業(yè)資源、不斷突破觀念以使企業(yè)策略得到完善和成熟,建立了一套“以技術(shù)為基點(diǎn),以客戶需求中心、市場(chǎng)為導(dǎo)向”的快速反應(yīng)體系。對(duì)公司的主營(yíng)項(xiàng)目,如中高端企業(yè)網(wǎng)站企劃 / 設(shè)計(jì)、行業(yè) / 企業(yè)門戶設(shè)計(jì)推廣、行業(yè)門戶平臺(tái)運(yùn)營(yíng)、手機(jī)APP定制開發(fā)、手機(jī)網(wǎng)站制作、微信網(wǎng)站制作、軟件開發(fā)、簡(jiǎn)陽(yáng)服務(wù)器托管等實(shí)行標(biāo)準(zhǔn)化操作,讓客戶可以直觀的預(yù)知到從創(chuàng)新互聯(lián)建站可以獲得的服務(wù)效果。
一、Redis群集原理
1、架構(gòu)細(xì)節(jié)
2、Redis選舉
二、搭建Redis群集
1、安裝第一臺(tái)Redis并修改配置文件
2、安裝第二臺(tái)Redis并修改配置文件
3、使用腳本創(chuàng)建群集
4、測(cè)試群集
關(guān)于Redis非關(guān)系型數(shù)據(jù)庫(kù)工作原理詳述請(qǐng)參考博文:聊一聊Centos 7中的Redis(非關(guān)系型數(shù)據(jù)庫(kù))
Redis Cluster是一個(gè)無中心的結(jié)構(gòu),每個(gè)節(jié)點(diǎn)都保存數(shù)據(jù)和整個(gè)群集的狀態(tài)。每個(gè)節(jié)點(diǎn)都會(huì)保存其他節(jié)點(diǎn)的信息,知道其他節(jié)點(diǎn)鎖負(fù)責(zé)的槽,并且會(huì)與其他節(jié)點(diǎn)定時(shí)發(fā)送心跳信息,能夠及時(shí)感知群集中異常的節(jié)點(diǎn)。如下圖所示:
當(dāng)客戶端向群集中任一節(jié)點(diǎn)發(fā)送與數(shù)據(jù)庫(kù)鍵有關(guān)的命令時(shí),接受命令的節(jié)點(diǎn)會(huì)計(jì)算出命令要處理的數(shù)據(jù)庫(kù)鍵屬于哪個(gè)槽,并檢查這個(gè)槽是否指派給了自己。如果鍵所在的槽正好指派給了當(dāng)前節(jié)點(diǎn),那么節(jié)點(diǎn)直接執(zhí)行這個(gè)命令;如果鍵所在的槽并沒有指派給當(dāng)前節(jié)點(diǎn),那么節(jié)點(diǎn)會(huì)向客戶端返回一個(gè)MOVED錯(cuò)誤,指引客戶端轉(zhuǎn)向(redirect)正確的節(jié)點(diǎn),并再次發(fā)送之前想要執(zhí)行的命令。
群集角色有Master和Slave。Master之間分配slots,一共有16384個(gè)slot。Slave向它指定的Master同步數(shù)據(jù),實(shí)現(xiàn)備份。當(dāng)其中一個(gè)Master無法提供服務(wù)時(shí),該Master的Slave將提升為Master。以保證群集鍵slot的完整性。當(dāng)其中的某一個(gè)Master和它的Slave都失效,就會(huì)導(dǎo)致slot不完整,群集失效,這是就需要人工去處理了。
群集搭建好后,群集中的每個(gè)節(jié)點(diǎn)都會(huì)定期地想其他節(jié)點(diǎn)發(fā)送PING消息,如果接收PING消息的節(jié)點(diǎn)沒有在規(guī)定的時(shí)間內(nèi)返回PONG消息,那么發(fā)送PING消息的節(jié)點(diǎn)就會(huì)將其標(biāo)記為疑似下線(PFAIL)。各個(gè)節(jié)點(diǎn)會(huì)通過互相發(fā)送消息的方式來交換群集中各個(gè)節(jié)點(diǎn)的狀態(tài)信息。如果在一個(gè)群集里面,半數(shù)以上的主節(jié)點(diǎn)都將某個(gè)節(jié)點(diǎn) X 報(bào)告為疑似下線,那么這個(gè)主節(jié)點(diǎn) X 將被標(biāo)記為已下線(FAIL),同時(shí)會(huì)向群集廣播一條關(guān)于主節(jié)點(diǎn) X 的FAIL消息,所有收到這條FAIL消息的節(jié)點(diǎn)都會(huì)立即將主節(jié)點(diǎn) X 標(biāo)記為已下線。
當(dāng)需要減少或增加群集中的機(jī)器時(shí),我們需要將已經(jīng)指派給某個(gè)節(jié)點(diǎn)(源節(jié)點(diǎn))的槽改為指派給另一個(gè)節(jié)點(diǎn)(目標(biāo)節(jié)點(diǎn)),并且將相關(guān)槽所屬的鍵值對(duì)從源節(jié)點(diǎn)移動(dòng)到目標(biāo)節(jié)點(diǎn)。
Redis群集的重新分片操作是由Redis的群集管理軟件redis-trib負(fù)責(zé)執(zhí)行的,不支持自動(dòng)的分片,而且需要自己計(jì)算從哪些節(jié)點(diǎn)上遷移多少Slot。在重新分片的過程中,群集不需要下線,并且源節(jié)點(diǎn)和目標(biāo)節(jié)點(diǎn)都可以繼續(xù)處理命令請(qǐng)求。
所有的redis節(jié)點(diǎn)彼此互聯(lián)(PING-PONG機(jī)制),內(nèi)部使用二進(jìn)制協(xié)議優(yōu)化傳輸速度和帶寬;
節(jié)點(diǎn)的失效(fail)在群集中超過半數(shù)的主(master)節(jié)點(diǎn)檢測(cè)失效才失效;
客戶端與redis節(jié)點(diǎn)直連,不需要中間代理(proxy)層,客戶端不需要連接群集所有節(jié)點(diǎn),連接群集中任何一個(gè)可用節(jié)點(diǎn)即可;
- redis-cluster把所有的物理節(jié)點(diǎn)映射到【0-16383】slot上,cluster 負(fù)責(zé)維護(hù)node<->slot<->key;
如下圖所示:選舉過程是群集中所有master參與,如果半數(shù)以上master節(jié)點(diǎn)與當(dāng)前master節(jié)點(diǎn)通信超時(shí)(cluster-node-timeout),認(rèn)為當(dāng)前master節(jié)點(diǎn)掛掉。
以下兩種情況為整個(gè)群集不可用(cluster_state:fail),當(dāng)群集不可用時(shí),所有對(duì)群集的操作都不可用,收到((error) CLUSTERDOWN The cluster is down)錯(cuò)誤。
如果群集任意master掛掉,且當(dāng)前master沒有slave,則群集進(jìn)入fail狀態(tài),也可以理解為群集的slot映射[0-16383]不完整時(shí)進(jìn)入的fail狀態(tài);
- 如果群集中出現(xiàn)半數(shù)的master掛掉,無論是否有slave,群集都進(jìn)入fail狀態(tài);默認(rèn)情況下,每個(gè)群集的節(jié)點(diǎn)都使用兩個(gè)TCP端口,一個(gè)是6379,一個(gè)16379;6379服務(wù)用于客戶端的連接,16379用于群集總線,即使用二進(jìn)制協(xié)議的節(jié)點(diǎn)到節(jié)點(diǎn)通信通道。節(jié)點(diǎn)使用群集總線進(jìn)行故障檢測(cè)、配置更新、故障轉(zhuǎn)移授權(quán)等。如果開啟了防火墻,需要開放這兩個(gè)端口。
環(huán)境描述:
此案例的環(huán)境采用6臺(tái)Centos 7服務(wù)器搭建Redis群集,其中3臺(tái)為master,3臺(tái)為salve;
6臺(tái)服務(wù)器的IP地址為192.168.100.10/24——192.168.100.60/24;
自行準(zhǔn)備所需源碼包即工具,也可以訪問:https://pan.baidu.com/s/126siXcoxrqBWmp9SWhEVmQ
提取碼:a45i ;
自行配置網(wǎng)絡(luò)及防火墻,放行TCP的6379和16379這兩個(gè)端口,我這里直接關(guān)閉了防火墻;
自行通過rz命令將redis壓縮包和redis的gem文件上傳到服務(wù)器;
廢話少說,大點(diǎn)干早點(diǎn)散,開始干活...
[root@centos01 ~]# ls <!--查看redis壓縮包和redis的gem文件是否上傳成功-->
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.0.gem redis-3.2.9.tar.gz
[root@centos01 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/ <!--redis解壓縮到/usr/src/目錄-->
[root@centos01 ~]# mv /usr/src/redis-3.2.9/ /usr/src/redis/
<!--將redis所有配置文件剪切到/usr/src/redis/目錄 -->
[root@centos01 ~]# cd /usr/src/redis/ <!--進(jìn)入redis目錄->
[root@centos01 redis]# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src
[root@centos01 redis]# make && make install <!--編輯及安裝redis-->
[root@centos01 redis]# cd utils/ <!--進(jìn)入utils目錄-->
[root@centos01 utils]# ./install_server.sh <!--初始化redis-->
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] <!--回車鍵即可-->
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] <!--回車鍵即可-->
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] <!--回車鍵即可-->
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] <!--回車鍵即可-->
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] <!--回車鍵即可-->
Selected config:
Port : 6379 <!--端口號(hào),默認(rèn)允許6379-->
Config file : /etc/redis/6379.conf <!--redis主配置文件-->
Log file : /var/log/redis_6379.log <!--redis日志文件-->
Data dir : /var/lib/redis/6379 <!--設(shè)置數(shù)據(jù)目錄-->
Executable : /usr/local/bin/redis-server <!--執(zhí)行命令-->
Cli Executable : /usr/local/bin/redis-cli <!--客戶端命令-->
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@centos01 ~]# vim /etc/redis/6379.conf <!--修改redis主配置文件啟動(dòng)群集功能-->
62 bind 192.168.100.10 <!--監(jiān)聽的主機(jī)地址-->
85 port 6379 <!--監(jiān)聽端口號(hào)-->
129 daemonize yes <!--啟動(dòng)守護(hù)進(jìn)程-->
164 logfile /var/log/redis_6379.log <!--指定日志文件-->
722 cluster-enabled yes <!--啟動(dòng)群集-->
730 cluster-config-file nodes-6379.conf <!--群集配置文件-->
736 cluster-node-timeout 15000
813 cluster-require-full-coverage no
[root@centos01 ~]# /etc/init.d/redis_6379 start <!--啟動(dòng)redis服務(wù)-->
Starting Redis server...
[root@centos01 ~]# netstat -anptu | grep redis
<!--查看6379和16379端口是否已經(jīng)正常啟動(dòng)-->
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 4662/redis-server 1
tcp 0 0 192.168.100.10:16379 0.0.0.0:* LISTEN 4662/redis-server 1
[root@centos01 ~]# yum -y install ruby rubygems <!--安裝群集所需依賴程序-->
[root@centos01 ~]# gem install redis --version 3.2.0 <!--安裝gem工具-->
<!--j接下來將redis壓縮包遠(yuǎn)程復(fù)制到100.20、30、40、50、60服務(wù)器的根目錄-->
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.20:/root
<!--將redis壓縮包復(fù)制到100.20服務(wù)器的根目錄-->
The authenticity of host '192.168.100.20 (192.168.100.20)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes <!--輸入yes-->
Warning: Permanently added '192.168.100.20' (ECDSA) to the list of known hosts.
root@192.168.100.20's password: <!--輸入密碼-->
redis-3.2.9.tar.gz 100% 1511KB 44.5MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.30:/root
<!--將redis壓縮包復(fù)制到100.30服務(wù)器的根目錄-->
The authenticity of host '192.168.100.30 (192.168.100.30)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes <!--輸入yes-->
Warning: Permanently added '192.168.100.30' (ECDSA) to the list of known hosts.
root@192.168.100.30's password: <!--輸入密碼-->
redis-3.2.9.tar.gz 100% 1511KB 48.7MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.40:/root
<!--將redis壓縮包復(fù)制到100.40服務(wù)器的根目錄-->
The authenticity of host '192.168.100.40 (192.168.100.40)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes <!--輸入yes-->
Warning: Permanently added '192.168.100.40' (ECDSA) to the list of known hosts.
root@192.168.100.40's password: <!--輸入密碼-->
redis-3.2.9.tar.gz 100% 1511KB 72.2MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.50:/root
<!--將redis壓縮包復(fù)制到100.50服務(wù)器的根目錄-->
The authenticity of host '192.168.100.50 (192.168.100.50)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes <!--輸入yes-->
Warning: Permanently added '192.168.100.50' (ECDSA) to the list of known hosts.
root@192.168.100.50's password: <!--輸入密碼-->
redis-3.2.9.tar.gz 100% 1511KB 47.3MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.60:/root
<!--將redis壓縮包復(fù)制到100.60服務(wù)器的根目錄-->
The authenticity of host '192.168.100.60 (192.168.100.60)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes <!--輸入yes-->
Warning: Permanently added '192.168.100.60' (ECDSA) to the list of known hosts.
root@192.168.100.60's password: <!--輸入密碼-->
redis-3.2.9.tar.gz 100% 1511KB 3.5MB/s 00:00
[root@centos02 ~]# yum -y install ruby rubygems <!--安裝redis群集所需依賴程序-->
[root@centos02 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz
[root@centos02 ~]# tar zxvf redis-3.2.9.tar.gz <!--解壓縮redis程序包-->
[root@centos02 ~]# mv redis-3.2.9 /usr/src/redis/ <!--剪切到/usr/src/redis/目錄-->
[root@centos02 ~]# cd /usr/src/redis/ <!--進(jìn)入redis目錄-->
[root@centos02 redis]# make && make install <!--編輯及安裝redis-->
[root@centos02 redis]# cd utils/ <!--進(jìn)入utils目錄-->
[root@centos02 utils]# ./install_server.sh <!--初始化redis-->
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
<!--在第一臺(tái)redis服務(wù)器上將redis主配置文件遠(yuǎn)程復(fù)制到剩下五臺(tái)服務(wù)器上-->
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.20:/etc/redis/
<!--將第一臺(tái)redis服務(wù)器上的主配置文件遠(yuǎn)程復(fù)制到第二臺(tái)redis服務(wù)器的/etc/redis/目錄下-->
root@192.168.100.20's password: <!--輸入密碼-->
6379.conf 100% 46KB 37.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.30:/etc/redis/
<!--將第一臺(tái)redis服務(wù)器上的主配置文件遠(yuǎn)程復(fù)制到第三臺(tái)redis服務(wù)器的/etc/redis/目錄下-->
root@192.168.100.30's password: <!--輸入密碼-->
6379.conf 100% 46KB 27.9MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.40:/etc/redis/
<!--將第一臺(tái)redis服務(wù)器上的主配置文件遠(yuǎn)程復(fù)制到第四臺(tái)redis服務(wù)器的/etc/redis/目錄下-->
root@192.168.100.40's password: <!--輸入密碼-->
6379.conf 100% 46KB 13.5MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.50:/etc/redis/
<!--將第一臺(tái)redis服務(wù)器上的主配置文件遠(yuǎn)程復(fù)制到第五臺(tái)redis服務(wù)器的/etc/redis/目錄下-->
root@192.168.100.50's password: <!--輸入密碼-->
6379.conf 100% 46KB 35.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.60:/etc/redis/
<!--將第一臺(tái)redis服務(wù)器上的主配置文件遠(yuǎn)程復(fù)制到第六臺(tái)redis服務(wù)器的/etc/redis/目錄下-->
root@192.168.100.60's password: <!--輸入密碼-->
6379.conf 100% 46KB 44.7MB/s 00:00
[root@centos02 ~]# vim /etc/redis/6379.conf
<!--第二臺(tái)redis服務(wù)器修改主配置文件監(jiān)聽的IP地址-->
bind 192.168.100.20 <!--將IP地址改為本服務(wù)器自身的IP-->
[root@centos02 ~]# redis-server /etc/redis/6379.conf <!--啟動(dòng)redis服務(wù)-->
[root@centos02 ~]# netstat -anptu | grep redis <!--監(jiān)聽redis服務(wù)是否正常啟動(dòng)-->
tcp 0 0 192.168.100.20:6379 0.0.0.0:* LISTEN 6224/redis-server 1
tcp 0 0 192.168.100.20:16379 0.0.0.0:* LISTEN 6224/redis-server 1
剩下四臺(tái)服務(wù)器的操作步驟按照第二臺(tái)的操作步驟做同樣的配置即可,修改主配置文件監(jiān)聽的IP地址設(shè)置成服務(wù)器自己的IP地址即可
創(chuàng)建群集要用到ruby的一個(gè)腳本,在創(chuàng)建群集之前,需要先安裝ruby的運(yùn)行環(huán)境和ruby的Redis客戶端,該操作在其中一臺(tái)服務(wù)器進(jìn)行即可。gem命令是提前下載的redis-3.2.0 gem軟件包提供的,直接上傳服務(wù)器即可使用。
[root@centos01 ~]# /usr/src/redis/src/redis-trib.rb create --replicas 1
192.168.100.10:6379 192.168.100.20:6379
192.192.168.100.30:6379 192.168.100.40:6379
192. 192.168.100.50:6379 192.168.100.60:6379
<!--在第一臺(tái)redis服務(wù)器上使用腳本創(chuàng)建群集-->
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.100.10:6379
192.168.100.20:6379
192.168.100.30:6379
Adding replica 192.168.100.40:6379 to 192.168.100.10:6379
Adding replica 192.168.100.50:6379 to 192.168.100.20:6379
Adding replica 192.168.100.60:6379 to 192.168.100.30:6379
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
replicates 82196443876dd7a7dba2cbda237064577e6996e5
Can I set the above configuration? (type 'yes' to accept): yes <!--輸入“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.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@centos01 ~]# cd /usr/src/redis/src/
[root@centos01 src]# ./redis-trib.rb check 192.168.100.10:6379
<!--查看群集狀態(tài)
(可以清楚的看到哪臺(tái)主機(jī)是master、哪臺(tái)主機(jī)是salve)-->
>>> Performing Cluster Check (using node 192.168.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
<!--登錄redis群集,設(shè)置鍵值測(cè)試。這里需要跟“-c”參數(shù)來激活群集模式-->
[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379 -c <!--登錄到群集-->
192.168.100.10:6379> set centos 7.4 <!--插入數(shù)據(jù)-->
OK
192.168.100.10:6379> get centos <!--查看-->
"7.4"
192.168.100.10:6379> quit <!--退出群集-->
[root@centos01 ~]# redis-cli -h 192.168.100.40 -p 6379 -c
192.168.100.40:6379> get centos
<!--查看在100.10上插入的數(shù)據(jù),同樣可以看到;數(shù)據(jù)自動(dòng)同步其redis服務(wù)器-->
-> Redirected to slot [467] located at 192.168.100.10:6379
"7.4"
192.168.100.10:6379> quit
[root@centos01 ~]# redis-cli -h 192.168.100.60 -p 6379 -c
192.168.100.60:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
"7.4"
192.168.100.10:6379> quit
———————— 本文至此結(jié)束,感謝閱讀 ————————
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文題目:Centos7搭建Redis群集-創(chuàng)新互聯(lián)
鏈接URL:http://aaarwkj.com/article28/dpgscp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、Google、企業(yè)網(wǎng)站制作、動(dòng)態(tài)網(wǎng)站、虛擬主機(jī)、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容