标签:link online format nec data ubunt 启动 first ports
环境说明:
docker pull redis
mkdir /docker/redis
在此目录下下载服务启动配置文件
wget http://download.redis.io/redis-stable/redis.conf
下载后,进入文件修改下面3个参数(在非编辑状态下,采用 /bind 来搜索字符串位置 )
vim /docker/redis/redis.conf
# 修改下面三个配置参数 #bind 127.0.0.1 #如果bind选项为空的话,则允许所有来自于可用网络接口的连接 protected-mode no #保护模式,若为yes,只允许本地客户端连接 appendonly yes #开启后,Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件,每次启动时Redis都会先把这个文件的数据读入内存里
/docker/redis/redis6379/redis.conf
# --restart always (docker启动时,本镜像也自动启动) # --name 容器名为 redis-6379 # -p 映射本地端口 6379 至容器端口 6379 # -v 绑定Master目录 /docker/redis/redis6379 映射至 docker 中的 /data # -d 后台运行容器,并返回容器ID # 指定镜像 redis # 利用 conf 启动服务 redis-server /data/redis.conf docker run --restart always --name redis-6379 -p 6379:6379 -v /docker/redis/redis6379:/data -d redis redis-server /data/redis.conf
root@iZ282zj76jqZ:/docker/redis/redis6379# docker ps |grep redis-6379 792067d225e6 redis "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:6379->6379/tcp redis-6379
查看 Master 容器的IP,用于配置 Salve 中的参数
# 查看 Master 容器 IP,
# docker inspect redis-6379 查看 NetworkSettings 配置中 IPAdress docker inspect --format=‘{{.NetworkSettings.IPAddress}}‘ redis-6379 # 192.168.0.4
vim /docker/redis/redis.conf # 修改下面四个配置参数 #bind 127.0.0.1 #如果bind选项为空的话,则允许所有来自于可用网络接口的连接 protected-mode no #保护模式,若为yes,只允许本地客户端连接 appendonly yes #开启后,Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件,每次启动时Redis都会先把这个文件的数据读入内存里 # replicaof <master ip> <master port> replicaof 192.168.0.4 6379 #Redis主机(Master)IP 端口
启动三个 Salve 服务
docker run --restart always --name redis-6380 -p 6380:6379 -v /docker/redis/redis6380:/data -d redis redis-server /data/redis.conf docker run --restart always --name redis-6381 -p 6381:6379 -v /docker/redis/redis6381:/data -d redis redis-server /data/redis.conf docker run --restart always --name redis-6382 -p 6382:6379 -v /docker/redis/redis6382:/data -d redis redis-server /data/redis.conf
root@iZ282zj76jqZ:/docker/redis# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 43488a8c668c redis "docker-entrypoint.s…" 3 seconds ago Up 1 second 0.0.0.0:6382->6379/tcp redis-6382 ca3caaa77f4a redis "docker-entrypoint.s…" 2 hours ago Up About an hour 0.0.0.0:6381->6379/tcp redis-6381 792067d225e6 redis "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:6379->6379/tcp redis-6379 979318c633be redis "docker-entrypoint.s…" 2 hours ago Up About an hour 0.0.0.0:6380->6379/tcp redis-6380
进入 Master 容器操作 Redis
root@iZ282zj76jqZ:/docker/redis# docker exec -it redis-6379 /bin/bash root@792067d225e6:/data# redis-cli 127.0.0.1:6379> info replication # Replication role:master connected_slaves:3 slave0:ip=192.168.0.3,port=6379,state=online,offset=7129,lag=1 slave1:ip=192.168.0.6,port=6379,state=online,offset=7129,lag=0 slave2:ip=192.168.0.5,port=6379,state=online,offset=7129,lag=0 master_replid:09e8f31f23d920034b8f5e20749489ffff3fec17 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:7143 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:6892 repl_backlog_histlen:252 127.0.0.1:6379> dbsize (integer) 3
进入Salve 容器操作Redis
root@iZ282zj76jqZ:~# docker exec -it redis-6381 /bin/bash root@ca3caaa77f4a:/data# redis-cli 127.0.0.1:6379> info replication # Replication role:slave master_host:192.168.0.4 master_port:6379 master_link_status:down master_last_io_seconds_ago:-1 master_sync_in_progress:0 slave_repl_offset:6891 master_link_down_since_seconds:8 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:7d6ef858609048f3210a178772ea98ac20446c9e master_replid2:0000000000000000000000000000000000000000 master_repl_offset:6891 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1027 repl_backlog_histlen:5865 127.0.0.1:6379> dbsize (integer) 3
# -it 为容器重新分配一个伪输入终端,以交互模式运行容器 # 容器名 redis-6379 # redis-cli set Key Value docker exec -it redis-6379 redis-cli set name tomkluas
标签:link online format nec data ubunt 启动 first ports
原文地址:https://www.cnblogs.com/tomkluas/p/12682489.html