From b6d9c81ffbc2a402c592797719836c5ac5c8ff26 Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Thu, 16 Jul 2020 11:21:46 +0800 Subject: [PATCH] =?UTF-8?q?Redis=20Cluster=20=E9=85=8D=E7=BD=AE=E6=A1=88?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cluster/{26381 => 27001}/sentinel.conf | 6 +- .../cluster/{26382 => 27002}/sentinel.conf | 6 +- .../cluster/{26383 => 27003}/sentinel.conf | 6 +- .../config/redis/cluster/27004/sentinel.conf | 8 ++ .../config/redis/cluster/27005/sentinel.conf | 8 ++ .../config/redis/cluster/27006/sentinel.conf | 8 ++ .../soft/config/redis/cluster/6381/redis.conf | 12 --- .../soft/config/redis/cluster/6382/redis.conf | 12 --- .../soft/config/redis/cluster/6383/redis.conf | 12 --- .../soft/config/redis/cluster/6384/redis.conf | 12 --- .../soft/config/redis/cluster/6385/redis.conf | 12 --- .../soft/config/redis/cluster/6386/redis.conf | 12 --- .../soft/config/redis/cluster/6387/redis.conf | 12 --- .../soft/config/redis/cluster/6388/redis.conf | 12 --- .../soft/config/redis/cluster/6389/redis.conf | 12 --- .../soft/config/redis/cluster/7001/redis.conf | 12 +++ .../soft/config/redis/cluster/7002/redis.conf | 12 +++ .../soft/config/redis/cluster/7003/redis.conf | 12 +++ .../soft/config/redis/cluster/7004/redis.conf | 12 +++ .../soft/config/redis/cluster/7005/redis.conf | 12 +++ .../soft/config/redis/cluster/7006/redis.conf | 12 +++ .../soft/config/redis/cluster/7007/redis.conf | 12 +++ .../soft/config/redis/cluster/7008/redis.conf | 12 +++ .../soft/config/redis/cluster/7009/redis.conf | 12 +++ .../soft/config/redis/cluster/7010/redis.conf | 12 +++ .../soft/config/redis/cluster/7011/redis.conf | 12 +++ .../soft/config/redis/cluster/7012/redis.conf | 12 +++ .../linux/soft/config/redis/cluster/README.md | 28 ++--- .../{create-cluster => redis-cluster.sh} | 59 +++++----- .../config/redis/cluster/redis-cluster2.sh | 101 ++++++++++++++++++ .../config/redis/cluster/start-cluster.sh | 32 +++--- .../config/redis/cluster/start-cluster2.sh | 18 ++++ .../config/redis/cluster/start-sentinel.sh | 9 +- codes/linux/soft/config/redis/redis.conf | 2 +- 34 files changed, 363 insertions(+), 180 deletions(-) rename codes/linux/soft/config/redis/cluster/{26381 => 27001}/sentinel.conf (64%) rename codes/linux/soft/config/redis/cluster/{26382 => 27002}/sentinel.conf (64%) rename codes/linux/soft/config/redis/cluster/{26383 => 27003}/sentinel.conf (64%) create mode 100644 codes/linux/soft/config/redis/cluster/27004/sentinel.conf create mode 100644 codes/linux/soft/config/redis/cluster/27005/sentinel.conf create mode 100644 codes/linux/soft/config/redis/cluster/27006/sentinel.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6381/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6382/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6383/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6384/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6385/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6386/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6387/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6388/redis.conf delete mode 100644 codes/linux/soft/config/redis/cluster/6389/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7001/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7002/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7003/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7004/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7005/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7006/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7007/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7008/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7009/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7010/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7011/redis.conf create mode 100644 codes/linux/soft/config/redis/cluster/7012/redis.conf rename codes/linux/soft/config/redis/cluster/{create-cluster => redis-cluster.sh} (63%) create mode 100644 codes/linux/soft/config/redis/cluster/redis-cluster2.sh create mode 100644 codes/linux/soft/config/redis/cluster/start-cluster2.sh diff --git a/codes/linux/soft/config/redis/cluster/26381/sentinel.conf b/codes/linux/soft/config/redis/cluster/27001/sentinel.conf similarity index 64% rename from codes/linux/soft/config/redis/cluster/26381/sentinel.conf rename to codes/linux/soft/config/redis/cluster/27001/sentinel.conf index a4b3f94..0b7a6f0 100644 --- a/codes/linux/soft/config/redis/cluster/26381/sentinel.conf +++ b/codes/linux/soft/config/redis/cluster/27001/sentinel.conf @@ -1,8 +1,8 @@ -port 26381 +port 27001 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 failover-timeout redis-master 900000 sentinel parallel-syncs redis-master 1 #sentinel auth-pass redis-master 123456 -logfile /usr/local/redis/conf/26381/26381.log \ No newline at end of file +logfile /usr/local/redis/conf/27001/27001.log \ No newline at end of file diff --git a/codes/linux/soft/config/redis/cluster/26382/sentinel.conf b/codes/linux/soft/config/redis/cluster/27002/sentinel.conf similarity index 64% rename from codes/linux/soft/config/redis/cluster/26382/sentinel.conf rename to codes/linux/soft/config/redis/cluster/27002/sentinel.conf index db20a61..d208d9e 100644 --- a/codes/linux/soft/config/redis/cluster/26382/sentinel.conf +++ b/codes/linux/soft/config/redis/cluster/27002/sentinel.conf @@ -1,8 +1,8 @@ -port 26382 +port 27002 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 failover-timeout redis-master 900000 sentinel parallel-syncs redis-master 1 #sentinel auth-pass redis-master 123456 -logfile /usr/local/redis/conf/26382/26382.log \ No newline at end of file +logfile /usr/local/redis/conf/27002/27002.log \ No newline at end of file diff --git a/codes/linux/soft/config/redis/cluster/26383/sentinel.conf b/codes/linux/soft/config/redis/cluster/27003/sentinel.conf similarity index 64% rename from codes/linux/soft/config/redis/cluster/26383/sentinel.conf rename to codes/linux/soft/config/redis/cluster/27003/sentinel.conf index fc5af05..c6d8588 100644 --- a/codes/linux/soft/config/redis/cluster/26383/sentinel.conf +++ b/codes/linux/soft/config/redis/cluster/27003/sentinel.conf @@ -1,8 +1,8 @@ -port 26383 +port 27003 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 failover-timeout redis-master 900000 sentinel parallel-syncs redis-master 1 #sentinel auth-pass redis-master 123456 -logfile /usr/local/redis/conf/26383/26383.log \ No newline at end of file +logfile /usr/local/redis/conf/27003/27003.log \ No newline at end of file diff --git a/codes/linux/soft/config/redis/cluster/27004/sentinel.conf b/codes/linux/soft/config/redis/cluster/27004/sentinel.conf new file mode 100644 index 0000000..39f1088 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/27004/sentinel.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/27005/sentinel.conf b/codes/linux/soft/config/redis/cluster/27005/sentinel.conf new file mode 100644 index 0000000..a33aa83 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/27005/sentinel.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/27006/sentinel.conf b/codes/linux/soft/config/redis/cluster/27006/sentinel.conf new file mode 100644 index 0000000..a006f15 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/27006/sentinel.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6381/redis.conf b/codes/linux/soft/config/redis/cluster/6381/redis.conf deleted file mode 100644 index 054c1f0..0000000 --- a/codes/linux/soft/config/redis/cluster/6381/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6382/redis.conf b/codes/linux/soft/config/redis/cluster/6382/redis.conf deleted file mode 100644 index d5d62e1..0000000 --- a/codes/linux/soft/config/redis/cluster/6382/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6383/redis.conf b/codes/linux/soft/config/redis/cluster/6383/redis.conf deleted file mode 100644 index 41e10ee..0000000 --- a/codes/linux/soft/config/redis/cluster/6383/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6384/redis.conf b/codes/linux/soft/config/redis/cluster/6384/redis.conf deleted file mode 100644 index b57fef5..0000000 --- a/codes/linux/soft/config/redis/cluster/6384/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6385/redis.conf b/codes/linux/soft/config/redis/cluster/6385/redis.conf deleted file mode 100644 index 7535e79..0000000 --- a/codes/linux/soft/config/redis/cluster/6385/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6386/redis.conf b/codes/linux/soft/config/redis/cluster/6386/redis.conf deleted file mode 100644 index 03f1127..0000000 --- a/codes/linux/soft/config/redis/cluster/6386/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6387/redis.conf b/codes/linux/soft/config/redis/cluster/6387/redis.conf deleted file mode 100644 index 31ccfe9..0000000 --- a/codes/linux/soft/config/redis/cluster/6387/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6388/redis.conf b/codes/linux/soft/config/redis/cluster/6388/redis.conf deleted file mode 100644 index 6f159f9..0000000 --- a/codes/linux/soft/config/redis/cluster/6388/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/6389/redis.conf b/codes/linux/soft/config/redis/cluster/6389/redis.conf deleted file mode 100644 index e9a17b3..0000000 --- a/codes/linux/soft/config/redis/cluster/6389/redis.conf +++ /dev/null @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7001/redis.conf b/codes/linux/soft/config/redis/cluster/7001/redis.conf new file mode 100644 index 0000000..34bd021 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7001/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7002/redis.conf b/codes/linux/soft/config/redis/cluster/7002/redis.conf new file mode 100644 index 0000000..5e7fbc0 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7002/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7003/redis.conf b/codes/linux/soft/config/redis/cluster/7003/redis.conf new file mode 100644 index 0000000..e87573d --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7003/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7004/redis.conf b/codes/linux/soft/config/redis/cluster/7004/redis.conf new file mode 100644 index 0000000..1b4d608 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7004/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7005/redis.conf b/codes/linux/soft/config/redis/cluster/7005/redis.conf new file mode 100644 index 0000000..d959a8d --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7005/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7006/redis.conf b/codes/linux/soft/config/redis/cluster/7006/redis.conf new file mode 100644 index 0000000..6fd2635 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7006/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7007/redis.conf b/codes/linux/soft/config/redis/cluster/7007/redis.conf new file mode 100644 index 0000000..5cd28ed --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7007/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7008/redis.conf b/codes/linux/soft/config/redis/cluster/7008/redis.conf new file mode 100644 index 0000000..54efbd8 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7008/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7009/redis.conf b/codes/linux/soft/config/redis/cluster/7009/redis.conf new file mode 100644 index 0000000..41bdc4c --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7009/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7010/redis.conf b/codes/linux/soft/config/redis/cluster/7010/redis.conf new file mode 100644 index 0000000..b3b73f3 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7010/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7011/redis.conf b/codes/linux/soft/config/redis/cluster/7011/redis.conf new file mode 100644 index 0000000..ad94ad0 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7011/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/7012/redis.conf b/codes/linux/soft/config/redis/cluster/7012/redis.conf new file mode 100644 index 0000000..8b97944 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/7012/redis.conf @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/README.md b/codes/linux/soft/config/redis/cluster/README.md index 3d37908..f632241 100644 --- a/codes/linux/soft/config/redis/cluster/README.md +++ b/codes/linux/soft/config/redis/cluster/README.md @@ -4,31 +4,31 @@ 集群拓扑: -- 三主六从,每个主节点有两个从节点。 -- 三哨兵,分别监听其中一个主节点。 +- 三主三从 +- 三哨兵 启动方式: -- 先执行 start-cluster.sh,会自动根据 6381 ~ 6389 目录启动服务器,并将其配置为集群。 -- 再执行 start-sentinel.sh,会根据 26381 ~ 26383 目录启动哨兵,监听集群中的三个主节点。 +- 先执行 redis-cluster.sh,会自动根据 7001 ~ 7006 目录启动服务器,并将其配置为集群。 +- 再执行 start-sentinel.sh,会根据 27001 ~ 27003 目录启动哨兵,监听集群中的三个主节点。 ## 配置 (1)集群服务器配置 redis.conf ``` -port 6381 +port 7001 bind 0.0.0.0 daemonize 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 appendonly yes -dir /usr/local/redis/conf/6381 -pidfile /usr/local/redis/conf/6381/6381.pid -logfile /usr/local/redis/conf/6381/6381.log +dir /usr/local/redis/conf/7001 +pidfile /usr/local/redis/conf/7001/7001.pid +logfile /usr/local/redis/conf/7001/7001.log ``` 端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。 @@ -36,18 +36,18 @@ logfile /usr/local/redis/conf/6381/6381.log (2)哨兵服务器配置 sentinel.conf ``` -port 26383 +port 27003 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 failover-timeout redis-master 900000 sentinel parallel-syncs redis-master 1 #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`)根据实际情况修改。 -最重要的配置在于: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 个哨兵同意。 \ No newline at end of file +表示监听的服务器集群名叫 redis-master,当前哨兵监听的服务器节点是:172.22.6.3:7003,这个节点如果是主节点,一旦宕机,选举新的主节点,需要至少 2 个哨兵同意。 diff --git a/codes/linux/soft/config/redis/cluster/create-cluster b/codes/linux/soft/config/redis/cluster/redis-cluster.sh similarity index 63% rename from codes/linux/soft/config/redis/cluster/create-cluster rename to codes/linux/soft/config/redis/cluster/redis-cluster.sh index ac133a5..07c44d7 100644 --- a/codes/linux/soft/config/redis/cluster/create-cluster +++ b/codes/linux/soft/config/redis/cluster/redis-cluster.sh @@ -1,25 +1,35 @@ -#!/bin/bash +#!/usr/bin/env bash # Settings -PORT=6380 +HOST="172.22.6.3" +PORT=7000 TIMEOUT=2000 NODES=6 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 ] +if [[ -a config.sh ]] then source "config.sh" fi -# Computed vars -ENDPORT=$((PORT+NODES)) - -if [ "$1" == "start" ] +if [[ "$1" == "create" ]] 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)) echo "Starting $PORT" /opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf @@ -27,40 +37,29 @@ then exit 0 fi -if [ "$1" == "create" ] +if [[ "$1" == "stop" ]] then - HOSTS="" - 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 + while [[ $((PORT < ENDPORT)) != "0" ]]; do PORT=$((PORT+1)) echo "Stopping $PORT" - /opt/redis/src/redis-cli -p $PORT shutdown nosave + /opt/redis/src/redis-cli -p ${PORT} shutdown nosave done exit 0 fi -if [ "$1" == "watch" ] +if [[ "$1" == "watch" ]] then PORT=$((PORT+1)) while [ 1 ]; do clear 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 done exit 0 fi -if [ "$1" == "tail" ] +if [[ "$1" == "tail" ]] then INSTANCE=$2 PORT=$((PORT+INSTANCE)) @@ -68,16 +67,16 @@ then exit 0 fi -if [ "$1" == "call" ] +if [[ "$1" == "call" ]] then - while [ $((PORT < ENDPORT)) != "0" ]; do + while [[ $((PORT < ENDPORT)) != "0" ]]; do 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 exit 0 fi -if [ "$1" == "clean" ] +if [[ "$1" == "clean" ]] then rm -rf *.log rm -rf appendonly*.aof @@ -86,7 +85,7 @@ then exit 0 fi -if [ "$1" == "clean-logs" ] +if [[ "$1" == "clean-logs" ]] then rm -rf *.log exit 0 diff --git a/codes/linux/soft/config/redis/cluster/redis-cluster2.sh b/codes/linux/soft/config/redis/cluster/redis-cluster2.sh new file mode 100644 index 0000000..3e3b37e --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/redis-cluster2.sh @@ -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 -- Run tail -f of instance at base port + ID." +echo "clean -- Remove all instances data, logs, configs." +echo "clean-logs -- Remove just instances logs." diff --git a/codes/linux/soft/config/redis/cluster/start-cluster.sh b/codes/linux/soft/config/redis/cluster/start-cluster.sh index 71eb01c..c9ec4be 100644 --- a/codes/linux/soft/config/redis/cluster/start-cluster.sh +++ b/codes/linux/soft/config/redis/cluster/start-cluster.sh @@ -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-server /usr/local/redis/conf/6386/redis.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 +# 启动哨兵 +/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 diff --git a/codes/linux/soft/config/redis/cluster/start-cluster2.sh b/codes/linux/soft/config/redis/cluster/start-cluster2.sh new file mode 100644 index 0000000..54b59c9 --- /dev/null +++ b/codes/linux/soft/config/redis/cluster/start-cluster2.sh @@ -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 diff --git a/codes/linux/soft/config/redis/cluster/start-sentinel.sh b/codes/linux/soft/config/redis/cluster/start-sentinel.sh index 9b14673..a21c7d6 100644 --- a/codes/linux/soft/config/redis/cluster/start-sentinel.sh +++ b/codes/linux/soft/config/redis/cluster/start-sentinel.sh @@ -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/26382/sentinel.conf -/opt/redis/src/redis-sentinel /usr/local/redis/conf/26383/sentinel.conf +/opt/redis/src/redis-sentinel /usr/local/redis/conf/27001/sentinel.conf +/opt/redis/src/redis-sentinel /usr/local/redis/conf/27002/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 diff --git a/codes/linux/soft/config/redis/redis.conf b/codes/linux/soft/config/redis/redis.conf index 798b879..9062850 100644 --- a/codes/linux/soft/config/redis/redis.conf +++ b/codes/linux/soft/config/redis/redis.conf @@ -66,7 +66,7 @@ # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # 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 # Redis instances left open on the internet are accessed and exploited.