本篇內(nèi)容介紹了“redis集群部署方法”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
10年積累的網(wǎng)站制作、網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有紅河哈尼免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
1、主從節(jié)點均安裝好redis以及ruby。
[root@D2-LZY245 redis-4.0.1]# yum -y install ruby ruby-devel rubygems rpm-build
[root@D2-LZY245 redis-4.0.1]# gem install redis
2、主節(jié)點創(chuàng)建集群目錄、配置參數(shù)并啟動
[root@D2-LZY245 ~]# cd redis-4.0.1/
[root@D2-LZY245 redis-4.0.1]# mkdir redis_cluster
[root@D2-LZY245 redis-4.0.1]# cd redis_cluster/
[root@D2-LZY245 redis_cluster]# mkdir 7000 7001 7002
[root@D2-LZY245 redis_cluster]# cp ../redis.conf 7000/
[root@D2-LZY245 redis_cluster]# vim 7000/redis.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7000/redis_7000.conf
bind 10.163.89.245
port 7000
daemonize yes
pidfile /var/run/redis_7000.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
[root@D2-LZY245 redis_cluster]# mv 7000/redis.conf 7000/redis_7000.conf
[root@D2-LZY245 redis_cluster]# cp 7000/redis_7000.conf 7001/redis_7001.conf
[root@D2-LZY245 redis_cluster]# cp 7000/redis_7000.conf 7002/redis_7002.conf
[root@D2-LZY245 redis_cluster]# vim 7001/redis_7001.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7001/redis_7001.conf
bind 10.163.89.245
port 7001
daemonize yes
pidfile /var/run/redis_7001.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
[root@D2-LZY245 redis_cluster]# vim 7002/redis_7002.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7002/redis_7002.conf
bind 10.163.89.245
port 7002
daemonize yes
pidfile /var/run/redis_7002.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7002.conf
cluster-node-timeout 15000
[root@D2-LZY245 redis_cluster]# cd ..
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7000/redis_7000.conf
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7001/redis_7001.conf
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7002/redis_7002.conf
[root@D2-LZY245 redis-4.0.1]# netstat -tunlp | grep 700
tcp 0 0 10.163.89.245:17000 0.0.0.0:* LISTEN 28447/src/redis-ser
tcp 0 0 10.163.89.245:17001 0.0.0.0:* LISTEN 28423/src/redis-ser
tcp 0 0 10.163.89.245:17002 0.0.0.0:* LISTEN 28432/src/redis-ser
tcp 0 0 10.163.89.245:7000 0.0.0.0:* LISTEN 28447/src/redis-ser
tcp 0 0 10.163.89.245:7001 0.0.0.0:* LISTEN 28423/src/redis-ser
tcp 0 0 10.163.89.245:7002 0.0.0.0:* LISTEN 28432/src/redis-ser
3、從節(jié)點創(chuàng)建集群目錄、配置參數(shù)并啟動
[root@D2-TRAIN15 ~]# cd redis-4.0.1
[root@D2-TRAIN15 redis-4.0.1]# mkdir redis_cluster
[root@D2-TRAIN15 redis-4.0.1]# cd redis_cluster/
[root@D2-TRAIN15 redis_cluster]# mkdir 7003 7004 7005
[root@D2-TRAIN15 redis_cluster]# cp ../redis.conf 7003/
[root@D2-TRAIN15 redis_cluster]# vim 7003/redis.conf
[root@D2-TRAIN15 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7003/redis.conf
bind 10.163.89.15
port 7003
daemonize yes
pidfile /var/run/redis_7003.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7003.conf
cluster-node-timeout 15000
[root@D2-TRAIN15 redis_cluster]# mv 7003/redis.conf 7003/redis_7003.conf
[root@D2-TRAIN15 redis_cluster]# cp 7003/redis_7003.conf 7004/redis_7004.conf
[root@D2-TRAIN15 redis_cluster]# cp 7003/redis_7003.conf 7005/redis_7005.conf
[root@D2-TRAIN15 redis_cluster]# vim 7004/redis_7004.conf
[root@D2-TRAIN15 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7004/redis_7004.conf
bind 10.163.89.15
port 7004
daemonize yes
pidfile /var/run/redis_7004.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7004.conf
cluster-node-timeout 15000
[root@D2-TRAIN15 redis_cluster]# vim 7005/redis_7005.conf
[root@D2-TRAIN15 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7005/redis_7005.conf
bind 10.163.89.15
port 7005
daemonize yes
pidfile /var/run/redis_7005.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7005.conf
cluster-node-timeout 15000
[root@D2-TRAIN15 redis_cluster]# cd ..
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7003/redis_7003.conf
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7004/redis_7004.conf
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7005/redis_7005.conf
[root@D2-TRAIN15 redis-4.0.1]# netstat -tunlp | grep 700
tcp 0 0 10.163.89.15:17003 0.0.0.0:* LISTEN 14258/src/redis-ser
tcp 0 0 10.163.89.15:17004 0.0.0.0:* LISTEN 14263/src/redis-ser
tcp 0 0 10.163.89.15:17005 0.0.0.0:* LISTEN 14268/src/redis-ser
tcp 0 0 10.163.89.15:7003 0.0.0.0:* LISTEN 14258/src/redis-ser
tcp 0 0 10.163.89.15:7004 0.0.0.0:* LISTEN 14263/src/redis-ser
tcp 0 0 10.163.89.15:7005 0.0.0.0:* LISTEN 14268/src/redis-ser
[root@D2-TRAIN15 redis-4.0.1]#
4、創(chuàng)建集群
[root@D2-LZY245 redis-4.0.1]# src/redis-trib.rb create --replicas 1 10.163.89.245:7000 10.163.89.245:7001 10.163.89.245:7002 10.163.89.15:7003 10.163.89.15:7004 10.163.89.15:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.163.89.245:7000
10.163.89.15:7003
10.163.89.245:7001
Adding replica 10.163.89.15:7004 to 10.163.89.245:7000
Adding replica 10.163.89.245:7002 to 10.163.89.15:7003
Adding replica 10.163.89.15:7005 to 10.163.89.245:7001
M: b545390b3e8c3602e13978cf28f6ef7dd76b6197 10.163.89.245:7000
slots:0-5460 (5461 slots) master
M: 0e26e28f3c531357db73e522bb6279350ff5275e 10.163.89.245:7001
slots:10923-16383 (5461 slots) master
S: 8164d21461a9a5612e9657863c1c214f8c116a8e 10.163.89.245:7002
replicates e81c2072be94bdf7729b10088a312ff519cb0f2b
M: e81c2072be94bdf7729b10088a312ff519cb0f2b 10.163.89.15:7003
slots:5461-10922 (5462 slots) master
S: 4284f88f612157caa6611173d347ec4ec9f9554b 10.163.89.15:7004
replicates b545390b3e8c3602e13978cf28f6ef7dd76b6197
S: d141fe7c975728b1243d6d314914179a7febb306 10.163.89.15:7005
replicates 0e26e28f3c531357db73e522bb6279350ff5275e
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 10.163.89.245:7000)
M: b545390b3e8c3602e13978cf28f6ef7dd76b6197 10.163.89.245:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 8164d21461a9a5612e9657863c1c214f8c116a8e 10.163.89.245:7002
slots: (0 slots) slave
replicates e81c2072be94bdf7729b10088a312ff519cb0f2b
S: d141fe7c975728b1243d6d314914179a7febb306 10.163.89.15:7005
slots: (0 slots) slave
replicates 0e26e28f3c531357db73e522bb6279350ff5275e
S: 4284f88f612157caa6611173d347ec4ec9f9554b 10.163.89.15:7004
slots: (0 slots) slave
replicates b545390b3e8c3602e13978cf28f6ef7dd76b6197
M: e81c2072be94bdf7729b10088a312ff519cb0f2b 10.163.89.15:7003
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 0e26e28f3c531357db73e522bb6279350ff5275e 10.163.89.245:7001
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.
5、測試
在主節(jié)點7000端口設(shè)置key:
[root@D2-LZY245 ~]# cd redis-4.0.1/
[root@D2-LZY245 redis-4.0.1]# src/redis-cli -h 10.163.89.245 -c -p 7000
10.163.89.245:7000> set key1 "hello world"
-> Redirected to slot [9189] located at 10.163.89.15:7003
OK
10.163.89.15:7003> keys *
1) "key1"
在從節(jié)點7005端口查看:
[root@D2-TRAIN15 redis-4.0.1]# src/redis-cli -h 10.163.89.15 -c -p 7005
10.163.89.15:7005> get key1
-> Redirected to slot [9189] located at 10.163.89.15:7003
"hello world"
“Redis集群部署方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
當(dāng)前標(biāo)題:Redis集群部署方法
URL標(biāo)題:http://aaarwkj.com/article8/iggoip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、小程序開發(fā)、軟件開發(fā)、虛擬主機、品牌網(wǎng)站設(shè)計、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)