关于docker:docker-搭建redis主从复制

2次阅读

共计 1579 个字符,预计需要花费 4 分钟才能阅读完成。

首先从 dockerhub 上搜寻 redis
而后行将 docker pull 到本地 docker pull redis,待同步完镜像后。
咱们须要对容器进行端口映射,以及文件映射,让 redis 读取本地的 redis.conf 文件。redis.conf 问价能够去 redis 官网下载一份 redis,而后提取。咱们 批改好 redis.conf 文件,并放到咱们映射的门路下,待容器启动就会加载。master 节点批改 bind,这个参数是用来绑定能够拜访该 redis 的 ip 地址。
slave 节点也是批改这个,而后还要批改 replicaof masterip port 参数,masterip 就是 master 节点的 IP,port 是他的端口。
而后就是运行 docker 镜像啦。
docker run -v ~/workspace/redis/master/config/redis.conf:/usr/local/etc/redis/redis.conf -v ~/workspace/redis/master:/data -p 6379:6379 --name master redis redis-server /usr/local/etc/redis/redis.conf 参数 - v 是将后面的宿主机的地址映射到容器中的门路。-p 是将主机端口映射到容器端口。
而后咱们批改容器映射到主机的端口。也就是 -p。–name 是容器的名字。
咱们启动容器。

这是咱们的 master 节点。同样的,咱们批改启动容器的命令,启动另外两个 redis 节点。批改配置文件 redis.conf 和 –name , 以及端口映射。
这样就好了。
然而我在搭建的时候遇到了如下的问题:

1:S 30 Oct 2020 00:24:28.379 * MASTER <-> REPLICA sync started
1:S 30 Oct 2020 00:24:28.380 * Non blocking connect for SYNC fired the event.
1:S 30 Oct 2020 00:24:28.380 * Master replied to PING, replication can continue...
1:S 30 Oct 2020 00:24:28.380 * Partial resynchronization not possible (no cached master)
1:S 30 Oct 2020 00:24:28.380 * Master is currently unable to PSYNC but should be in the future: -NOMASTERLINK Can't SYNC while not connected with my master

输出 docker inspect master,查看容器的信息;

"Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "d146143ce326a6d873f44293e255e1b77453747373ce9a11af450e74757bcce4",
                    "EndpointID": "46962fab58f136d8005a4c1e0773e24e0a2618a887f3248da4815a8f4722238e",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "","GlobalIPv6Address":"",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }

能够看到 master 的 ip 地址为 172.17.0.2,我之前相当然的是本机地址(localhost), 去批改配置。

这下就胜利了。

正文完
 0