一、前言
本文将基于以下环境部署redis主从复制模式
- CentOS Linux release 7.6.1810 (Core)
- Docker version 20.10.5, build 55c4c88
- docker-compose version 1.28.6, build 5db8d86f
二、docker-compose 部署redis主从复制 模式
可参考 https://gitee.com/zhengqingya/docker-compose
git clone https://gitee.com/zhengqingya/docker-compose.git
cd docker-compose/Liunx
chmod -R 777 ./redis-master-slave
docker-compose -f docker-compose-redis-master-slave.yml -p redis up -d
下面贴出相关配置文件
docker-compose-redis-master-slave.yml
version: '3'
networks:
redis:
services:
master:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8
container_name: redis-master
restart: unless-stopped
command: redis-server /etc/redis/redis.conf --requirepass 123456 --appendonly no
environment:
TZ: Asia/Shanghai
LANG: en_US.UTF-8
volumes:
- "./redis-master-slave/master/data:/data"
- "./redis-master-slave/master/config/redis.conf:/etc/redis/redis.conf"
ports:
- "6380:6379"
networks:
- redis
slave:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8
container_name: redis-slave
restart: unless-stopped
command: redis-server /etc/redis/redis.conf --requirepass 123456 --appendonly no --slaveof www.zhengqingya.com 6380 --masterauth 123456
environment:
TZ: Asia/Shanghai
LANG: en_US.UTF-8
volumes:
- "./redis-master-slave/slave/data:/data"
- "./redis-master-slave/slave/config/redis.conf:/etc/redis/redis.conf"
ports:
- "6381:6379"
networks:
- redis
redis.conf
内容可参考 http://download.redis.io/redis-stable/redis.conf
三、测试主写从读
master中写入数据,slave中查看
查看实例状态info replication
今日分享语句: 把艰辛的劳作看作是生命的必然,即使没有收获的希望也心平气和的继续。
|