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"
[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"
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2143386/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redis 4.0叢集環境部署Redis
- Redis Cluster叢集模式部署Redis模式
- redis叢集之主從複製叢集的原理和部署Redis
- Redis-cluster叢集搭建部署Redis
- redis叢集之分片叢集的原理和常用代理環境部署Redis
- NoSQL之Redis叢集部署解析SQLRedis
- Centos7部署Redis叢集CentOSRedis
- Redis系列:搭建Redis叢集(叢集模式)Redis模式
- 玩轉Redis叢集之SentinelRedis
- 玩轉Redis叢集之CodisRedis
- 玩轉Redis叢集之ClusterRedis
- redis 叢集搭建以及redislive監測部署Redis
- Redis+TwemProxy(nutcracker)叢集方案部署記錄Redis
- redis Cluster模式叢集 多機器 docker 部署Redis模式Docker
- redis 叢集Redis
- redis叢集Redis
- Redis叢集部署Redis
- Redis 叢集部署Redis
- Redis學習之 Redis3.0.x 叢集搭建RedisS3
- K8S如何部署Redis(單機、叢集)K8SRedis
- Docker部署系列之Docker Compose安裝Redis三主三從叢集DockerRedis
- Redis服務之叢集節點管理Redis
- Redis cluster 叢集Redis
- redis叢集搭建Redis
- redis系列:叢集Redis
- 搭建 Redis 叢集Redis
- Redis Cluster(叢集)Redis
- Redis 叢集方法Redis
- Redis叢集方案Redis
- Redis 叢集方案Redis
- Redis-叢集Redis
- redis叢集原理Redis
- 部署分片叢集
- redis偽叢集配置Cluster叢集模式Redis模式
- Redis叢集 - cluster叢集、資料分片Redis
- redis主從叢集搭建及容災部署(哨兵sentinel)Redis
- Redis Cluster 叢集部署Redis
- 認識Redis叢集——Redis ClusterRedis