您好,登錄后才能下訂單哦!
本篇內容介紹了“Redis集群部署方法”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
1、主從節點均安裝好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、主節點創建集群目錄、配置參數并啟動
[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、從節點創建集群目錄、配置參數并啟動
[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、創建集群
[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、測試
在主節點7000端口設置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"
在從節點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集群部署方法”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。