2020-06-24 10:56:56 +08:00
|
|
|
|
# Redis 集群配置
|
|
|
|
|
|
|
|
|
|
## 使用方式
|
|
|
|
|
|
|
|
|
|
集群拓扑:
|
|
|
|
|
|
2020-07-16 11:21:46 +08:00
|
|
|
|
- 三主三从
|
|
|
|
|
- 三哨兵
|
2020-06-24 10:56:56 +08:00
|
|
|
|
|
|
|
|
|
启动方式:
|
|
|
|
|
|
2020-07-16 11:21:46 +08:00
|
|
|
|
- 先执行 redis-cluster.sh,会自动根据 7001 ~ 7006 目录启动服务器,并将其配置为集群。
|
|
|
|
|
- 再执行 start-sentinel.sh,会根据 27001 ~ 27003 目录启动哨兵,监听集群中的三个主节点。
|
2020-06-24 10:56:56 +08:00
|
|
|
|
|
|
|
|
|
## 配置
|
|
|
|
|
|
|
|
|
|
(1)集群服务器配置 redis.conf
|
|
|
|
|
|
|
|
|
|
```
|
2020-07-16 11:21:46 +08:00
|
|
|
|
port 7001
|
2020-06-24 10:56:56 +08:00
|
|
|
|
bind 0.0.0.0
|
|
|
|
|
daemonize yes
|
|
|
|
|
|
|
|
|
|
cluster-enabled yes
|
2020-07-16 11:21:46 +08:00
|
|
|
|
cluster-config-file /usr/local/redis/conf/7001/7001.conf
|
2020-06-24 10:56:56 +08:00
|
|
|
|
cluster-node-timeout 10000
|
|
|
|
|
|
|
|
|
|
appendonly yes
|
2020-07-16 11:21:46 +08:00
|
|
|
|
dir /usr/local/redis/conf/7001
|
|
|
|
|
pidfile /usr/local/redis/conf/7001/7001.pid
|
|
|
|
|
logfile /usr/local/redis/conf/7001/7001.log
|
2020-06-24 10:56:56 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
|
|
|
|
|
|
|
|
|
(2)哨兵服务器配置 sentinel.conf
|
|
|
|
|
|
|
|
|
|
```
|
2020-07-16 11:21:46 +08:00
|
|
|
|
port 27003
|
2020-06-24 10:56:56 +08:00
|
|
|
|
daemonize yes
|
2020-07-16 11:21:46 +08:00
|
|
|
|
sentinel monitor redis-master 172.22.6.3 7003 2
|
2020-06-24 10:56:56 +08:00
|
|
|
|
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
|
2020-07-16 11:21:46 +08:00
|
|
|
|
logfile /usr/local/redis/conf/27003/27003.log
|
2020-06-24 10:56:56 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
端口号、配置目录(`/usr/local/redis/conf`)根据实际情况修改。
|
|
|
|
|
|
2020-07-16 11:21:46 +08:00
|
|
|
|
最重要的配置在于:sentinel monitor redis-master 172.22.6.3 7003 2
|
2020-06-24 10:56:56 +08:00
|
|
|
|
|
2020-07-16 11:21:46 +08:00
|
|
|
|
表示监听的服务器集群名叫 redis-master,当前哨兵监听的服务器节点是:172.22.6.3:7003,这个节点如果是主节点,一旦宕机,选举新的主节点,需要至少 2 个哨兵同意。
|