做网站如何购买服务器,网站怎么做熊掌号,怎么做网站内容添加,手机logo在线制作 免费目录
简介
1 概述
1.1 术语
1.2 组件
1.2.1 repmgr
1.2.2 repmgrd
1.3 Repmgr用户与元数据
2 安装部署
2.0 部署环境
2.1 安装要求
2.1.1 操作系统
2.1.2 PostgreSQL 版本
2.1.3 操作系统用户
2.1.4 安装位置
2.1.5 版本要求
2.2 安装
2.2.1 软件包安装
2.2…目录
简介
1 概述
1.1 术语
1.2 组件
1.2.1 repmgr
1.2.2 repmgrd
1.3 Repmgr用户与元数据
2 安装部署
2.0 部署环境
2.1 安装要求
2.1.1 操作系统
2.1.2 PostgreSQL 版本
2.1.3 操作系统用户
2.1.4 安装位置
2.1.5 版本要求
2.2 安装
2.2.1 软件包安装
2.2.2 源码编译安装
3 快速开始
3.2 PostgreSQL部署主库
3.3 创建用户与数据库
3.4 配置认证文件 pg_hba.conf
3.5 设置免密登录
3.6 repmgr配置文件
3.7 注册主节点
3.8 克隆 standby Server
3.9 验证主从同步正常
3.10 注册从节点
参考
repmgr官网
5.3.3版本文档
最新文档5.4版本
github repmgr 简介
repmgr是一套开源工具用于管理 PostgreSQL 服务器集群内的复制和故障转移。它通过设置备用服务器、监控复制以及执行故障转移或切换操作等管理任务的实用程序增强了 PostgreSQL 的内置复制功能。
1 概述
1.1 术语
整个repmgr文档 中使用了以下术语 replication cluster在repmgr文档中“replication cluster”是指通过流式复制连接的 PostgreSQL 服务器网络。node 节点是复制集群中的单个 PostgreSQL 服务器。upstream node备用服务器连接到的节点以便接收流式复制。这可以是主服务器或者在级联复制的情况下是另一台备用服务器。failover这是在主服务器发生故障并且合适的备用服务器升级为新的主服务器时发生的操作。repmgrd守护程序支持自动故障转移以最大限度地减少停机时间 。switchover在某些情况下例如硬件或操作系统维护有必要使主服务器离线在这种情况下需要进行受控切换从而提升合适的备用数据库并以受控方式从复制集群中删除现有的主数据库。repmgr命令行客户端提供此功能 。fencing在故障转移情况下在升级新的备用数据库后之前的主数据库不会意外地重新上线否则会导致脑裂情况。为了防止这种情况发生发生故障的主数据库应与应用程序隔离即“隔离”。witness serverepmgr提供了设置所谓“witness server”的功能以帮助在具有多个备用服务器的故障转移情况下确定新的主服务器。witness server本身不是复制集群的一部分尽管它包含 repmgr 元数据架构的副本。 1.2 组件 repmgr是一套开源工具用于管理 PostgreSQL 服务器集群内的复制和故障转移。它支持并增强 PostgreSQL 的内置流复制该复制提供单个读/写主服务器和一个或多个包含主服务器数据库的近实时副本的只读备用服务器。它提供了两个主要工具 1.2.1 repmgr 用于执行管理任务的命令行工具例如 设置备用服务器将备用服务器升级为主服务器主备服务器切换显示复制集群中服务器的状态 1.2.2 repmgrd 主动监视复制集群中的服务器并执行以下任务的守护程序 监控和记录复制性能通过检测主服务器的故障并升级最合适的备用服务器来执行故障转移向用户定义的脚本提供有关集群中事件的通知该脚本可以执行通过电子邮件发送警报等任务 1.3 Repmgr用户与元数据 为了有效地管理复制集群repmgr需要将集群中服务器的信息存储在专用的数据库schema中。此架构由repmgr扩展自动创建该扩展在初始化repmgr管理的集群 ( repmgr primary register)的第一步中安装并包含以下对象 table repmgr.events记录关注的事件repmgr.nodes复制集群中每个服务器的连接和状态信息repmgr.monitoring_history repmgrd写入的历史备用监控信息 view repmgr.show_nodes基于 table repmgr.nodes另外显示服务器上游节点的名称repmgr.replication_status当启用repmgrd的监控时显示每个备用数据库的当前监控状态。 repmgr元数据模式可以存储在现有数据库或其自己的专用数据库中。请注意repmgr 元数据模式不能保存在不属于repmgr管理的复制集群的数据库服务器上。 数据库用户必须可供repmgr访问该数据库并修改的权限。该用户不需要是超级用户但是某些操作例如repmgr扩展的初始安装将需要超级用户连接可以在需要时使用命令行选项指定 --superuser。 2 安装部署 2.0 部署环境 PostgreSQL:13.12 repmgr 5.3.3 CentOS Linux release 7.2.1511 (Core) repmgr可以从操作系统的打包系统提供的二进制包或源代码安装。一般来说我们建议使用二进制包除非您的操作系统不可用。 2.1 安装要求 2.1.1 操作系统 repmgr 是在 Linux 和 OS X 上开发和测试的但应该可以在 PostgreSQL 本身支持的任何类 UNIX 系统上运行。不支持 Microsoft Windows。 2.1.2 PostgreSQL 版本 复制集群中的所有服务器必须运行相同的 PostgreSQL 主要版本我们建议它们也运行相同的次要版本。 2.1.3 操作系统用户 不需要repmgr的 专用系统用户由于许多repmgr和 repmgrd操作需要直接访问 PostgreSQL 数据目录因此这些命令应由postgres用户执行。 2.1.4 安装位置 repmgr必须安装在复制集群中的每台服务器上。如果从软件包安装 repmgr软件包版本必须与 PostgreSQL 版本匹配。如果从源代码安装repmgr必须针对相同的主要版本进行编译。 2.1.5 版本要求 下表概述了repmgr版本支持的 PostgreSQL 版本。 版本兼容矩阵 repmgr 版本 Supported? 是否维护 Latest release 最新版本 Supported PostgreSQL versions 支持的PostgreSQL版本 Notes 注意 repmgr 5.4(dev)5.4.1 (2023-07-04)9.4, 9.5, 9.6, 10, 11, 12, 13, 15repmgr 5.3YES5.4.1 (2023-07-04)9.4, 9.5, 9.6, 10, 11, 12, 13, 14, 15PostgreSQL 15 supported from repmgr 5.3.3repmgr 5.2NO5.2.1 (2020-12-07)9.4, 9.5, 9.6, 10, 11, 12, 13repmgr 5.1NO5.1.0 (2020-04-13)9.3, 9.4, 9.5, 9.6, 10, 11, 12repmgr 5.0NO5.0 (2019-10-15)9.3, 9.4, 9.5, 9.6, 10, 11, 12repmgr 4.xNO4.4 (2019-06-27)9.3, 9.4, 9.5, 9.6, 10, 11repmgr 3.xNO3.3.2 (2017-05-30)9.3, 9.4, 9.5, 9.6repmgr 2.xNO2.0.3 (2015-04-16)9.0, 9.1, 9.2, 9.3, 9.4 2.2 安装 2.2.1 软件包安装 这个命令的含义是下载一个文件然后执行 这个需要外网 ,生产数据库服务器一般没有外网 curl https://dl.enterprisedb.com/default/release/get/13/rpm | sudo bash
yum list repmgr13yum install repmgr13 -y 2.2.2 源码编译安装 如果服务器没有外网 只能使用源码安装 下载源码的地址 下面两个地址都可以 一个是官网上的下载地址一个是gtihub的下载地址 wget https://github.com/EnterpriseDB/repmgr/archive/refs/tags/v5.3.3.tar.gz // 我使用的这个 wget https://www.repmgr.org/download/repmgr-5.3.3.tar.gz 安装依赖 yum check-update
yum groupinstall Development Tools -y
yum install -y yum-utils openjade docbook-dtds docbook-style-dsssl docbook-style-xsl
yum-builddep postgresql96// 执行不了 没有postgresql96yum源用以下命令替代
yum install -y cmake make gcc zlib gcc-c perl readline readline-devel zlib // 自己安装pg13安装的依赖yum -y install yum-builddep flex libselinux-devel libxml2-devel libxslt-devel openssl-devel pam-devel readline-devel // 博客上的 下载源码包 wget https://www.repmgr.org/download/repmgr-5.3.3.tar.gz 解压安装repmgr主备库都安装 tar -zxvf repmgr-5.3.3.tar.gz 使用postgres用户安装 chown -R postgres:postgres /home/packet/repmgr-5.3.3 su - postgres cd /home/packet/repmgr-5.3.3 ./configure make install 输出一下内容说明二进制命令安装到了目录/usr/local/pgsql/bin/下 /bin/install -c -m 755 repmgr repmgrd /usr/local/pgsql/bin/ 进入到目录中查看/usr/local/pgsql/bin/ 多了以下两个命令 可以通过repmgr --help 验证安装是否成功 3 快速开始 3.2 PostgreSQL部署主库 参考我的博客只部署主库即可 【PG】PostgreSQL13主从流复制部署(详细可用)-CSDN博客 3.3 创建用户与数据库 // 创建用户 需要超级用户权限
create user repmgr with superuser password repmgr connection limit 10;// 创建元数据库create database repmgr owner repmgr;// repmgr会创建repmgr schema 来报错repmgr的元数据表函数视图等建议设置用户repmgr的搜索路径如下
ALTER USER repmgr SET search_path TO repmgr, $user, public; 3.4 配置认证文件 pg_hba.conf # 允许用户 repmgr 通过local127.0.0.110.79.21.网段连接到replication
local replication repmgr trust
host replication repmgr 127.0.0.1/32 trust
host replication repmgr 10.79.21.0/24 trust# 允许用户 repmgr 通过local127.0.0.110.79.21. 连接到repmgr schema
local repmgr repmgr trust
host repmgr repmgr 127.0.0.1/32 trust
host repmgr repmgr 10.79.21.0/24 trust 3.5 设置免密登录 如果之前postgres 没有密码 需要先设置一个密码 否则下面ssh拷贝公钥时会提示输入密码 使用postgres用户 在两台服务器上在node1上
ssh-keygen -t rsa
ssh-copy-id postgres10.79.21.29
ssh postgres10.79.21.29 date在node2上
ssh-keygen -t rsa
ssh-copy-id postgres10.79.21.30
ssh postgres10.79.21.30 date// 数据库免密登录 IP:port:schema?:user:passwd
vim .pgpass
10.79.21.30:5432:repmgr:repmgr:repmgr
10.79.21.29:5432:repmgr:repmgr:repmgr修改权限只允许postgres用户读写
chmod 600 .pgpass3.6 repmgr配置文件 repmgr.conf不应存储在 PostgreSQL 数据目录中因为在设置或重新初始化 PostgreSQL 服务器时它可能会被覆盖 vim repmgr.conf node_id1
node_namenode1
conninfohost10.79.21.30 port5432 userrepmgr dbnamerepmgr connect_timeout2
data_directory/home/storage/pgsql/data 3.7 注册主节点 要使repmgr支持复制集群主节点必须向repmgr注册。这将安装repmgr 扩展和元数据对象并为主服务器添加元数据记录 repmgr -f /etc/repmgr.conf primary register $repmgr -f /etc/repmgr.conf primary register
INFO: connecting to primary database...
NOTICE: attempting to install extension repmgr
NOTICE: repmgr extension successfully installed
NOTICE: primary node record (ID: 1) registered 验证集群的状态如下所示 repmgr -f /etc/repmgr.conf cluster show $repmgr -f /etc/repmgr.conf cluster showID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
-----------------------------------------------------------------------------------------------------------------------------------------------1 | node1 | primary | * running | | default | 100 | 1 | host10.79.21.30 port5432 userrepmgr dbnamerepmgr connect_timeout2 元数据表中的记录 repmgr# select * from nodes;
-[ RECORD 1 ]---------------------------------------------------------------------------
node_id | 1
upstream_node_id |
active | t
node_name | node1
type | primary
location | default
priority | 100
conninfo | host10.79.21.30 port5432 userrepmgr dbnamerepmgr connect_timeout2
repluser | repmgr
slot_name |
config_file | /etc/repmgr.conf 3.8 克隆 standby Server 在从节点上编辑配置文件
vim repmgr.conf node_id2
node_namenode2
conninfohost10.79.21.29 port5432 userrepmgr dbnamerepmgr connect_timeout2
data_directory/home/storage/pgsql/data 使用参数--dry-run 检查是否可以克隆从库 repmgr -h 10.79.21.30 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone --dry-run 检查目录检查参数 max_wal_senders 是否大于2 检查参数 wal_log_hints检查通过会执行备份命令 pg_basebackup -l repmgr base backup -D /home/storage/pgsql/data -h 10.79.21.30 -p 5432 -U repmgr -X stream $repmgr -h 10.79.21.30 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone --dry-run
NOTICE: destination directory /home/storage/pgsql/data provided
INFO: connecting to source node
DETAIL: connection string is: host10.79.21.30 userrepmgr dbnamerepmgr
DETAIL: current installation size is 116 MB
INFO: repmgr extension is installed in database repmgr
INFO: replication slot usage not requested; no replication slot will be set up for this standby
INFO: parameter max_wal_senders set to 10
NOTICE: checking for available walsenders on the source node (2 required)
INFO: sufficient walsenders available on the source node
DETAIL: 2 required, 10 available
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: required number of replication connections could be made to the source server
DETAIL: 2 replication connections required
WARNING: data checksums are not enabled and wal_log_hints is off
DETAIL: pg_rewind requires wal_log_hints to be enabled
NOTICE: standby will attach to upstream node 1
HINT: consider using the -c/--fast-checkpoint option
INFO: would execute:pg_basebackup -l repmgr base backup -D /home/storage/pgsql/data -h 10.79.21.30 -p 5432 -U repmgr -X stream
INFO: all prerequisites for standby clone are met 可以看到个warning ,将参数 wal_log_hints 设置为 on ,再次检查 如果检查没有问题 就可以进行克隆 repmgr -h 10.79.21.30 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone$repmgr -h 10.79.21.30 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone
NOTICE: destination directory /home/storage/pgsql/data provided
INFO: connecting to source node
DETAIL: connection string is: host10.79.21.30 userrepmgr dbnamerepmgr
DETAIL: current installation size is 116 MB
INFO: replication slot usage not requested; no replication slot will be set up for this standby
NOTICE: checking for available walsenders on the source node (2 required)
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: checking and correcting permissions on existing directory /home/storage/pgsql/data
NOTICE: starting backup (using pg_basebackup)...
HINT: this may take some time; consider using the -c/--fast-checkpoint option
INFO: executing:pg_basebackup -l repmgr base backup -D /home/storage/pgsql/data -h 10.79.21.30 -p 5432 -U repmgr -X stream
NOTICE: standby clone (using pg_basebackup) complete
NOTICE: you can now start your PostgreSQL server
HINT: for example: pg_ctl -D /home/storage/pgsql/data start
HINT: after starting the server, you need to register this standby with repmgr standby register 3.9 验证主从同步正常 在主库上查看 SELECT * FROM pg_stat_replication; 可以看到 standy 上查看 SELECT * FROM pg_stat_wal_receiver; 3.10 注册从节点 使用以下命令注册从节点 repmgr -f /etc/repmgr.conf standby register$repmgr -f /etc/repmgr.conf standby register
INFO: connecting to local node node2 (ID: 2)
INFO: connecting to primary database
WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID: 1)
INFO: standby registration complete
NOTICE: standby node node2 (ID: 2) successfully registered 验证注册成功repmgr -f /etc/repmgr.conf cluster show $repmgr -f /etc/repmgr.conf cluster showID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
-----------------------------------------------------------------------------------------------------------------------------------------------1 | node1 | primary | * running | | default | 100 | 1 | host10.79.21.30 port5432 userrepmgr dbnamerepmgr connect_timeout22 | node2 | standby | running | node1 | default | 100 | 1 | host10.79.21.29 port5432 userrepmgr dbnamerepmgr connect_timeout2 参考 repmgr官网
repmgr - Replication Manager for PostgreSQL clusters
5.3.3版本文档
https://www.repmgr.org/docs/5.3/index.html
最新文档5.4版本
repmrg文档
github repmgr
GitHub - EnterpriseDB/repmgr: A lightweight replication manager for PostgreSQL (Postgres) 参考
进阶数据库系列十八PostgreSQL 基于 repmgr 高可用架构实践_mingongge的博客-CSDN博客
PostgreSQLrepmgr高可用部署 - 墨天轮