Redis3.2.8集群安裝配置-創(chuàng)新互聯(lián)

具體就不做介紹了,直接開始安裝

10年積累的成都網(wǎng)站建設(shè)、網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有海原免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

準(zhǔn)備環(huán)境:

使用2臺centos服務(wù)器,每臺機(jī)器上部署3個實(shí)例,集群為三個主節(jié)點(diǎn)與三個從節(jié)點(diǎn): 第一臺 192.168.1.107:7000  192.168.1.107:7001  192.168.1.107:7002   第二臺 192.168.1.108:7003   192.168.1.108:7004   192.168.1.108:7005

安裝配置:

192.168.1.107服務(wù)器

#yum -y  install gcc zlib ruby rubygems #gem install redis #wget http://download.redis.io/releases/redis-3.2.8.tar.gz #tar -zxvf redis-3.2.8.tar.gz #cd redis-3.2.8 #make && make install  將 redis-trib.rb 復(fù)制到 /usr/local/bin 目錄下 #cp src/redis-trib.rb /usr/local/bin/    #mkdir -p /data/redis/{conf,data,logs} #cp redis.conf /data/redis/conf/redis-7000.conf  #cp redis.conf /data/redis/conf/redis-7001.conf  #cp redis.conf /data/redis/conf/redis-7002.conf

配置內(nèi)容如下(redis-7000.conf其它類同):

daemonize  yes   pidfile /data/redis/data/redis-7000.pid   port 7000   bind 192.168.1.107   unixsocket /data/redis/data/redis-7000.sock   unixsocketperm 700   timeout 300   loglevel verbose   logfile /data/redis/logs/redis-7000.log   databases 16   dbfilename dump-7000.rdb   dir /data/redis/data/      #aof持久化   appendonly yes   appendfilename appendonly-7000.aof   appendfsync everysec   no-appendfsync-on-rewrite yes     auto-aof-rewrite-percentage 80-100   auto-aof-rewrite-min-size 64mb     lua-time-limit 5000      #集群配置   cluster-enabled yes   cluster-config-file /data/redis/data/nodes-7000.conf   cluster-node-timeout 5000

同樣的在192.168.1.108上配置其它端口,配置后我們分別啟動

192.168.1.107主機(jī) #redis-server /data/redis/conf/redis-7000.conf #redis-server /data/redis/conf/redis-7001.conf #redis-server /data/redis/conf/redis-7002.conf 192.168.1.108主機(jī) #redis-server /data/redis/conf/redis-7003.conf #redis-server /data/redis/conf/redis-7004.conf #redis-server /data/redis/conf/redis-7005.conf

分別在兩臺主機(jī)查看啟動進(jìn)程與端口:

# ps -ef|grep redis root      4663     1  0 10:53 ?        00:00:09 redis-server 192.168.1.107:7000 [cluster] root      4667     1  0 10:53 ?        00:00:09 redis-server 192.168.1.107:7001 [cluster] root      5566     1  0 12:12 ?        00:00:06 redis-server 192.168.1.107:7002 [cluster] root      5611  5313  0 14:49 pts/1    00:00:00 grep redis # netstat -tnlp | grep redis tcp        0      0 192.168.1.107:7000         0.0.0.0:*                   LISTEN      4663/redis-server 1  tcp        0      0 192.168.1.107:7001         0.0.0.0:*                   LISTEN      4667/redis-server 1  tcp        0      0 192.168.1.107:7002         0.0.0.0:*                   LISTEN      5566/redis-server 1  tcp        0      0 192.168.1.107:17000        0.0.0.0:*                   LISTEN      4663/redis-server 1  tcp        0      0 192.168.1.107:17001        0.0.0.0:*                   LISTEN      4667/redis-server 1  tcp        0      0 192.168.1.107:17002        0.0.0.0:*                   LISTEN      5566/redis-server 1

創(chuàng)建集群

