老規(guī)矩,廢話不多說,直接上步驟加圖示渠欺。
1.拉取redis鏡像高蜂,直接最新版本
docker pull redis:latest
2.創(chuàng)建全部需要的文件夾和文件沥匈,我這里目錄如圖:
各目錄作用介紹:
masterslave -存放redis主從docker-compose.yml文件
redisconf -存放redis哨兵主配置文件
sentinel -存放redis的docker-compose.yml文件和哨兵多個配置文件
3.reids主從docker-compose.yml
version: '3.7'
services:
master:
image: redis
container_name: redis-master
restart: always
command: redis-server --requirepass 123456 --appendonly yes
ports:
- 6379:6379
#數(shù)據(jù)卷目錄掛載,都是當前目錄蔗喂,跟yml文件同級
volumes:
- ./data1:/data
slave1:
image: redis
container_name: redis-slave-1
restart: always
command: redis-server --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456 --appendonly yes
ports:
- 6380:6379
volumes:
- ./data2:/data
slave2:
image: redis
container_name: redis-slave-2
restart: always
command: redis-server --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456 --appendonly yes
ports:
- 6381:6379
volumes:
- ./data3:/data
4.進入redis主從目錄,先啟動redis主從
5.創(chuàng)建redis哨兵主配置文件和多個配置文件
主配置文件:
# 自定義集群名,192.168.001.220 為 redis-master 的 ip高帖,6379 為 redis-master 的端口缰儿,2 為最小投票數(shù)(因為有 3 臺 Sentinel 所以可以設(shè)置成 #2),kingmaster是可以自定義集群的名字
port 26379
dir /tmp
sentinel monitor kingmaster 192.168.001.220 6379 2
sentinel down-after-milliseconds kingmaster 30000
sentinel parallel-syncs kingmaster 1
sentinel auth-pass kingmaster redispwd
sentinel failover-timeout kingmaster 180000
sentinel deny-scripts-reconfig yes
將此文件復(fù)制到指定位置3份并重命名
cp sentinel.conf /home/sentinelredis/sentinel/sentinel1.conf
cp sentinel.conf /home/sentinelredis/sentinel/sentinel2.conf
cp sentinel.conf /home/sentinelredis/sentinel/sentinel3.conf
6.創(chuàng)建哨兵docker-compose文件
version: '3.7'
services:
sentinel1:
image: redis
container_name: redis-sentinel-1
restart: always
ports:
- 26379:26379
command: redis-sentinel /home/sentinelredis/redisconf/sentinel.conf
volumes:
- ./sentinel1.conf:/home/sentinelredis/redisconf/sentinel.conf
sentinel2:
image: redis
container_name: redis-sentinel-2
restart: always
ports:
- 26380:26379
command: redis-sentinel /home/sentinelredis/redisconf/sentinel.conf
volumes:
- ./sentinel2.conf:/home/sentinelredis/redisconf/sentinel.conf
sentinel3:
image: redis
container_name: redis-sentinel-3
ports:
- 26381:26379
command: redis-sentinel /home/sentinelredis/redisconf/sentinel.conf
volumes:
- ./sentinel3.conf:/home/sentinelredis/redisconf/sentinel.conf
networks:
default:
external:
name: masterslave_default
這里要注意 networks:default:external:name: masterslave_default,這個是要查看自己redis的主節(jié)點信息散址,把Networks復(fù)制過來,命令:docker inspect d6a81ae3106e
7.進入對應(yīng)目錄乖阵,啟動哨兵:
8.查看啟動容器:
最終目錄圖示:
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者