集群的搭建步驟是什么

這篇文章主要介紹“集群的搭建步驟是什么”,在日常操作中,相信很多人在集群的搭建步驟是什么問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”集群的搭建步驟是什么”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到渾源網(wǎng)站設(shè)計(jì)與渾源網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類(lèi)型包括:網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋渾源地區(qū)。

集群的搭建

redis的下載、安裝、啟動(dòng)(單實(shí)例)

  1. 下載redis壓縮包,然后解壓壓縮文件,我們統(tǒng)一將Redis下載在/opt目錄下

  2. 進(jìn)入到解壓縮后的redis文件目錄(此時(shí)可以看到Makefile文件),編譯redis源文件;

執(zhí)行命令如下

$ cd /opt
$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz
$ tar zxvf redis-4.0.9.tar.gz
$ cd redis-4.0.9
$ make
$ make install
  1. 把編譯好的redis源文件安裝到/usr/local/redis目錄下,如果/local目錄下沒(méi)有redis目錄,會(huì)自動(dòng)新建redis目錄;

  2. 然后修改該$ ./src/redis-server redis.conf文件->daemonize:no 改為daemonize:yes;

  3. 進(jìn)入/usr/local/redis/bin目錄,直接./redis-server啟動(dòng)redis(此時(shí)為前端啟動(dòng)redis);

  4. 注意,由于Redis的保護(hù)模式,只綁定了本機(jī)的127.0.0.1,從其他機(jī)器是不能訪問(wèn)的。所以我們需要添加本機(jī)的ip

192.168.xxx.xxx。
  1. 在/bin目錄下通過(guò)./redis-server redis.conf啟動(dòng)redis(此時(shí)為后臺(tái)啟動(dòng))。

$ cd /opt/redis-4.0.9
$ ./src/redis-server .redis.conf

集群的規(guī)劃

根據(jù)官方推薦,集群部署至少要 3 臺(tái)以上的master節(jié)點(diǎn),最好使用 3 主 3 從六個(gè)節(jié)點(diǎn)的模式。

配置文件

咱們準(zhǔn)備 6 個(gè)配置文件 ,端口 7001,7002,7003,7004,7005,7006

并在redis-cluster目錄下創(chuàng)建6個(gè)節(jié)點(diǎn)的配置文件。分別為:

redis-7000.conf
redis-7001.conf
redis-7002.conf
redis-7003.conf
redis-7004.conf
redis-7005.conf

后面的7000,7001等是redis啟動(dòng)的端口號(hào)。接下來(lái)編輯文件的內(nèi)容:

#該集群階段的端口
port 7000
#為每一個(gè)集群節(jié)點(diǎn)指定一個(gè)pid_file
pidfile /var/run/redis_7000.pid
#在bind指令后添加本機(jī)的ip
bind 127.0.0.1 149.28.37.147
#找到Cluster配置的代碼段,使得Redis支持集群
cluster-enabled yes
#每一個(gè)集群節(jié)點(diǎn)都有一個(gè)配置文件,這個(gè)文件是不能手動(dòng)編輯的。確保每一個(gè)集群節(jié)點(diǎn)的配置文件不通
cluster-config-file nodes-7000.conf
#集群節(jié)點(diǎn)的超時(shí)時(shí)間,單位:ms,超時(shí)后集群會(huì)認(rèn)為該節(jié)點(diǎn)失敗
cluster-node-timeout 5000
#最后將appendonly改成yes
appendonly yes
啟動(dòng) redis 節(jié)點(diǎn)
挨個(gè)啟動(dòng)節(jié)點(diǎn)

看以下啟動(dòng)情況

首先我們創(chuàng)建Redis的配置文件目錄,如下:

$ cd /opt
$ mkdir redis-cluster

這樣一個(gè)節(jié)點(diǎn)的配置就完成,其他的5個(gè)節(jié)點(diǎn)也做同樣的配置。并將6個(gè)節(jié)點(diǎn)的Redis實(shí)例啟動(dòng):

$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7000.conf &
$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7001.conf &
$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7002.conf &
$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7003.conf &
$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7004.conf &
$ nohup /opt/redis-4.0.9/src/redis-server /opt/redis-cluster/redis-7005.conf &

使用這6個(gè)節(jié)點(diǎn)創(chuàng)建集群:

$ /opt/redis-4.0.9/src/redis-trib.rb create --replicas 1 149.28.37.147:7000 149.28.37.147:7001 149.28.37.147:7002 149.28.37.147:7003 149.28.37.147:7004 149.28.37.147:7005

$ redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluste r-replicas 1

--replicas 1 表示我們希望為集群中的每個(gè)主節(jié)點(diǎn)創(chuàng)建一個(gè)從節(jié)點(diǎn)。

