Redis Cluster 配置案例
parent
42f2b4ea8a
commit
b6d9c81ffb
|
@ -1,8 +1,8 @@
|
||||||
port 26381
|
port 27001
|
||||||
daemonize yes
|
daemonize yes
|
||||||
sentinel monitor redis-master 172.22.6.3 6381 2
|
sentinel monitor redis-master 172.22.6.3 7001 2
|
||||||
sentinel down-after-milliseconds redis-master 5000
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
sentinel failover-timeout redis-master 900000
|
sentinel failover-timeout redis-master 900000
|
||||||
sentinel parallel-syncs redis-master 1
|
sentinel parallel-syncs redis-master 1
|
||||||
#sentinel auth-pass redis-master 123456
|
#sentinel auth-pass redis-master 123456
|
||||||
logfile /usr/local/redis/conf/26381/26381.log
|
logfile /usr/local/redis/conf/27001/27001.log
|
|
@ -1,8 +1,8 @@
|
||||||
port 26382
|
port 27002
|
||||||
daemonize yes
|
daemonize yes
|
||||||
sentinel monitor redis-master 172.22.6.3 6382 2
|
sentinel monitor redis-master 172.22.6.3 7002 2
|
||||||
sentinel down-after-milliseconds redis-master 5000
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
sentinel failover-timeout redis-master 900000
|
sentinel failover-timeout redis-master 900000
|
||||||
sentinel parallel-syncs redis-master 1
|
sentinel parallel-syncs redis-master 1
|
||||||
#sentinel auth-pass redis-master 123456
|
#sentinel auth-pass redis-master 123456
|
||||||
logfile /usr/local/redis/conf/26382/26382.log
|
logfile /usr/local/redis/conf/27002/27002.log
|
|
@ -1,8 +1,8 @@
|
||||||
port 26383
|
port 27003
|
||||||
daemonize yes
|
daemonize yes
|
||||||
sentinel monitor redis-master 172.22.6.3 6383 2
|
sentinel monitor redis-master 172.22.6.3 7003 2
|
||||||
sentinel down-after-milliseconds redis-master 5000
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
sentinel failover-timeout redis-master 900000
|
sentinel failover-timeout redis-master 900000
|
||||||
sentinel parallel-syncs redis-master 1
|
sentinel parallel-syncs redis-master 1
|
||||||
#sentinel auth-pass redis-master 123456
|
#sentinel auth-pass redis-master 123456
|
||||||
logfile /usr/local/redis/conf/26383/26383.log
|
logfile /usr/local/redis/conf/27003/27003.log
|
|
@ -0,0 +1,8 @@
|
||||||
|
port 27004
|
||||||
|
daemonize yes
|
||||||
|
sentinel monitor redis-master 172.22.6.3 7007 2
|
||||||
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
|
sentinel failover-timeout redis-master 900000
|
||||||
|
sentinel parallel-syncs redis-master 1
|
||||||
|
#sentinel auth-pass redis-master 123456
|
||||||
|
logfile /usr/local/redis/conf/27004/27004.log
|
|
@ -0,0 +1,8 @@
|
||||||
|
port 27005
|
||||||
|
daemonize yes
|
||||||
|
sentinel monitor redis-master 172.22.6.3 7008 2
|
||||||
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
|
sentinel failover-timeout redis-master 900000
|
||||||
|
sentinel parallel-syncs redis-master 1
|
||||||
|
#sentinel auth-pass redis-master 123456
|
||||||
|
logfile /usr/local/redis/conf/27005/27005.log
|
|
@ -0,0 +1,8 @@
|
||||||
|
port 27006
|
||||||
|
daemonize yes
|
||||||
|
sentinel monitor redis-master 172.22.6.3 7009 2
|
||||||
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
|
sentinel failover-timeout redis-master 900000
|
||||||
|
sentinel parallel-syncs redis-master 1
|
||||||
|
#sentinel auth-pass redis-master 123456
|
||||||
|
logfile /usr/local/redis/conf/27006/27006.log
|
|
@ -1,12 +0,0 @@
|
||||||
port 6381
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6381/6381.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6381
|
|
||||||
pidfile /usr/local/redis/conf/6381/6381.pid
|
|
||||||
logfile /usr/local/redis/conf/6381/6381.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6382
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6382/6382.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6382
|
|
||||||
pidfile /usr/local/redis/conf/6382/6382.pid
|
|
||||||
logfile /usr/local/redis/conf/6382/6382.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6383
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6383/6383.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6383
|
|
||||||
pidfile /usr/local/redis/conf/6383/6383.pid
|
|
||||||
logfile /usr/local/redis/conf/6383/6383.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6384
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6384/6384.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6384
|
|
||||||
pidfile /usr/local/redis/conf/6384/6384.pid
|
|
||||||
logfile /usr/local/redis/conf/6384/6384.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6385
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6385/6385.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6385
|
|
||||||
pidfile /usr/local/redis/conf/6385/6385.pid
|
|
||||||
logfile /usr/local/redis/conf/6385/6385.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6386
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6386/6386.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6386
|
|
||||||
pidfile /usr/local/redis/conf/6386/6386.pid
|
|
||||||
logfile /usr/local/redis/conf/6386/6386.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6387
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6387/6387.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6387
|
|
||||||
pidfile /usr/local/redis/conf/6387/6387.pid
|
|
||||||
logfile /usr/local/redis/conf/6387/6387.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6388
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6388/6388.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6388
|
|
||||||
pidfile /usr/local/redis/conf/6388/6388.pid
|
|
||||||
logfile /usr/local/redis/conf/6388/6388.log
|
|
|
@ -1,12 +0,0 @@
|
||||||
port 6389
|
|
||||||
bind 0.0.0.0
|
|
||||||
daemonize yes
|
|
||||||
|
|
||||||
cluster-enabled yes
|
|
||||||
cluster-config-file /usr/local/redis/conf/6389/6389.conf
|
|
||||||
cluster-node-timeout 10000
|
|
||||||
|
|
||||||
appendonly yes
|
|
||||||
dir /usr/local/redis/conf/6389
|
|
||||||
pidfile /usr/local/redis/conf/6389/6389.pid
|
|
||||||
logfile /usr/local/redis/conf/6389/6389.log
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7001
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7001/7001.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7001
|
||||||
|
pidfile /usr/local/redis/conf/7001/7001.pid
|
||||||
|
logfile /usr/local/redis/conf/7001/7001.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7002
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7002/7002.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7002
|
||||||
|
pidfile /usr/local/redis/conf/7002/7002.pid
|
||||||
|
logfile /usr/local/redis/conf/7002/7002.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7003
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7003/7003.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7003
|
||||||
|
pidfile /usr/local/redis/conf/7003/7003.pid
|
||||||
|
logfile /usr/local/redis/conf/7003/7003.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7004
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7004/7004.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7004
|
||||||
|
pidfile /usr/local/redis/conf/7004/7004.pid
|
||||||
|
logfile /usr/local/redis/conf/7004/7004.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7005
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7005/7005.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7005
|
||||||
|
pidfile /usr/local/redis/conf/7005/7005.pid
|
||||||
|
logfile /usr/local/redis/conf/7005/7005.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7006
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7006/7006.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7006
|
||||||
|
pidfile /usr/local/redis/conf/7006/7006.pid
|
||||||
|
logfile /usr/local/redis/conf/7006/7006.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7007
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7007/7007.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7007
|
||||||
|
pidfile /usr/local/redis/conf/7007/7007.pid
|
||||||
|
logfile /usr/local/redis/conf/7007/7007.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7008
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7008/7008.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7008
|
||||||
|
pidfile /usr/local/redis/conf/7008/7008.pid
|
||||||
|
logfile /usr/local/redis/conf/7008/7008.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7009
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7009/7009.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7009
|
||||||
|
pidfile /usr/local/redis/conf/7009/7009.pid
|
||||||
|
logfile /usr/local/redis/conf/7009/7009.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7010
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7010/7010.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7010
|
||||||
|
pidfile /usr/local/redis/conf/7010/7010.pid
|
||||||
|
logfile /usr/local/redis/conf/7010/7010.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7011
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7011/7011.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7011
|
||||||
|
pidfile /usr/local/redis/conf/7011/7011.pid
|
||||||
|
logfile /usr/local/redis/conf/7011/7011.log
|
|
@ -0,0 +1,12 @@
|
||||||
|
port 7012
|
||||||
|
bind 172.22.6.3
|
||||||
|
daemonize yes
|
||||||
|
|
||||||
|
cluster-enabled yes
|
||||||
|
cluster-config-file /usr/local/redis/conf/7012/7012.conf
|
||||||
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
|
appendonly yes
|
||||||
|
dir /usr/local/redis/conf/7012
|
||||||
|
pidfile /usr/local/redis/conf/7012/7012.pid
|
||||||
|
logfile /usr/local/redis/conf/7012/7012.log
|
|
@ -4,31 +4,31 @@
|
||||||
|
|
||||||
集群拓扑:
|
集群拓扑:
|
||||||
|
|
||||||
- 三主六从,每个主节点有两个从节点。
|
- 三主三从
|
||||||
- 三哨兵,分别监听其中一个主节点。
|
- 三哨兵
|
||||||
|
|
||||||
启动方式:
|
启动方式:
|
||||||
|
|
||||||
- 先执行 start-cluster.sh,会自动根据 6381 ~ 6389 目录启动服务器,并将其配置为集群。
|
- 先执行 redis-cluster.sh,会自动根据 7001 ~ 7006 目录启动服务器,并将其配置为集群。
|
||||||
- 再执行 start-sentinel.sh,会根据 26381 ~ 26383 目录启动哨兵,监听集群中的三个主节点。
|
- 再执行 start-sentinel.sh,会根据 27001 ~ 27003 目录启动哨兵,监听集群中的三个主节点。
|
||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
(1)集群服务器配置 redis.conf
|
(1)集群服务器配置 redis.conf
|
||||||
|
|
||||||
```
|
```
|
||||||
port 6381
|
port 7001
|
||||||
bind 0.0.0.0
|
bind 0.0.0.0
|
||||||
daemonize yes
|
daemonize yes
|
||||||
|
|
||||||
cluster-enabled yes
|
cluster-enabled yes
|
||||||
cluster-config-file /usr/local/redis/conf/6381/6381.conf
|
cluster-config-file /usr/local/redis/conf/7001/7001.conf
|
||||||
cluster-node-timeout 10000
|
cluster-node-timeout 10000
|
||||||
|
|
||||||
appendonly yes
|
appendonly yes
|
||||||
dir /usr/local/redis/conf/6381
|
dir /usr/local/redis/conf/7001
|
||||||
pidfile /usr/local/redis/conf/6381/6381.pid
|
pidfile /usr/local/redis/conf/7001/7001.pid
|
||||||
logfile /usr/local/redis/conf/6381/6381.log
|
logfile /usr/local/redis/conf/7001/7001.log
|
||||||
```
|
```
|
||||||
|
|
||||||
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
||||||
|
@ -36,18 +36,18 @@ logfile /usr/local/redis/conf/6381/6381.log
|
||||||
(2)哨兵服务器配置 sentinel.conf
|
(2)哨兵服务器配置 sentinel.conf
|
||||||
|
|
||||||
```
|
```
|
||||||
port 26383
|
port 27003
|
||||||
daemonize yes
|
daemonize yes
|
||||||
sentinel monitor redis-master 172.22.6.3 6383 2
|
sentinel monitor redis-master 172.22.6.3 7003 2
|
||||||
sentinel down-after-milliseconds redis-master 5000
|
sentinel down-after-milliseconds redis-master 5000
|
||||||
sentinel failover-timeout redis-master 900000
|
sentinel failover-timeout redis-master 900000
|
||||||
sentinel parallel-syncs redis-master 1
|
sentinel parallel-syncs redis-master 1
|
||||||
#sentinel auth-pass redis-master 123456
|
#sentinel auth-pass redis-master 123456
|
||||||
logfile /usr/local/redis/conf/26383/26383.log
|
logfile /usr/local/redis/conf/27003/27003.log
|
||||||
```
|
```
|
||||||
|
|
||||||
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
||||||
|
|
||||||
最重要的配置在于:sentinel monitor redis-master 172.22.6.3 6383 2
|
最重要的配置在于:sentinel monitor redis-master 172.22.6.3 7003 2
|
||||||
|
|
||||||
表示监听的服务器集群名叫 redis-master,当前哨兵监听的服务器节点是:172.22.6.3:6383,这个节点如果是主节点,一旦宕机,选举新的主节点,需要至少 2 个哨兵同意。
|
表示监听的服务器集群名叫 redis-master,当前哨兵监听的服务器节点是:172.22.6.3:7003,这个节点如果是主节点,一旦宕机,选举新的主节点,需要至少 2 个哨兵同意。
|
||||||
|
|
|
@ -1,25 +1,35 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
PORT=6380
|
HOST="172.22.6.3"
|
||||||
|
PORT=7000
|
||||||
TIMEOUT=2000
|
TIMEOUT=2000
|
||||||
NODES=6
|
NODES=6
|
||||||
REPLICAS=1
|
REPLICAS=1
|
||||||
|
ENDPORT=$((PORT+NODES))
|
||||||
|
|
||||||
# You may want to put the above config parameters into config.sh in order to
|
# You may want to put the above config parameters into config.sh in order to
|
||||||
# override the defaults without modifying this script.
|
# override the defaults without modifying this script.
|
||||||
|
|
||||||
if [ -a config.sh ]
|
if [[ -a config.sh ]]
|
||||||
then
|
then
|
||||||
source "config.sh"
|
source "config.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Computed vars
|
if [[ "$1" == "create" ]]
|
||||||
ENDPORT=$((PORT+NODES))
|
|
||||||
|
|
||||||
if [ "$1" == "start" ]
|
|
||||||
then
|
then
|
||||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
HOSTLIST=""
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
HOSTLIST="$HOSTLIST $HOST:$PORT"
|
||||||
|
done
|
||||||
|
/opt/redis/src/redis-cli --cluster create ${HOSTLIST} --cluster-replicas ${REPLICAS}
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "start" ]]
|
||||||
|
then
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
PORT=$((PORT+1))
|
PORT=$((PORT+1))
|
||||||
echo "Starting $PORT"
|
echo "Starting $PORT"
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf
|
/opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf
|
||||||
|
@ -27,40 +37,29 @@ then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "create" ]
|
if [[ "$1" == "stop" ]]
|
||||||
then
|
then
|
||||||
HOSTS=""
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
||||||
PORT=$((PORT+1))
|
|
||||||
HOSTS="$HOSTS 127.0.0.1:$PORT"
|
|
||||||
done
|
|
||||||
/opt/redis/src/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$1" == "stop" ]
|
|
||||||
then
|
|
||||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
||||||
PORT=$((PORT+1))
|
PORT=$((PORT+1))
|
||||||
echo "Stopping $PORT"
|
echo "Stopping $PORT"
|
||||||
/opt/redis/src/redis-cli -p $PORT shutdown nosave
|
/opt/redis/src/redis-cli -p ${PORT} shutdown nosave
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "watch" ]
|
if [[ "$1" == "watch" ]]
|
||||||
then
|
then
|
||||||
PORT=$((PORT+1))
|
PORT=$((PORT+1))
|
||||||
while [ 1 ]; do
|
while [ 1 ]; do
|
||||||
clear
|
clear
|
||||||
date
|
date
|
||||||
/opt/redis/src/redis-cli -p $PORT cluster nodes | head -30
|
/opt/redis/src/redis-cli -p ${PORT} cluster nodes | head -30
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "tail" ]
|
if [[ "$1" == "tail" ]]
|
||||||
then
|
then
|
||||||
INSTANCE=$2
|
INSTANCE=$2
|
||||||
PORT=$((PORT+INSTANCE))
|
PORT=$((PORT+INSTANCE))
|
||||||
|
@ -68,16 +67,16 @@ then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "call" ]
|
if [[ "$1" == "call" ]]
|
||||||
then
|
then
|
||||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
PORT=$((PORT+1))
|
PORT=$((PORT+1))
|
||||||
/opt/redis/src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
|
/opt/redis/src/redis-cli -p ${PORT} $2 $3 $4 $5 $6 $7 $8 $9
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "clean" ]
|
if [[ "$1" == "clean" ]]
|
||||||
then
|
then
|
||||||
rm -rf *.log
|
rm -rf *.log
|
||||||
rm -rf appendonly*.aof
|
rm -rf appendonly*.aof
|
||||||
|
@ -86,7 +85,7 @@ then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" == "clean-logs" ]
|
if [[ "$1" == "clean-logs" ]]
|
||||||
then
|
then
|
||||||
rm -rf *.log
|
rm -rf *.log
|
||||||
exit 0
|
exit 0
|
|
@ -0,0 +1,101 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
HOST="172.22.6.3"
|
||||||
|
PORT=7000
|
||||||
|
TIMEOUT=2000
|
||||||
|
NODES=12
|
||||||
|
REPLICAS=1
|
||||||
|
ENDPORT=$((PORT+NODES))
|
||||||
|
|
||||||
|
# You may want to put the above config parameters into config.sh in order to
|
||||||
|
# override the defaults without modifying this script.
|
||||||
|
|
||||||
|
if [[ -a config.sh ]]
|
||||||
|
then
|
||||||
|
source "config.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "create" ]]
|
||||||
|
then
|
||||||
|
HOSTLIST=""
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
HOSTLIST="$HOSTLIST $HOST:$PORT"
|
||||||
|
done
|
||||||
|
/opt/redis/src/redis-cli --cluster create ${HOSTLIST} --cluster-replicas ${REPLICAS}
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "start" ]]
|
||||||
|
then
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
echo "Starting $PORT"
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "stop" ]]
|
||||||
|
then
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
echo "Stopping $PORT"
|
||||||
|
/opt/redis/src/redis-cli -p ${PORT} shutdown nosave
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "watch" ]]
|
||||||
|
then
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
while [ 1 ]; do
|
||||||
|
clear
|
||||||
|
date
|
||||||
|
/opt/redis/src/redis-cli -p ${PORT} cluster nodes | head -30
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "tail" ]]
|
||||||
|
then
|
||||||
|
INSTANCE=$2
|
||||||
|
PORT=$((PORT+INSTANCE))
|
||||||
|
tail -f ${PORT}.log
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "call" ]]
|
||||||
|
then
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
/opt/redis/src/redis-cli -p ${PORT} $2 $3 $4 $5 $6 $7 $8 $9
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "clean" ]]
|
||||||
|
then
|
||||||
|
rm -rf *.log
|
||||||
|
rm -rf appendonly*.aof
|
||||||
|
rm -rf dump*.rdb
|
||||||
|
rm -rf nodes*.conf
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "clean-logs" ]]
|
||||||
|
then
|
||||||
|
rm -rf *.log
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Usage: $0 [start|create|stop|watch|tail|clean]"
|
||||||
|
echo "start -- Launch Redis Cluster instances."
|
||||||
|
echo "create -- Create a cluster using redis-cli --cluster create."
|
||||||
|
echo "stop -- Stop Redis Cluster instances."
|
||||||
|
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
|
||||||
|
echo "tail <id> -- Run tail -f of instance at base port + ID."
|
||||||
|
echo "clean -- Remove all instances data, logs, configs."
|
||||||
|
echo "clean-logs -- Remove just instances logs."
|
|
@ -1,19 +1,21 @@
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6381/redis.conf
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6382/redis.conf
|
PORT=6380
|
||||||
|
NODES=6
|
||||||
|
ENDPORT=$((PORT+NODES))
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6383/redis.conf
|
# 启动 4 个 redis server
|
||||||
|
while [[ $((PORT < ENDPORT)) != "0" ]]; do
|
||||||
|
PORT=$((PORT+1))
|
||||||
|
echo "Starting $PORT"
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf
|
||||||
|
done
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6384/redis.conf
|
# 创建集群模式,设置副本为 1
|
||||||
|
# redis cluster 会自动将 4 个节点设置为 一主一从 模式,并且为两个主节点做数据分片
|
||||||
|
/opt/redis/src/redis-cli --cluster create 172.22.6.3:6381 172.22.6.3:6382 172.22.6.3:6383 172.22.6.3:6384 172.22.6.3:6385 172.22.6.3:6386 --cluster-replicas 1
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6385/redis.conf
|
# 启动哨兵
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26381/sentinel.conf
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6386/redis.conf
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26382/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26383/sentinel.conf
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6387/redis.conf
|
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6388/redis.conf
|
|
||||||
|
|
||||||
/opt/redis/src/redis-server /usr/local/redis/conf/6389/redis.conf
|
|
||||||
|
|
||||||
/opt/redis/src/redis-cli --cluster create 172.22.6.3:6381 172.22.6.3:6382 172.22.6.3:6383 172.22.6.3:6384 172.22.6.3:6385 172.22.6.3:6386 172.22.6.3:6387 172.22.6.3:6388 172.22.6.3:6389 --cluster-replicas 2
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# 启动 4 个 redis server
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6381/redis.conf
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6382/redis.conf
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6383/redis.conf
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6384/redis.conf
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6385/redis.conf
|
||||||
|
/opt/redis/src/redis-server /usr/local/redis/conf/6386/redis.conf
|
||||||
|
|
||||||
|
# 创建集群模式,设置副本为 1
|
||||||
|
# redis cluster 会自动将 4 个节点设置为 一主一从 模式,并且为两个主节点做数据分片
|
||||||
|
/opt/redis/src/redis-cli --cluster create 172.22.6.3:6381 172.22.6.3:6382 172.22.6.3:6383 172.22.6.3:6384 172.22.6.3:6385 172.22.6.3:6386 --cluster-replicas 1
|
||||||
|
|
||||||
|
# 启动哨兵
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26381/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26382/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26383/sentinel.conf
|
|
@ -1,3 +1,6 @@
|
||||||
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26381/sentinel.conf
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27001/sentinel.conf
|
||||||
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26382/sentinel.conf
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27002/sentinel.conf
|
||||||
/opt/redis/src/redis-sentinel /usr/local/redis/conf/26383/sentinel.conf
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27003/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27004/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27005/sentinel.conf
|
||||||
|
/opt/redis/src/redis-sentinel /usr/local/redis/conf/27006/sentinel.conf
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
|
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
|
||||||
# JUST COMMENT THE FOLLOWING LINE.
|
# JUST COMMENT THE FOLLOWING LINE.
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
bind 0.0.0.0
|
bind 172.22.6.3
|
||||||
|
|
||||||
# Protected mode is a layer of security protection, in order to avoid that
|
# Protected mode is a layer of security protection, in order to avoid that
|
||||||
# Redis instances left open on the internet are accessed and exploited.
|
# Redis instances left open on the internet are accessed and exploited.
|
||||||
|
|
Loading…
Reference in New Issue