Docker配置Redis哨兵
时间: 2024-04-24 14:25:08 浏览: 100
要配置Docker中的Redis哨兵,可以按照以下步骤进行操作:
1. 首先,确保已经安装了docker-compose,并且版本为1.29.2。可以使用以下命令进行安装:
```
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
```
2. 在`/usr/local/etc/redis`目录下创建一个`docker-compose.yml`文件,并将以下内容添加到文件中:
```
version: '3'
services:
master:
image: redis
container_name: redis-master
command: redis-server
ports:
- 6379:6379
slave1:
image: redis
container_name: redis-slave1
command: redis-server --slaveof redis-master 6379
ports:
- 6380:6380
slave2:
image: redis
container_name: redis-slave2
command: redis-server --slaveof redis-master 6379
ports:
- 6381:6381
```
3. 保存并关闭文件。
4. 在终端中,进入到包含`docker-compose.yml`文件的目录。
5. 运行以下命令启动Redis哨兵:
```
docker-compose up -d
```
这样,你就成功配置了Docker中的Redis哨兵。其中,`redis-master`是主节点,`redis-slave1`和`redis-slave2`是从节点。主节点会监听6379端口,从节点分别监听6380和6381端口。
#### 引用[.reference_title]
- *1* *3* [一分钟搞定docker+redis哨兵模式(一主二从三哨兵)](https://blog.csdn.net/helloworldchina/article/details/127355618)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [基于docker搭建redis哨兵模式](https://blog.csdn.net/qq_45061361/article/details/126899027)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文