本文主要mark下redis sentinel搭建過程,本次搭建redis使用master+ slave,sentinel使用最小配置(3個)
redis sentinel 掃盲請參考 https://redis.io/topics/sentinel
DJY(management+djy+datasync) local testbed installation
文章目錄
- 下載下傳redis5.0 dockers鏡像檔案
- 使用下述dockers compose檔案, 建立3個鏡像redis (master +2 slave )
使用如下指令建立redis 容器version: '3.7' services: redis-master: image: redis:5 container_name: redis-master restart: always network_mode: "host" volumes: - type: volume source: redis-master target: /data command: --appendonly yes --port 6379 redis-slave1: image: redis:5 container_name: redis-slave1 restart: always depends_on: - redis-master network_mode: "host" volumes: - type: volume source: redis-slave1 target: /data command: --appendonly yes --port 6380 --slaveof 127.0.0.1 6379 redis-slave2: image: redis:5 container_name: redis-slave2 restart: always depends_on: - redis-master network_mode: "host" volumes: - type: volume source: redis-slave2 target: /data command: --appendonly yes --port 6381 --slaveof 127.0.0.1 6379 volumes: redis-master: redis-slave1: redis-slave2:
docker-compose up -d
-
redis sentinel 安裝
redis sentinel最小需要配置三個sentinel。
sentinel leader 配置檔案内容如下:
sentinel follow1 配置檔案内容如下:port 36379 dir "/var/redis/data" sentinel myid 29c0734753f7de85017a1111ce2b46a7a780ab9d sentinel deny-scripts-reconfig yes sentinel monitor redis-master 127.0.0.1 6379 2 sentinel config-epoch redis-master 0
sentinel follow2 配置檔案内容如下:port 36380 dir "/var/redis/data" sentinel myid b290690d6817d721e3872cd142e4f58f90034b22 sentinel deny-scripts-reconfig yes sentinel monitor redis-master 127.0.0.1 6379 2 sentinel config-epoch redis-master 0
sentinel使用dockers-compose 啟動,compose檔案内容如下:port 36381 dir "/var/redis/data" sentinel myid 2da5366952c656ccadef934b76adceee5a603e14 sentinel deny-scripts-reconfig yes sentinel monitor redis-master 127.0.0.1 6379 2 sentinel config-epoch redis-master 0
啟動redis sentinel使用docker composeversion: '3.7' services: redis-sentinel-leader: image: redis:5 container_name: redis-sentinel-leader restart: always network_mode: "host" volumes: - type: volume source: redis-sentinel-leader target: /var/redis/data - type: bind source: ./sentinel-leader.conf target: /conf/sentinel-leader.conf command: /conf/sentinel-leader.conf --sentinel redis-sentinel-follow1: image: redis:5 container_name: redis-sentinel-follow1 restart: always depends_on: - redis-sentinel-leader network_mode: "host" volumes: - type: volume source: redis-sentinel-follow1 target: /var/redis/data - type: bind source: ./sentinel-follow1.conf target: /conf/sentinel-follow1.conf command: /conf/sentinel-follow1.conf --sentinel redis-sentinel-follow2: image: redis:5 container_name: redis-sentinel-follow2 restart: always depends_on: - redis-sentinel-leader - redis-sentinel-follow1 network_mode: "host" volumes: - type: volume source: redis-sentinel-follow2 target: /var/redis/data - type: bind source: ./sentinel-follow2.conf target: /conf/sentinel-follow2.conf command: /conf/sentinel-follow2.conf --sentinel volumes: redis-sentinel-leader: redis-sentinel-follow1: redis-sentinel-follow2:
啟動成功後,容器的運作狀态如:docker-compose up -d
[[email protected] docker-install]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
710ec199db2c redis:5 "docker-entrypoint.s鈥 41 hours ago Up 41 hours redis-sentinel-follow2
d19766731096 redis:5 "docker-entrypoint.s鈥 41 hours ago Up 41 hours redis-sentinel-follow1
a8e12b67c3c4 redis:5 "docker-entrypoint.s鈥 41 hours ago Up 41 hours redis-sentinel-leader
99abd2a8c4f5 redis:5 "docker-entrypoint.s鈥 2 days ago Up 2 days redis-slave2
c9a105ca53f2 redis:5 "docker-entrypoint.s鈥 2 days ago Up 2 days redis-slave1
b636cc3475aa redis:5 "docker-entrypoint.s鈥 2 days ago Up 2 days redis-master