- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章docker compose部署主从复制的实现由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
受限于 Redis 单点性能,加上我们对数据天生就有的备份的需求,因此 Redis 提供了主从复制的服务.
本文记录了通过 docker compose 搭建一主双从的 Redis 服务.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
################################# REPLICATION #################################
# 【Slave】连接 Master 的配置
# slaveof 172.25.0.101 6379
# 【Slave】只读模式
# slave-read-only yes
# 【Slave】密码
# masterauth <master-password>
# 【Slave】复制期间是否允许响应查询,可能会返回脏数据
# slave-serve-stale-data yes
# 【Slave】Slave 晋级为 Master 的优先级,仅哨兵模式下生效
# slave-priority 100
# 【Slave】Slave 向 Master 报告的自己的 IP
# slave-announce-ip 5.5.5.5
# 【Slave】Slave 向 Master 报告的自己的端口
# slave-announce-port 1234
# 【Slave】Slave ping Master 的时间间隔
# repl-ping-slave-period 10
# 【Master/Slave】超时时间
# repl-timeout 60
# 【Master】Diskless 就是直接将要复制的 RDB 文件写入到 Socket 中,而不会先存储到磁盘上
repl-diskless-sync no
# 【Master】若开启 Diskless,会等待指定秒之后再进行复制,以便让更多客户端可以在窗口期内连接,并行传送
# repl-diskless-sync-delay 5
# 【Master】是否开启 Nagle 算法,可以减少流量占用,但会同步得慢些
repl-disable-tcp-nodelay no
# 【Master】环形缓冲日志的大小,给 Slave 断开之后重连使用,避免全量复制,默认 1mb
# repl-backlog-size 1mb
# 【Master】当 Master 断连所有 Slave 指定时间后,Master 会清空 backlog
# repl-backlog-ttl 3600
# 【Master】当低于指定个 Slave 连接时,Master 拒绝所有写操作
# min-slaves-to-write 3
# 【Master】当延迟高于指定秒数时,Master 拒绝所有写操作
# min-slaves-max-lag 10
|
1
2
3
4
5
6
7
8
9
10
11
|
replication/
├── docker-compose.yml
├── master
│ ├── data
│ └── redis.conf
├── slave1
│ ├── data
│ └── redis.conf
└── slave2
├── data
└── redis.conf
|
定义了一个子网,方便操作,对外暴露 6371(Master)、6372、6373 端口.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
version: "3"
networks:
redis-replication:
driver: bridge
ipam:
config:
- subnet: 172.25.0.0/24
services:
master:
image: redis
container_name: redis-master
ports:
- "6371:6379"
volumes:
- "./master/redis.conf:/etc/redis.conf"
- "./master/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.101
slave1:
image: redis
container_name: redis-slave-1
ports:
- "6372:6379"
volumes:
- "./slave1/redis.conf:/etc/redis.conf"
- "./slave1/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.102
slave2:
image: redis
container_name: redis-slave-2
ports:
- "6373:6379"
volumes:
- "./slave2/redis.conf:/etc/redis.conf"
- "./slave2/data:/data"
command: ["redis-server", "/etc/redis.conf"]
restart: always
networks:
redis-replication:
ipv4_address: 172.25.0.103
|
Master:
基本不用配置,最简单的是指定一个端口就好了.
1
2
3
4
5
|
port 6379
protected-mode no
repl-diskless-sync no
repl-disable-tcp-nodelay no
|
Slave:
实例的配置保持一致就可以了,因为定义了子网,不存在端口冲突.
1
2
3
4
5
6
|
port 6379
protected-mode no
slaveof 172.25.0.101 6379
slave-read-only yes
slave-serve-stale-data yes
|
1
2
3
4
5
|
ocker-compose up -d
Creating network "replication_redis-replication" with driver "bridge"
Creating redis-slave-1 ... done
Creating redis-master ... done
Creating redis-slave-2 ... done
|
查看 Master 日志,可以看到接受了两个 Slave 的复制请求:
1:M 18 Aug 2021 15:50:31.772 * Replica 172.25.0.102:6379 asks for synchronization 1:M 18 Aug 2021 15:50:31.772 * Full resync requested by replica 172.25.0.102:6379 1:M 18 Aug 2021 15:50:31.772 * Replication backlog created, my new replication IDs are '5d27746f14ee9be9694d794f96de6ba14a669dd1' and '0000000000000000000000000000000000000000' 1:M 18 Aug 2021 15:50:31.772 * Starting BGSAVE for SYNC with target: disk 1:M 18 Aug 2021 15:50:31.773 * Background saving started by pid 19 19:C 18 Aug 2021 15:50:31.777 * DB saved on disk 19:C 18 Aug 2021 15:50:31.777 * RDB: 0 MB of memory used by copy-on-write 1:M 18 Aug 2021 15:50:31.822 * Background saving terminated with success 1:M 18 Aug 2021 15:50:31.823 * Synchronization with replica 172.25.0.102:6379 succeeded 1:M 18 Aug 2021 15:50:32.170 * Replica 172.25.0.103:6379 asks for synchronization 1:M 18 Aug 2021 15:50:32.170 * Full resync requested by replica 172.25.0.103:6379 1:M 18 Aug 2021 15:50:32.170 * Starting BGSAVE for SYNC with target: disk 1:M 18 Aug 2021 15:50:32.171 * Background saving started by pid 20 20:C 18 Aug 2021 15:50:32.175 * DB saved on disk 20:C 18 Aug 2021 15:50:32.175 * RDB: 0 MB of memory used by copy-on-write 1:M 18 Aug 2021 15:50:32.225 * Background saving terminated with success 1:M 18 Aug 2021 15:50:32.226 * Synchronization with replica 172.25.0.103:6379 succeeded 。
查看 Slave 日志,可以看到连接建立的全过程:
1:S 18 Aug 2021 15:50:31.771 * Connecting to MASTER 172.25.0.101:6379 1:S 18 Aug 2021 15:50:31.771 * MASTER <-> REPLICA sync started 1:S 18 Aug 2021 15:50:31.771 * Non blocking connect for SYNC fired the event. 1:S 18 Aug 2021 15:50:31.771 * Master replied to PING, replication can continue... 1:S 18 Aug 2021 15:50:31.772 * Partial resynchronization not possible (no cached master) 1:S 18 Aug 2021 15:50:31.773 * Full resync from master: 5d27746f14ee9be9694d794f96de6ba14a669dd1:0 1:S 18 Aug 2021 15:50:31.823 * MASTER <-> REPLICA sync: receiving 175 bytes from master to disk 1:S 18 Aug 2021 15:50:31.823 * MASTER <-> REPLICA sync: Flushing old data 1:S 18 Aug 2021 15:50:31.823 * MASTER <-> REPLICA sync: Loading DB in memory 1:S 18 Aug 2021 15:50:31.828 * Loading RDB produced by version 6.2.5 1:S 18 Aug 2021 15:50:31.828 * RDB age 0 seconds 1:S 18 Aug 2021 15:50:31.828 * RDB memory usage when created 1.83 Mb 1:S 18 Aug 2021 15:50:31.829 * MASTER <-> REPLICA sync: Finished with success 。
登录 Master,尝试写入新 Key.
1
2
|
127.0.0.1:6371>
set
hello world
OK
|
登录 Slave,查看能否读取到:
1
2
|
127.0.0.1:6372> get hello
"world"
|
Slave 尝试写操作:
1
2
|
127.0.0.1:6372>
set
hello redis
(error) READONLY You can't write against a
read
only
replica.
|
到此这篇关于docker compose部署主从复制的实现的文章就介绍到这了,更多相关docker compose 主从复制内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://juejin.cn/post/6997804248457019399 。
最后此篇关于docker compose部署主从复制的实现的文章就讲到这里了,如果你想了解更多关于docker compose部署主从复制的实现的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我在 *.sql 文件中得到了我的数据库转储(表、函数、触发器等)。此时我正在通过 jenkins 部署它们,通过传递执行 shell 命令: sudo -u postgres psql -d my_
我正在使用网络部署 API 来部署网络包(.zip 文件,由 MSDeploy.exe 创建)以编程方式将包发布到服务器(在发布包之前我们需要做一些其他事情这就是为什么我们不使用 MSDeploy.e
我们正在使用 Web Deploy 3 的(几乎完全未记录的)“公共(public) API”来创建我们网站的 .zip 包,然后将其同步到服务器: DeploymentBaseOptions des
将 clojure 应用程序制作成可执行文件的最简单方法是什么,例如 http://rawr.rubyforge.org/ ruby 吗? (exe 和 app 文件也是) 最佳答案 使用 leini
是否可以下载 Android 源代码并针对任何设备进行编译? 我想做的是尝试 GSM 代码部分并编译操作系统并将其部署到我的摩托罗拉手机上。 谢谢! 最佳答案 是的,但这很难,因为大多数手机不共享驱动
我正在考虑用 c/c++ 编写需要在大多数个人计算机上运行的 nbody 样式模拟。本质上是一个 O(n^2) 粒子模拟器。 因为这需要相当用户友好,所以我希望有 1 个不需要用户安装任何东西的 Wi
需要了解 kubernetes 部署中 kube_deployment_status_replicas 和 kube_deployment_spec_replicas 指标的区别 最佳答案 简而言之,
我正在尝试使用分类器部署 Maven Artifact 。由于我需要源代码和 JAR(我从 GWT 使用它),我想获得 artifact-version-classifier.jar 和 artifa
我设置部署以将我的项目代码与存储我的网站的 FTP 服务器上的项目同步。 但是,每次尝试同步时,我总是必须登录。 我什至检查了记住,但它不起作用! 我正在使用最新的 PhpStorm 2017.1.4
我在 Visual Studio 2008 中开发了一个 ASP.NET 网站。现在我想在其他机器上部署它。我怎样才能做到这一点??就像我们为 Windows 应用程序制作安装包一样,我们可以为 AS
将 QT 框架添加到我的 .app 包中 我正在关注 Qt 站点上关于部署的文档。 我创建了一个名为 HTTPClient.app 的应用程序 我在 Contents 下创建了 Framework 文
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the h
我正在研究改变我目前创建营销网站的策略。目前,我完全用 PHP 从头开始构建网站,使用一个简单的包含系统。所有代码(以及内容)都存储在文件(而不是数据库)中,允许我使用 Subversion 进行
我有一个长期运行的服务(在 while 1 循环中)并通过 GCloud pub/sub 处理有效负载,之后它将结果写入数据库。 该服务不需要监听任何端口。 Kind=Deployment 的声明性
似乎部署已停滞不前。我该如何进一步诊断? kubectl rollout status deployment/wordpress Waiting for rollout to finish: 2 ou
我正在Dart中使用前端的Angular和后端的Shelf构建一个客户端/服务器应用程序。当我执行pub build时,它会按预期生成Dart文件的javascript,但不会替换HTML文件中的Da
我在 Azure 部署中心的下拉列表中看不到我的所有 Github 组织存储库。 Azure 很久以前就已经被授权了,下拉列表正确地显示了所有的存储库,直到上周我在 DevOps 中玩游戏时,不得不再
我认为标题几乎说明了一切...对于 Deployd 来说是全新的,所以任何关于如何最好地实现这一点的指示都值得赞赏。 最佳答案 要获取用户创建的集合中的对象(我假设您使用的是 javascript 库
我有一个试图用于CD服务器的部署脚本,但是在编写bash脚本以完成一些所需的步骤(例如运行npm和迁移命令)时遇到了问题。 我将如何从该脚本进入容器bash,运行下面的命令,然后退出以完成对更改的提取
我想在使用 kubectl 时将参数传递给 Kubernetes 部署命令应用部署文件。 示例:在我的部署 .yaml 中,我有如下参数,我想在使用 kubectl apply - f .yaml 运
我是一名优秀的程序员,十分优秀!