HG_REPMGR Virtual IP虚拟IP配置

原文链接: https://support.highgo.com/#/index/docContent/badd508402336fe2

目录

文档用途

详细信息

文档用途

HG_REPMGR Virtual IP虚拟IP配置参考

详细信息

Hg_Repmgr Virtual IP使用说明示例

 

当前环境IP地址

 

[highgo@dbrs conf]$ cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.6.16        dbrs

192.168.6.17        dbrs2

[highgo@dbrs conf]$

 

 

1. 系统配置

hg_repmgr的virtual IP功能是使用系统命令进行virtual ip的漂移,所以需要给highgo

户配置免密sudo权限。## Allow root to run any commands anywhere

 

vi /etc/sudoers

root    ALL=(ALL)       ALL

highgo  ALL=(ALL)       NOPASSWD:ALL

%highgo ALL=(ALL)       NOPASSWD:ALL

 

测试:

[highgo@dbrs2 ~]$ sudo tail -n 50 /var/log/messages

 

下面可以利用repmgr进行流复制环境的搭配

 

2. 配置各个节点的hg_repmgr.conf配置文件。

 

新建:

新建repmgr

 

# cus

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'

 

failover=automatic     

promote_command='repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf standby promote'

follow_command='repmgr -f /opt/highgo/5.6.1/conf/hg_repmgr.conf standby follow --upstream-node-id=%n' 

 

log_file='/opt/highgo/5.6.1/data/log/hg_repmgr.log'

 

virtual_ip = '192.168.6.201'

network_card = 'enp0s3'

gateway = '192.168.6.254'

 

以上是primary节点的配置,standby节点配置类似(需要改变一下node_id和node_name)

 

 

 

3. 生成primary节点数据库后,执行repmgr primary register进行注册。

执行repmgr cluster show查看:

 

具体命令参考HG_REPMGR配置章节 

 

在注册primary成功后,virtual IP会自动绑定到该节点的网卡上。可通过ip addr查看。

 

 

 

 

[highgo@dbrs ~]$ ip addr

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 08:00:27:65:b4:93 brd ff:ff:ff:ff:ff:ff

    inet 192.168.6.16/24 brd 192.168.6.255 scope global noprefixroute enp0s3

       valid_lft forever preferred_lft forever

    inet 192.168.6.201/32 scope global enp0s3

       valid_lft forever preferred_lft forever

    inet6 fe80::72b4:e379:e445:51bb/64 scope link noprefixroute

       valid_lft forever preferred_lft forever

    inet6 fe80::600:efed:eea6:3304/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

 

4. 对standby进行clone,并启动注册。

 

 

具体命令参考HG_REPMGR配置章节 

 

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

 2  | dbrs2 | standby | ! running as primary | dbrs     | default  | host=dbrs2 user=hgrepmgr dbname=hgrepmgr connect_timeout=2

 

 

 

5. 对每个节点启动repmgrd 监控进程。

通过执行以下命令启动:

 

 

repmgrd                 -d

 

6. 利用下面shell脚本,模拟向流复制集群中写入数据,指定VIP

 

 

[highgo@dbrs conf]$ cat /tmp/b.sh

#!/bin/bash

DATE=`date +%Y-%m-%d-%H`

. ~/.bash_profile

psql -h 192.168.6.201 -d highgo -p 5866 -U highgo << EOF

insert into test values(10001,'张强');

\q

EOF

 

Sh b.sh

 

 

 

显示插入成功,检查数据表test, 已经插入了一条数据。

highgo=# select * from test;

   n   |  t  

-------+------

 10001 | 张强

(1 行记录)

 

更多详细信息请登录【瀚高技术支持平台】 查看https://support.highgo.com/#/index/docContent/badd508402336fe2

你可能感兴趣的:(Highgo,DB)