redis-trib.rb命令介紹可以參考: http://weizijun.cn/2016/01/08/redis%20cluster%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7redis-trib-rb%E8%AF%A6%E8%A7%A3/ # redis-trib.rb  create  --replicas  1  192.168.1.107:7000 192.168.1.107:7001  192.168.1.107:7002 192.168.1.108:7003  192.168.1.108:7004  192.168.1.108:7005 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.1.108:7003 192.168.1.107:7000 192.168.1.108:7004 Adding replica 192.168.1.107:7001 to 192.168.12.108:7003 Adding replica 192.168.1.108:7005 to 192.168.12.107:7000 Adding replica 192.168.1.107:7002 to 192.168.12.108:7004 M: d0ce4d4eb8c503267ffea606e90d1c537a83a22e 192.168.1.107:7000    slots:5461-10922 (5462 slots) master S: 24ca2753885db7f37c0e0077b1f43eb2b1a52e42 192.168.1.107:7001    replicates 8ee448821d5e757af73bab65861340e557b8cd14 S: 90c36924c71ae924b1179ff1a384c53e5ea2e484 192.168.1.107:7002    replicates 5a93221a3281f88f9984c24b6e1d6f08b3685c89 M: 8ee448821d5e757af73bab65861340e557b8cd14 192.168.1.108:7003    slots:0-5460 (5461 slots) master M: 5a93221a3281f88f9984c24b6e1d6f08b3685c89 192.168.1.108:7004    slots:10923-16383 (5461 slots) master S: a63176f88cbf58ab879421148da3b171f169540d 192.168.1.108:7005    replicates d0ce4d4eb8c503267ffea606e90d1c537a83a22e 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.1.107:7000) M: d0ce4d4eb8c503267ffea606e90d1c537a83a22e 192.168.1.107:7000    slots:5461-10922 (5462 slots) master M: 24ca2753885db7f37c0e0077b1f43eb2b1a52e42 192.168.1.107:7001    slots: (0 slots) master    replicates 8ee448821d5e757af73bab65861340e557b8cd14 M: 90c36924c71ae924b1179ff1a384c53e5ea2e484 192.168.1.107:7002    slots: (0 slots) master    replicates 5a93221a3281f88f9984c24b6e1d6f08b3685c89 M: 8ee448821d5e757af73bab65861340e557b8cd14 192.168.1.108:7003    slots:0-5460 (5461 slots) master M: 5a93221a3281f88f9984c24b6e1d6f08b3685c89 192.168.1.108:7004    slots:10923-16383 (5461 slots) master M: a63176f88cbf58ab879421148da3b171f169540d 192.168.1.108:7005    slots: (0 slots) master    replicates d0ce4d4eb8c503267ffea606e90d1c537a83a22e [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.        #集群創(chuàng)建成功

集群驗(yàn)證

192.168.1.107的7002端口的節(jié)點(diǎn)寫入數(shù)據(jù),在192.168.1.108的7005端口查詢,接方式為  redis-cli -h 192.168.31.245 -c -p 7002  ,加參數(shù) -C 可連接到集群,因?yàn)樯厦?nbsp;redis.conf  將 bind 改為了ip地址,所以 -h 參數(shù)不可以省略。 # redis-cli -h 192.168.1.107 -c -p 7002 192.168.1.108:7003> set test01 "this is test01" OK 192.168.1.108:7003> # redis-cli -h 192.168.1.108 -c -p 7005 192.168.12.108:7005> get test01 -> Redirected to slot [1840] located at 192.168.12.108:7003 "this is test01" 說明集群運(yùn)作正常。

Redis 集群會把數(shù)據(jù)存在一個 master 節(jié)點(diǎn),然后在這個 master 和其對應(yīng)的salve 之間進(jìn)行數(shù)據(jù)同步。當(dāng)讀取數(shù)據(jù)時,也根據(jù)一致性哈希算法到對應(yīng)的 master 節(jié)點(diǎn)獲取數(shù)據(jù)。只有當(dāng)一個master 掛掉之后,才會啟動一個對應(yīng)的 salve 節(jié)點(diǎn),充當(dāng) master 。

需要注意的是:必須要3個或以上的主節(jié)點(diǎn),否則在創(chuàng)建集群時會失敗,并且當(dāng)存活的主節(jié)點(diǎn)數(shù)小于總節(jié)點(diǎn)數(shù)的一半時,整個集群就無法提供服務(wù)了。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站欄目:Redis3.2.8集群安裝配置-創(chuàng)新互聯(lián)
瀏覽路徑:http://bm7419.com/article28/dgopcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)網(wǎng)站排名、定制開發(fā)、品牌網(wǎng)站制作網(wǎng)站收錄、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司