網站首頁 編程語言 正文
?目錄
1:獲取redis鏡像
2:創建redis主從+哨兵docker-compose文件
3:redis配置和哨兵配置說明
4:啟動docker-compose
5:查看啟動情況
6:進入主節點查看集群情況
本文以docker-compose 搭建高可用Redis 主從、哨兵集群為例子
關于redis主從,哨兵集群原理參見:Redis 單機安裝/ 哨兵模式集群安裝_慕菲煙云的博客-CSDN博客_redis哨兵模式安裝
由于redis哨兵模式的網絡和docker的網絡配合的并不是太好,這里docker的網絡需要用host模式,既docker容器直接使用宿主機的ip和端口。
1:獲取redis鏡像
docker pull redis:6.2.7
2:創建redis主從+哨兵docker-compose文件
cd /opt/docker/redis
vi docker-compose.yml
docker-compose.yml的內容如下?
version: '3'
services:
master:
image: redis:6.2.7 ## 鏡像
container_name: redis-master
command: redis-server /etc/redis/redis.conf --requirepass 123456 --masterauth 123456
volumes:
- /opt/docker/redis/data/redis_data1:/data
- /opt/docker/redis/conf/redis1.conf:/etc/redis/redis.conf
network_mode: "host"
slave1:
image: redis:6.2.7 ## 鏡像
container_name: redis-slave-1
volumes:
- /opt/docker/redis/data/redis_data2:/data
- /opt/docker/redis/conf/redis2.conf:/etc/redis/redis.conf
command: redis-server /etc/redis/redis.conf --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456
depends_on:
- master
network_mode: "host"
slave2:
image: redis:6.2.7 ## 鏡像
container_name: redis-slave-2
volumes:
- /opt/docker/redis/data/redis_data3:/data
- /opt/docker/redis/conf/redis3.conf:/etc/redis/redis.conf
command: redis-server /etc/redis/redis.conf --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456
depends_on:
- master
network_mode: "host"
sentinel1:
image: redis:6.2.7 ## 鏡像
container_name: redis-sentinel-1
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- /opt/docker/redis/conf/sentinel1.conf:/usr/local/etc/redis/sentinel.conf
network_mode: "host"
depends_on:
- master
- slave1
- slave2
sentinel2:
image: redis:6.2.7 ## 鏡像
container_name: redis-sentinel-2
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- /opt/docker/redis/conf/sentinel2.conf:/usr/local/etc/redis/sentinel.conf
network_mode: "host"
depends_on:
- master
- slave1
- slave2
sentinel3:
image: redis:6.2.7 ## 鏡像
container_name: redis-sentinel-3
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- /opt/docker/redis/conf/sentinel3.conf:/usr/local/etc/redis/sentinel.conf
network_mode: "host"
depends_on:
- master
- slave1
- slave2
3:redis配置和哨兵配置說明
?查看配置文件的目錄樹
cd /opt/docker/redis
tree ./
結構如下
redis1.conf,redis2.conf,redis3.conf配置如下
#redis1.conf
bind 0.0.0.0
port 6379
protected-mode no
slave-read-only no
#redis2.conf
bind 0.0.0.0
port 6380
protected-mode no
slave-read-only no
#redis3.conf
bind 0.0.0.0
port 6381
protected-mode no
slave-read-only no
?sentinel1.conf,sentinel1.conf,sentinel1.conf配置:
#sentinel1.conf
port 26379
dir /tmp
sentinel monitor mymaster 192.168.18.131 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
sentinel deny-scripts-reconfig yes
#sentinel2.conf
port 26380
dir /tmp
sentinel monitor mymaster 192.168.18.131 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
sentinel deny-scripts-reconfig yes
#sentinel3.conf
port 26381
dir /tmp
sentinel monitor mymaster 192.168.18.131 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
sentinel deny-scripts-reconfig yes
說明:
【sentinel monitor mymaster 192.168.18.131 6379 2】192.168.18.131為服務器的IP地址,6379為redis master的端口號
【sentinel auth-pass mymaster 123456?】設置主節點的密碼 ?
【sentinel down-after-milliseconds mymaster 30000】表示在一段時間范圍內sentinel向master發送的心跳PING沒有回復則認為master不可用了。?
【sentinel parallel-syncs mymaster 1】的parallel-syncs表示設置在故障轉移之后,同時可以重新配置使用新master的slave的數量。數字越低,更多的時間將會用故障轉移完成,但是如果slaves配置為服務舊數據,你可能不希望所有的slave同時重新同步master。因為主從復制對于slave是非阻塞的,當停止從master加載批量數據時有一個片刻延遲。通過設置選項為1,確信每次只有一個slave是不可到達的。
【sentinel failover-timeout mymaster 10000 ?】表示10秒內mymaster還沒活過來,則認為master宕機了。?
redis_data1,?redis_data2,redis_data3為空文件夾,用于存放redis數據文件
4:啟動docker-compose
docker-compose up
#或者,后臺啟動
docker-compose up -d
5:查看啟動情況
6:進入主節點查看集群情況
docker exec -it 主節點容器id或者容器名稱 bash
redis-cli -p 6379
info replication
原文鏈接:https://blog.csdn.net/qq_36793589/article/details/125670672
- 上一篇:go語言環境搭建
- 下一篇:Docker 安裝redis
相關推薦
- 2022-04-19 前端如何使用webpack優化性能
- 2022-12-23 react數據管理機制React.Context源碼解析_React
- 2022-09-27 C#中的const和readonly關鍵字詳解_C#教程
- 2022-04-28 python實用的快捷語法技巧大全_python
- 2022-08-19 python循環之彩色圓環實現示例_python
- 2022-12-24 Docker中redis集群部署實戰_docker
- 2023-03-26 使用docker安裝hadoop的實現過程_docker
- 2022-04-25 C#關于Func和Action委托的介紹詳解_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支