執(zhí)行命令后會(huì)顯示:

>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
>>> Using 3 masters:
>>> 149.28.37.147:7000
>>> 149.28.37.147:7001
>>> 149.28.37.147:7002

---------------------------------------------
# 執(zhí)行成功結(jié)果如下
# 我們可以看到 7001,7002,7003 成為了 master 節(jié)點(diǎn),
# 分別占用了 slot [0-5460],[5461-10922],[10923-16383]
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
--------------------------------------------

>>> Adding replica 149.28.37.147:7004 to 149.28.37.147:7000
>>> Adding replica 149.28.37.147:7005 to 149.28.37.147:7001
>>> Adding replica 149.28.37.147:7003 to 149.28.37.147:7002
>>> Trying to optimize slaves allocation for anti-affinity
>>> [WARNING] Some slaves are in the same host as their master
>>> M: 65625091304b0fa2dd75a00f62b6aceac1701094 149.28.37.147:7000
>>> slots:0-5460 (5461 slots) master
>>> M: 4da569bf8402e4f75ab6e0fe7076919c22e3f900 149.28.37.147:7001
>>> slots:5461-10922 (5462 slots) master
>>> M: b977680e24f23f8fec96876d9014803ca752e2e2 149.28.37.147:7002
>>> slots:10923-16383 (5461 slots) master
>>> S: 7183e47a64bca23157140229352455d1a1407dc2 149.28.37.147:7003
>>> replicates b977680e24f23f8fec96876d9014803ca752e2e2
>>> S: b2f916a643fefef1d43dbd1ef5d22f72c0ee43d6 149.28.37.147:7004
>>> replicates 65625091304b0fa2dd75a00f62b6aceac1701094
>>> S: e362d9aae5fe3e9c343d266a5ab952272e0e37b0 149.28.37.147:7005
>>> replicates 4da569bf8402e4f75ab6e0fe7076919c22e3f900
>>> Can I set the above configuration? (type 'yes' to accept): 
>>> 我們輸入yes,回車(chē):

>>> 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 149.28.37.147:7000)
>>> M: 65625091304b0fa2dd75a00f62b6aceac1701094 149.28.37.147:7000
>>> slots:0-5460 (5461 slots) master
>>> 1 additional replica(s)
>>> M: b977680e24f23f8fec96876d9014803ca752e2e2 149.28.37.147:7002
>>> slots:10923-16383 (5461 slots) master
>>> 1 additional replica(s)
>>> S: e362d9aae5fe3e9c343d266a5ab952272e0e37b0 149.28.37.147:7005
>>> slots: (0 slots) slave
>>> replicates 4da569bf8402e4f75ab6e0fe7076919c22e3f900
>>> S: b2f916a643fefef1d43dbd1ef5d22f72c0ee43d6 149.28.37.147:7004
>>> slots: (0 slots) slave
>>> replicates 65625091304b0fa2dd75a00f62b6aceac1701094
>>> M: 4da569bf8402e4f75ab6e0fe7076919c22e3f900 149.28.37.147:7001
>>> slots:5461-10922 (5462 slots) master
>>> 1 additional replica(s)
>>> S: 7183e47a64bca23157140229352455d1a1407dc2 149.28.37.147:7003
>>> slots: (0 slots) slave
>>> replicates b977680e24f23f8fec96876d9014803ca752e2e2
>>> [OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
>>> [OK] All 16384 slots covered.
>>> 集群搭建完畢。我們可以使用Spring-Boot非常方便的去訪問(wèn)Redis集群了。

數(shù)據(jù)驗(yàn)證

注意 集群模式下要帶參數(shù) -c,表示集群,否則不能正常存取數(shù)據(jù)?。?!

[root@localhost redis-5.0.5]# redis-cli -p 7100 -c
設(shè)置 k1 v1
127.0.0.1:7001> set k1 v1
-> Redirected to slot [12706] located at 127.0.0.1:7003
OK
這可以看到集群的特點(diǎn):把數(shù)據(jù)存到計(jì)算得出的 slot,這里還自動(dòng)跳到了7003
127.0.0.1:7003> get k1
"v1"
我們還回到 7001 獲取 k1 試試
[root@localhost redis-5.0.5]# redis-cli -p 7001 -c
127.0.0.1:7001> get k1
-> Redirected to slot [12706] located at 127.0.0.1:7003
"v1"
我們可以看到重定向的過(guò)程
127.0.0.1:7003>

到此,關(guān)于“集群的搭建步驟是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

本文名稱:集群的搭建步驟是什么
本文網(wǎng)址:http://bm7419.com/article8/psdcop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)App開(kāi)發(fā)、品牌網(wǎng)站制作、做網(wǎng)站、電子商務(wù)

廣告

聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)