docker pull redis
cd /home/soft
mkdir -p redis/config
mkdir -p redis/data/data6379 redis/data/data6380 redis/data/data6381
cd /home/soft/redis/config
vi redis6379.conf :
port 6379
vi redis6380.conf :
#节点容器端口
port 6380
#宿主机ip、master端口
replicaof 192.168.10.15 6379
#宿主机ip
slave-announce-ip 192.168.10.15
#节点宿主机端口
slave-announce-port 6380
vi redis6381.conf :
port 6381
replicaof 192.168.10.15 6379
slave-announce-ip 192.168.10.15
slave-announce-port 6381
docker run \
-p 6379:6379 \
--name master-redis \
--restart=always \
-v /home/soft/redis/data/data6379:/data \
-v /home/soft/redis/config/redis6379.conf:/etc/redis/redis.conf \
-v /etc/localtime:/etc/localtime \
-d redis redis-server /etc/redis/redis.conf
docker run \
-p 6380:6380 \
--name salve1-redis \
--restart=always \
-v /home/soft/redis/data/data6380:/data \
-v /home/soft/redis/config/redis6380.conf:/etc/redis/redis.conf \
-v /etc/localtime:/etc/localtime \
-d redis redis-server /etc/redis/redis.conf
docker run \
-p 6381:6381 \
--name salve2-redis \
--restart=always \
-v /home/soft/redis/data/data6381:/data \
-v /home/soft/redis/config/redis6381.conf:/etc/redis/redis.conf \
-v /etc/localtime:/etc/localtime \
-d redis redis-server /etc/redis/redis.conf
验证:
[root@localhost config]# docker exec -it master-redis redis-cli -p 6379
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.75.10,port=6380,state=online,offset=98,lag=1
slave1:ip=192.168.75.10,port=6381,state=online,offset=98,lag=1
master_failover_state:no-failover
master_replid:f562378b948c944b4cb6e10307cf5c5b12f349ce
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:98
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:98
127.0.0.1:6379> PING
PONG
标签:soft,redis,etc,conf,home,docker,data,主从 From: https://www.cnblogs.com/sinsenliu/p/17528575.html