linux-tutorial/codes/linux/soft/config/redis/cluster/README.md

54 lines
1.4 KiB
Markdown
Raw Normal View History

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