目录
文档用途
HG_REPMG配置参考
详细信息
一、系统要求
HG_Repmgr 支持 Linux 和 Windows 操作系统。推荐操作系统使用 Redhat/CentOs 7.0 及以上版本。
二、环境准备
以下步骤,如无特殊说明,均需在所有节点执行。
1. 配置防火墙和 SELinux 请关闭防火墙和 SELinux 并关闭开机自启。
2. 修改主机名
3. 配置 IP 地址
4. 修改/etc/hosts
5. 时间同步 配置三个节点的时间同步,建议配置 NTP 时间服务器。(详细步骤略)
6. 创建用户 在所有节点创建相同的系统用户 highgo,使用该用户安装 HighGo DB V5。
7. 设置互信 在所有节点间设置 highgo 用户互信。
8. 安装 HighGo DB V5 使用 highgo 用户安装 HighGo DB V5。(详细步骤略) 推荐使用 HighGo DB 5.0 及以上版本,所有节点的数据库版本必须一致。
3 配置 HG_REPMGR
1. 设置 HGDB 的环境变量,确保 pg_config 在$PATH 中(所有节点)
vi .bash_profile export PGPORT=5866 export PGDATA=/home/highgo/hgdb/data export HGDB_HOME=/home/highgo/hgdb export LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/ lib:/usr/local/lib:$HGDB_HOME/lib export PATH=$HOME/bin:$HGDB_HOME/bin:$PATH export HG_BASE=/home/lmy/highgo/diag source .bash_profile |
注意:
[highgo@dbrs ~]$ ssh dbrs2 ssh: /opt/highgo/5.6.1/lib/libcrypto.so.10: version `OPENSSL_1.0.2' not found (required by ssh) [highgo@dbrs ~]$ 此问题解决方案,把/opt/highgo/5.6.1/lib放到系统环境变量的后面 |
2. 清空备节点的 data 目录(所有备节点)
pg_ctl stop cd $PGDATA rm –r * |
3 设置 HGDB 参数并重启数据库(仅主节点)
cd $PGDATA vi postgresql.replication.conf listen_addresses='*' log_destination = 'csvlog' logging_collector = on log_directory = 'log' log_filename = 'highgodb-%Y-%m-%d_%H%M%S.log' max_wal_senders = 10 wal_level = 'hot_standby' hot_standby = on wal_log_hints = on archive_mode = on #archive_directory = '/opt/highgo/5.6.1/arch' archive_command = 'cp %p /opt/highgo/5.6.1/arch' wal_keep_segments = 5000 |
需要的目录需要创建出来
mkdir $PGHOME/arch |
将该文件包含到 postgresql.conf 中:
vi postgresql.conf include 'postgresql.replication.conf' |
重启数据库
pg_ctl restart |
4. 为 HG_Repmgr 创建用户和数据库(仅主节点)
createuser -P -s hgrepmgr -->将密码设置为 highgo createdb hgrepmgr -O hgrepmgr |
5. 配置 pg_hba.conf(仅主节点) 在 pg_hba.conf 中追加:
# cus host replication hgrepmgr 192.168.90.0/24 md5 host hgrepmgr hgrepmgr 192.168.90.0/24 md5 |
重新加载
pg_ctl reload |
6. 配置密码文件(所有节点) 在所有节点使用 highgo 用户创建密码文件:
vi ~/.pgpass dbrs:5866:replication:hgrepmgr:highgo dbrs:5866:hgrepmgr:hgrepmgr:highgo dbrs2:5866:replication:hgrepmgr:highgo dbrs2:5866:hgrepmgr:hgrepmgr:highgo 修改文件权限: chmod 0600 .pgpass |
7. 测试主端数据库是否可达(所有备节点)
psql 'host=dbrs user=hgrepmgr dbname=hgrepmgr connect_timeout=2' [highgo@dbrs2 ~]$ psql 'host=dbrs user=hgrepmgr dbname=hgrepmgr connect_timeout=2' psql (5.6.1) Type "help" for help. hgrepmgr=# |
备节只需安装软件,调用psql可以连接主库。
3.2 配置 HG_Repmgr
1. 修改配置文件(仅主节点) 修改$HGDB_HOME/conf 中的 hg_repmgr.conf 文件,内容如下:
node_id=1 node_name=dbrs conninfo='host=dbrs user=hgrepmgr dbname=hgrepmgr connect_timeout=2' data_directory='/opt/highgo/5.6.1/data' pg_bindir='/opt/highgo/5.6.1/bin' passfile='/home/highgo/.pgpass' |
2 注册主节点(仅主节点)
repmgr primary register [highgo@dbrs conf]$ repmgr -f /opt/highgo/5.6.1/conf/hg_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 [highgo@dbrs conf]$ repmgr cluster show [highgo@dbrs conf]$ repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf cluster show ID | Name | Role | Status | Upstream | Location | Connection string ----+------+---------+-----------+----------+----------+----------------------------------------------------------- 1 | dbrs | primary | * running | | default | host=dbrs user=hgrepmgr dbname=hgrepmgr connect_timeout=2 [highgo@dbrs conf]$ |
提示:
Repmgr v4.7版本:默认路径不认,需要手动指定 -f
不指定-f的话,把hg_repmgr.conf 拷贝到以下路径里
3.3 克隆并注册备节点(所有备节点)
1)修改配置文件 修改 node2 的$HGDB_HOME/conf 中 hg_repmgr.conf 文件,内容如下:
node_id=2 node_name=dbrs2 conninfo='host=dbrs2 user=hgrepmgr dbname=hgrepmgr connect_timeout=2' data_directory='/opt/highgo/5.6.1/data' pg_bindir='/opt/highgo/5.6.1/bin' passfile='/home/highgo/.pgpass' |
其他节点类似,更改上述配置文件中的
node_id、node_name和conninfo。
2)检查备节点是否可被克隆 (备节点执行、 -h指的主节点,想想流复制配置pg_basebackup)
repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf -h dbrs -U hgrepmgr -d hgrepmgr standby clone --dry-run [highgo@dbrs2 ~]$ repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf -h dbrs -U hgrepmgr -d hgrepmgr standby clone --dry-run NOTICE: destination directory "/opt/highgo/5.6.1/data" provided INFO: connecting to source node DETAIL: connection string is: host=dbrs user=hgrepmgr dbname=hgrepmgr DETAIL: current installation size is 1437 MB NOTICE: standby will attach to upstream node 1 HINT: consider using the -c/--fast-checkpoint option INFO: all prerequisites for "standby clone" are met [highgo@dbrs2 ~]$ |
3)克隆备节点 (备节点执行、 -h指的主节点,想想流复制配置pg_basebackup)
repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf -h dbrs -U hgrepmgr -d hgrepmgr standby clone
[highgo@dbrs2 ~]$ repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf -h dbrs -U hgrepmgr -d hgrepmgr standby clone NOTICE: destination directory "/opt/highgo/5.6.1/data" provided INFO: connecting to source node DETAIL: connection string is: host=dbrs user=hgrepmgr dbname=hgrepmgr DETAIL: current installation size is 1437 MB INFO: checking and correcting permissions on existing directory "/opt/highgo/5.6.1/data" NOTICE: starting backup (using pg_basebackup)... HINT: this may take some time; consider using the -c/--fast-checkpoint option INFO: executing: /opt/highgo/5.6.1/bin/pg_basebackup -l "repmgr base backup" -D /opt/highgo/5.6.1/data -h dbrs -p 5866 -U hgrepmgr -X stream NOTICE: standby clone (using pg_basebackup) complete NOTICE: you can now start your PostgreSQL server HINT: for example: pg_ctl -D /opt/highgo/5.6.1/data start HINT: after starting the server, you need to register this standby with "repmgr standby register" [highgo@dbrs2 ~]$ [highgo@dbrs2 ~]$ |
4)启动并注册备节点
pg_ctl -D /opt/highgo/5.6.1/data start repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf standby register [highgo@dbrs2 ~]$ repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf standby register INFO: connecting to local node "dbrs2" (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 "dbrs2" (id: 2) successfully registered [highgo@dbrs2 ~]$ |
更多详细信息请登录【瀚高技术支持平台】查看https://support.highgo.com/#/index/docContent/89cd540c057816c7