Redis搭建主从:
1:拉取Redis镜像
docker pull redis
2:创建主从对应的目录结构
3:对redis6379.log,redis6380.log,redis6381.log进行授权
chmod 777 redis6379.log
chmod 777 redis6380.log
chmod 777 redis6381.log
4:修改主(master)的配置文件
5:创建主(master) redis_6379
docker run -it \
--name redis_6379 \
--privileged \
-p 6379:6379 \
--network wn_docker_net \
--ip 172.18.12.10 \
--sysctl net.core.somaxconn=1024 \
-e TIME_ZONE="Asia/Shanghai" -e TZ="Asia/Shanghai" \
-v /usr/local/software/redis/6379/conf/redis6379.conf:/usr/local/etc/redis/redis.conf \
-v /usr/local/software/redis/6379/data/:/data \
-v /usr/local/software/redis/6379/log/redis6379.log:/var/log/redis.log \
-d redis \
/usr/local/etc/redis/redis.conf
6:进入 主 (master)redis_6379;并测试
docker exec -it redis_6379 bash
redis-cli
info replication
docker exec -it redis_6379 bash
redis-cli
set food bread
7:用redis桌面工具连接redis_6379;并获取上一步所存的键值
8:修改从(slave)的配置文件
9:创建从(slave) redis_6380
docker run -it \
--name redis_6380 \
--privileged \
-p 6380:6379 \
--network wn_docker_net \
--ip 172.18.12.11 \
--sysctl net.core.somaxconn=1024 \
-e TIME_ZONE="Asia/Shanghai" -e TZ="Asia/Shanghai" \
-v /usr/local/software/redis/6380/conf/redis6380.conf:/usr/local/etc/redis/redis.conf \
-v /usr/local/software/redis/6380/data/:/data \
-v /usr/local/software/redis/6380/log/redis6380.log:/var/log/redis.log \
-d redis \
/usr/local/etc/redis/redis.conf
10:进入 主从(slave)redis_6380;并测试
docker exec -it redis_6380 bash
redis-cli
info replication
11:用redis桌面工具连接redis_6380;并获取在主(master)中所存的键值
12:创建从(slave) redis_6381
按照创建 redis_6380 的步骤创建即可.
docker run -it \
--name redis_6381 \
--privileged \
-p 6381:6379 \
--network wn_docker_net \
--ip 172.18.12.12 \
--sysctl net.core.somaxconn=1024 \
-e TIME_ZONE="Asia/Shanghai" -e TZ="Asia/Shanghai" \
-v /usr/local/software/redis/6381/conf/redis6381.conf:/usr/local/etc/redis/redis.conf \
-v /usr/local/software/redis/6381/data/:/data \
-v /usr/local/software/redis/6381/log/redis6381.log:/var/log/redis.log \
-d redis \
/usr/local/etc/redis/redis.conf
13:开放端口的步骤
-
firewall-cmd --add-port=3312/tcp --permanent
-
firewall-cmd --reload
-
firewall-cmd --list-ports