暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PG 14 + Pgpool-II + Watchdog 实现高可用(自动故障转移+读写分离+负载均衡)

简介

Pgpool-II是一个在PostgreSQL服务器和PostgreSQL数据库客户端之间工作的中间件。它是根据BSD许可证授权的。它提供以下功能。


连接池


Pgpool-II保存与PostgreSQL服务器的连接,并在具有相同属性(即用户名,数据库,协议版本)的新连接进入时重用它们。它减少了连接开销,并提高了系统的整体吞吐量。


复制


Pgpool-II可以管理多个PostgreSQL服务器。使用复制功能可以在2个或更多物理磁盘上创建实时备份,以便在磁盘发生故障时服务可以继续运行而不会停止服务器。


负载均衡


如果复制了数据库,则在任何服务器上执行SELECT查询都将返回相同的结果。Pgpool-II利用复制功能,通过在多个服务器之间分配SELECT查询来减少每个PostgreSQL服务器的负载,从而提高系统的整体吞吐量。充其量,性能与PostgreSQL服务器的数量成比例地提高。在许多用户同时执行许多查询的情况下,负载平衡最有效。


限制超出连接


PostgreSQL的最大并发连接数有限制,连接在这么多连接后被拒绝。但是,设置最大连接数会增加资源消耗并影响系统性能。pgpool-II对最大连接数也有限制,但额外连接将排队,而不是立即返回错误。


看家狗


Watchdog可以协调多个Pgpool-II,创建一个强大的集群系统,避免单点故障或脑裂。看门狗可以对其他pgpool-II节点执行生命检查,以检测Pgpoll-II的故障。如果活动Pgpool-II发生故障,则可以将备用Pgpool-II提升为活动状态,并接管虚拟IP。


在内存查询缓存中


在内存中查询缓存允许保存一对SELECT语句及其结果。如果有相同的SELECT,Pgpool-II将从缓存中返回值。由于不涉及SQL解析或访问PostgreSQL,因此在内存缓存中使用速度非常快。另一方面,在某些情况下,它可能比正常路径慢,因为它增加了存储缓存数据的一些开销。


Pgpool-II讲PostgreSQL的后端和前端协议,并在后端和前端之间传递消息。因此,数据库应用程序(前端)认为Pgpool-II是实际的PostgreSQL服务器,服务器(后端)将Pgpool-II视为其客户端之一。因为Pgpool-II对服务器和客户端都是透明的,所以现有的数据库应用程序可以与Pgpool-II一起使用。Pgpool-II讲述PostgreSQL的后端和前端协议,并在它们之间传递连接。因此,数据库应用程序(前端)认为Pgpool-II是实际的PostgreSQL服务器,服务器(后端)将Pgpool-II视为其客户端之一。因为Pgpool-II对服务器和客户端都是透明的,所以现有的数据库应用程序可以与Pgpool-II一起使用,几乎不需要更改其源码。


watchdog是pgpool的核心组件,watchdog在 pgpool方案中扮演非常重要的角色,当启动pgpool时会启动watchdog子进程,主要作用为:


  • 和pgpool后端PostgreSQL数据库节点以及远程pgpool节点进行通信。

  • 对远程pgpool节点是否存活进行检查。

  • 当watchdog子进程启动时,对本地pgpool的配置和远程pgpool的配置参数进行检查,并且输出本地和远程pgpool不一致的参数。

  • 当pgpool主节点宕机时,watchdog集群将选举出新的 watchdog主节点。

  • 当pgpool备节点激活成主节点时,watchdog负责将VIP飘移到新的pgpool节点。


相关文章

之前发布过几篇有关pgpool的文章:


  • 【DB宝60】PG12高可用之1主2从流复制环境搭建及切换测试

  • 【DB宝61】PostgreSQL使用Pgpool-II实现读写分离+负载均衡

  • PostgreSQL高可用之repmgr(1主2从+1witness)+Pgpool-II实现主从切换+读写分离+负载均衡

  • 【DB宝72】pgpool-II和pgpoolAdmin的使用

  • PG高可用之主从流复制+keepalived 的高可用


有关pgpool-II的相关文档:

  • pgpool-II 3.2.5手册

  • pgpool-II-3.2.5入门教程


架构


本节显示了使用Pgpool-II的流式复制配置示例。在本例中,我们使用3台Pgpool-II服务器来管理PostgreSQL服务器,以创建一个健壮的集群系统,并避免单点故障或脑裂。


本配置示例中使用了PostgreSQL 14。所有脚本都经过PostgreSQL 10及更高版本的测试。


我们使用3台安装了CentOS 7.6的服务器,server1、server2、server3。我们在每台服务器上安装PostgreSQL 14和Pgpool II。


我们假设所有Pgpool-II服务器和PostgreSQL服务器都位于同一子网中。


本文架构图如下所示:



Note: Active, Standby, Primary, Standby 这些角色不是固定的,在后续的切换中是可以改变的。

如果是2个节点,那么架构可以变为:


Table 1. 主机及IP地址


Hostname

IPAddress

VirtualIP

别名

lhrpg30

172.72.6.30

172.72.6.35

Server1

lhrpg31

172.72.6.31

172.72.6.35

Server2

lhrpg32

172.72.6.32

172.72.6.35

Server3


Table 2. PostgreSQL版本及配置


Item

Value

Detail

PostgreSQLVersion

14.2

-

Port

5432

-

$PGDATA

/var/lib/pgsql/14/data

-

Archivemode

on

/var/lib/pgsql/archivedir

ReplicationSlots

Enable

-

Startautomatically

Enable

-


Table 3. Pgpool-II版本及配置

Item

Value

Detail

Pgpool-II Version

4.3.0

-

port

9999

Pgpool-II accepts connections


9898

PCP process accepts connections


9000

watchdog accepts connections


9694

UDP port for receiving Watchdogs heartbeat signal

Config file

/etc/pgpool-II/pgpool.conf

Pgpool-II config file

Pgpool-II start user

postgres (Pgpool-II 4.1 or later)

Pgpool-II 4.0 or before, the default startup user is root

Running mode

streaming replication mode

-

Watchdog

on

Life check method: heartbeat

Start automatically

Enable

-


Table 4. 示例脚本


Feature

Script

Detail

Failover

/etc/pgpool-II/failover.sh.sample

Run by failover_command to perform failover



/etc/pgpool-II/follow_primary.sh.sample


Run by follow_primary_command to synchronize the Standby with the new Primary after failover.


Online recovery

/etc/pgpool-II/recovery_1st_stage.sample


Run by recovery_1st_stage_command to recovery a Standby node



/etc/pgpool-II/pgpool_remote_start.sample

Run after recovery_1st_stage_command to start the Standby node

Watchdog

/etc/pgpool-II/escalation.sh.sample

Run by wd_escalation_command to switch the Active/Standby Pgpool-II safely


上述脚本包含在RPM包中,可以根据需要进行定制。

  1. -- 网卡

  2. docker network create --subnet=172.72.6.0/24 pg-network


  3. -- 申请主机

  4. docker rm -f lhrpg30

  5. docker run -d --name lhrpg30 -h lhrpg30 \

  6. --net=pg-network --ip 172.72.6.30 \

  7. -p 64330:5432 -p 9930:9999 \

  8. -v /sys/fs/cgroup:/sys/fs/cgroup \

  9. --privileged=true lhrbest/lhrcentos76:8.5 \

  10. /usr/sbin/init



  11. docker rm -f lhrpg31

  12. docker run -d --name lhrpg31 -h lhrpg31 \

  13. --net=pg-network --ip 172.72.6.31 \

  14. -p 64331:5432 -p 9931:9999 \

  15. -v /sys/fs/cgroup:/sys/fs/cgroup \

  16. --privileged=true lhrbest/lhrcentos76:8.5 \

  17. /usr/sbin/init



  18. docker rm -f lhrpg32

  19. docker run -d --name lhrpg32 -h lhrpg32 \

  20. --net=pg-network --ip 172.72.6.32 \

  21. -p 64332:5432 -p 9932:9999 \

  22. -v /sys/fs/cgroup:/sys/fs/cgroup \

  23. --privileged=true lhrbest/lhrcentos76:8.5 \

  24. /usr/sbin/init



  25. [root@docker35 ~]# docker ps

  26. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

  27. 84113aee6b76 lhrbest/lhrcentos76:8.5 '/usr/sbin/init' 50 seconds ago Up 47 seconds 0.0.0.0:64332->5432/tcp, :::64332->5432/tcp, 0.0.0.0:9932->9999/tcp, :::9932->9999/tcp lhrpg32

  28. cb9e1aa0798b lhrbest/lhrcentos76:8.5 '/usr/sbin/init' 52 seconds ago Up 50 seconds 0.0.0.0:64331->5432/tcp, :::64331->5432/tcp, 0.0.0.0:9931->9999/tcp, :::9931->9999/tcp lhrpg31

  29. f2b458ef2e7d lhrbest/lhrcentos76:8.5 '/usr/sbin/init' 55 seconds ago Up 52 seconds 0.0.0.0:64330->5432/tcp, :::64330->5432/tcp, 0.0.0.0:9930->9999/tcp, :::9930->9999/tcp lhrpg30

安装Pgpool-II和PostgreSQL 14

我们使用yum来安装Pgpool-II和PostgreSQL 14。

在3台机器都安装,如下:


yum安装PG 14.2

参考:【DB宝67】使用yum来安装PostgreSQL13.3数据库

  1. yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

  2. yum install -y postgresql14 postgresql14-server postgresql14-contrib postgresql14-libs



  3. /usr/pgsql-14/bin/postgresql-14-setup initdb

  4. systemctl disable postgresql-14

  5. systemctl start postgresql-14

  6. systemctl status postgresql-14


  7. echo 'postgres ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

  8. echo 'export PS1='[\u@\h \W]$ '' >> /etc/profile

  9. echo 'postgres:lhr' | chpasswd


  10. echo 'export PATH=/usr/pgsql-14/bin:$PATH' >> /etc/profile



yum安装pgpool-II

https://www.pgpool.net/yum/rpms/

https://www.pgpool.net/mediawiki/index.php/Yum_Repository

https://www.pgpool.net/docs/latest/en/html/install-rpm.html


  1. yum install -y https://www.pgpool.net/yum/rpms/4.3/redhat/rhel-7-x86_64/pgpool-II-release-4.3-1.noarch.rpm

  2. yum install -y pgpool-II pgpool-II-pg14-extensions


  3. -- 会安装如下四个包:

  4. Installing : libmemcached-1.0.16-5.el7.x86_64 1/4

  5. Installing : pgpool-II-pcp-4.3.1-1.rhel7.x86_64 2/4

  6. Installing : pgpool-II-4.3.1-1.rhel7.x86_64 3/4

  7. Installing : pgpool-II-pg14-extensions-4.3.1-1.rhel7.x86_64



  8. systemctl disable pgpool-II.service

Note: 如果设置Pgpool-II自动启动,则需要将 search_primary_node_timeout更改为适当的值,以便在服务器启动后启动PostgreSQL。如果Pgpool-II在 search_primary_node_timeout期间无法连接到后端的PostgreSQL,它将失败。


准备工作

在server1操作即可。


配置归档

  1. su - postgres

  2. mkdir -p /var/lib/pgsql/archivedir



  3. -- 配置允许PG远程登录,注意版本:

  4. cat >> /var/lib/pgsql/14/data/postgresql.conf <<'EOF'

  5. listen_addresses = '*'

  6. port=5432

  7. unix_socket_directories='/var/run/postgresql/'

  8. logging_collector = on

  9. log_directory = 'pg_log'

  10. log_filename = 'postgresql-%a.log'

  11. log_truncate_on_rotation = on


  12. archive_mode = on

  13. archive_command = 'cp '%p' '/var/lib/pgsql/archivedir/%f''

  14. max_wal_senders = 10

  15. max_replication_slots = 10

  16. wal_level = replica

  17. hot_standby = on

  18. wal_log_hints = on


  19. password_encryption = 'md5'


  20. EOF


  21. cat > /var/lib/pgsql/14/data/pg_hba.conf << 'EOF'

  22. # TYPE DATABASE USER ADDRESS METHOD

  23. local all all trust

  24. host all all ::1/128 trust

  25. host all all 127.0.0.1/32 trust

  26. host all all 172.72.6.0/24 trust

  27. host all all 0.0.0.0/0 md5

  28. host replication all 0.0.0.0/0 md5

  29. EOF



  30. sudo systemctl restart postgresql-14

  31. systemctl status postgresql-14


Server1配置用户


Table 6. Users

User NamePasswordDetail
replreplPostgreSQL复制用户
pgpoolpgpoolPgpool-II health check (health_check_user) and replication delay check (sr_check_user) user
postgrespostgresUser running online recovery
  1. psql -U postgres -p 5432

  2. CREATE ROLE pgpool WITH LOGIN;

  3. CREATE ROLE repl WITH REPLICATION LOGIN;

  4. alter user postgres with encrypted password 'lhr';

  5. alter user pgpool with encrypted password 'lhr';

  6. alter user repl with encrypted password 'lhr';

  7. GRANT pg_monitor TO pgpool;

配置互信

  1. chmod +x ./sshUserSetup.sh

  2. ./sshUserSetup.sh -user root -hosts 'lhrpg30 lhrpg31 lhrpg32' -advanced exverify -confirm

  3. ./sshUserSetup.sh -user postgres -hosts 'lhrpg30 lhrpg31 lhrpg32' -advanced exverify -confirm




  4. cp /var/lib/pgsql/.ssh/id_rsa /var/lib/pgsql/.ssh/id_rsa_pgpool

  5. cp /var/lib/pgsql/.ssh/id_rsa.pub /var/lib/pgsql/.ssh/id_rsa_pgpool.pub

  6. chown -R postgres.postgres /var/lib/pgsql/.ssh/


  7. cp /root/.ssh/id_rsa /root/.ssh/id_rsa_pgpool

  8. cp /root/.ssh/id_rsa.pub /root/.ssh/id_rsa_pgpool.pub


pgpool配置


创建pgpool的密码文件

注意:/var/lib/pgsqll为postgres用的家目录。


  1. -- 配置psql的密码

  2. cat > /var/lib/pgsql/.pgpass <<'EOF'

  3. 172.72.6.30:5432:replication:repl:lhr

  4. 172.72.6.31:5432:replication:repl:lhr

  5. 172.72.6.32:5432:replication:repl:lhr

  6. 172.72.6.35:9999:postgres:pgpool:lhr

  7. 172.72.6.35:9999:postgres:postgres:lhr

  8. lhrpg30:5432:replication:repl:lhr

  9. lhrpg31:5432:replication:repl:lhr

  10. lhrpg32:5432:replication:repl:lhr

  11. lhrpg30:5432:postgres:postgres:lhr

  12. lhrpg31:5432:postgres:postgres:lhr

  13. lhrpg32:5432:postgres:postgres:lhr

  14. EOF


  15. chown postgres.postgres /var/lib/pgsql/.pgpass

  16. chmod 600 /var/lib/pgsql/.pgpass




  17. echo 'localhost:9898:pgpool:lhr' > /var/lib/pgsql/.pcppass

  18. chmod 600 /var/lib/pgsql/.pcppass

  19. chown postgres.postgres /var/lib/pgsql/.pcppass



  20. echo 'pgpool:'`pg_md5 -u=pgpool lhr` >> /etc/pgpool-II/pcp.conf


创建pgpool_node_id

  • server1

    1.echo '0' > /etc/pgool-II/pgpool_node_id
  • server2

  • 1.echo '1' > /etc/pgool-II/pgpool_node_id
  • server3

  • 1.echo '2' > /etc/pgool-II/pgpool_node_id

Pgpool-II参数配置

  1. cat > /etc/pgpool-II/pgpool.conf <<'EOF'



  2. backend_clustering_mode = 'streaming_replication'



  3. # - pgpool Connection Settings -

  4. listen_addresses = '*'

  5. port=9999


  6. # - Streaming Replication Check

  7. sr_check_user = 'pgpool'

  8. sr_check_password = ''


  9. # - Health Check

  10. health_check_period = 5

  11. health_check_timeout = 30

  12. health_check_user = 'pgpool'

  13. health_check_password = 'lhr'

  14. health_check_max_retries = 3



  15. search_primary_node_timeout = 10min



  16. # - Backend Connection Settings -

  17. backend_hostname0 = '172.72.6.30'

  18. backend_port0 = 5432

  19. backend_weight0 = 1

  20. backend_data_directory0 = '/var/lib/pgsql/14/data'

  21. backend_flag0 = 'ALLOW_TO_FAILOVER'

  22. backend_application_name0 = 'server1'


  23. backend_hostname1 = '172.72.6.31'

  24. backend_port1 = 5432

  25. backend_weight1 = 1

  26. backend_data_directory1 = '/var/lib/pgsql/14/data'

  27. backend_flag1 = 'ALLOW_TO_FAILOVER'

  28. backend_application_name0 = 'server2'


  29. backend_hostname2 = '172.72.6.32'

  30. backend_port2 = 5432

  31. backend_weight2 = 1

  32. backend_data_directory2 = '/var/lib/pgsql/14/data'

  33. backend_flag2 = 'ALLOW_TO_FAILOVER'

  34. backend_application_name0 = 'server3'



  35. # - Failover configuration

  36. failover_command = '/etc/pgpool-II/failover.sh %d %h %p %D %m %H %M %P %r %R %N %S'

  37. follow_primary_command = '/etc/pgpool-II/follow_primary.sh %d %h %p %D %m %H %M %P %r %R'


  38. # - Online Recovery Configurations

  39. recovery_user = 'postgres'

  40. recovery_password = 'lhr'

  41. recovery_1st_stage_command = 'recovery_1st_stage'



  42. # - Client Authentication Configuration

  43. enable_pool_hba = on

  44. pool_passwd = '/etc/pgpool-II/pool_passwd'


  45. # - Watchdog Configuration

  46. use_watchdog = on

  47. delegate_IP = '172.72.6.35'


  48. if_up_cmd = '/usr/bin/sudo /sbin/ip addr add $_IP_$/24 dev eth0 label eth0:1'

  49. if_down_cmd = '/usr/bin/sudo /sbin/ip addr del $_IP_$/24 dev eth0'

  50. arping_cmd = '/usr/bin/sudo /usr/sbin/arping -U $_IP_$ -w 1 -I eth0'


  51. hostname0 = '172.72.6.30'

  52. wd_port0 = 9000

  53. pgpool_port0 = 9999


  54. hostname1 = '172.72.6.31'

  55. wd_port1 = 9000

  56. pgpool_port1 = 9999


  57. hostname2 = '172.72.6.32'

  58. wd_port2 = 9000

  59. pgpool_port2 = 9999


  60. wd_lifecheck_method = 'heartbeat'

  61. wd_interval = 10


  62. heartbeat_hostname0 = '172.72.6.30'

  63. heartbeat_port0 = 9694

  64. heartbeat_device0 = ''


  65. heartbeat_hostname1 = '172.72.6.31'

  66. heartbeat_port1 = 9694

  67. heartbeat_device1 = ''


  68. heartbeat_hostname2 = '172.72.6.32'

  69. heartbeat_port2 = 9694

  70. heartbeat_device2 = ''


  71. wd_heartbeat_keepalive = 2

  72. wd_heartbeat_deadtime = 30


  73. wd_escalation_command = '/etc/pgpool-II/escalation.sh'




  74. # - Where to log -

  75. log_destination = 'stderr'

  76. logging_collector = on

  77. log_directory = '/var/log/pgpool-II'

  78. log_filename = 'pgpool-%Y-%m-%d_%H%M%S.log'

  79. log_truncate_on_rotation = on

  80. log_rotation_age = 1d

  81. log_rotation_size = 10MB



  82. pid_file_name = '/var/run/postgresql/pgpool.pid'



  83. #------------------------------------------------------------------------------

  84. # LOAD BALANCING MODE

  85. #------------------------------------------------------------------------------

  86. load_balance_mode = on



  87. EOF






  88. cp -p /etc/pgpool-II/failover.sh{.sample,}

  89. cp -p /etc/pgpool-II/follow_primary.sh{.sample,}

  90. chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}

  91. chmod +x /etc/pgpool-II/{failover.sh,follow_primary.sh}


  92. cp -p /etc/pgpool-II/recovery_1st_stage.sample /var/lib/pgsql/14/data/recovery_1st_stage

  93. cp -p /etc/pgpool-II/pgpool_remote_start.sample /var/lib/pgsql/14/data/pgpool_remote_start

  94. chown postgres:postgres /var/lib/pgsql/14/data/{recovery_1st_stage,pgpool_remote_start}

  95. chmod +x /var/lib/pgsql/14/data/{recovery_1st_stage,pgpool_remote_start}


  96. su - postgres

  97. psql template1 -c 'CREATE EXTENSION pgpool_recovery'

  98. psql postgres -c 'CREATE EXTENSION pgpool_recovery'


  99. echo 'host all all 0.0.0.0/0 md5' >> /etc/pgpool-II/pool_hba.conf



  100. -- cat /etc/pgpool-II/pool_passwd

  101. pg_md5 --md5auth --username=pgpool 'lhr'

  102. pg_md5 --md5auth --username=postgres 'lhr'




  103. cat > /etc/pgpool-II/escalation.sh <<'EOF'

  104. #!/bin/bash

  105. # This script is run by wd_escalation_command to bring down the virtual IP on other pgpool nodes

  106. # before bringing up the virtual IP on the new active pgpool node.


  107. set -o xtrace


  108. PGPOOLS=(172.72.6.30 172.72.6.31 172.72.6.32)

  109. VIP=172.72.6.35

  110. DEVICE=eth0


  111. for pgpool in '${PGPOOLS[@]}'; do

  112. [ '$HOSTNAME' = '$pgpool' ] && continue


  113. ssh -T -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null postgres@$pgpool -i ~/.ssh/id_rsa_pgpool '

  114. /usr/bin/sudo /sbin/ip addr del $VIP/24 dev $DEVICE

  115. '

  116. done

  117. exit 0


  118. EOF



  119. chown postgres:postgres /etc/pgpool-II/escalation.sh

  120. chmod +x /etc/pgpool-II/*.sh



  121. chown postgres:postgres /etc/pgpool-II/*.conf


故障转移配置

failover_command参数中执行故障转移后要执行的shell脚本。如果我们使用3台PostgreSQL服务器,我们需要指定follow_primary_command,以便在主节点故障转移后运行。对于两台PostgreSQL服务器,不需要设置follow_primary_command

  1. failover_command = '/etc/pgpool-II/failover.sh %d %h %p %D %m %H %M %P %r %R %N %S'

  2. follow_primary_command = '/etc/pgpool-II/follow_primary.sh %d %h %p %D %m %H %M %P %r %R'


示例脚本failover.sh和follow_primary.sh安装在/etc/pgpool-II/中。可以使用这些示例文件创建故障转移脚本。


  1. cp -p /etc/pgpool-II/failover.sh{.sample,}

  2. cp -p /etc/pgpool-II/follow_primary.sh{.sample,}

  3. chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}

  4. chmod +x /etc/pgpool-II/{failover.sh,follow_primary.sh}


注意脚本failover.sh
follow_primary.sh
中的PGHOME是否配置正确。脚本follow_primary.sh
中的PCP_USER为pgpool。


Pgpool-II在线恢复配置

为了使用Pgpool II执行在线恢复,我们指定PostgreSQL用户名和在线恢复命令recovery_1st_stage。因为执行在线恢复需要PostgreSQL中的超级用户权限,所以我们在recovery_user中指定postgres_user。然后,我们在PostgreSQL主服务器(server1)的数据库集群目录中创建recovery_1st_stage和pgpool_remote_start,并添加执行权限。


  1. recovery_user = 'postgres'

  2. recovery_password = 'lhr'

  3. recovery_1st_stage_command = 'recovery_1st_stage'

在线恢复示例脚本recovery_First_stage和pgpool_remote_start安装在/etc/pgpool II/中。将这些文件复制到主服务器(server1)的数据目录。


  1. cp -p /etc/pgpool-II/recovery_1st_stage.sample /var/lib/pgsql/14/data/recovery_1st_stage

  2. cp -p /etc/pgpool-II/pgpool_remote_start.sample /var/lib/pgsql/14/data/pgpool_remote_start

  3. chown postgres:postgres /var/lib/pgsql/14/data/{recovery_1st_stage,pgpool_remote_start}

Basically, it should work if you change PGHOME according to PostgreSQL installation directory.

注意脚本recovery_1st_stage
pgpool_remote_start
中的PGHOME是否配置正确。脚本follow_primary.sh
中的PCP_USER为pgpool。


为了使用在线恢复功能,需要pgpool_recovery、pgpool_remote_start、pgpool_switch_xlog等功能,因此我们需要在PostgreSQL server server1的template1上安装pgpool_recovery。

  1. su - postgres

  2. psql template1 -c 'CREATE EXTENSION pgpool_recovery'


配置/etc/pgpool-II/pool_hba.conf

  1. -- cat /etc/pgpool-II/pool_passwd

  2. pg_md5 --md5auth --username=pgpool 'lhr'

  3. pg_md5 --md5auth --username=postgres 'lhr'


Watchdog配置

  1. cat > /etc/pgpool-II/escalation.sh <<'EOF'

  2. #!/bin/bash

  3. # This script is run by wd_escalation_command to bring down the virtual IP on other pgpool nodes

  4. # before bringing up the virtual IP on the new active pgpool node.


  5. set -o xtrace


  6. PGPOOLS=(172.72.6.30 172.72.6.31 172.72.6.32)

  7. VIP=172.72.6.35

  8. DEVICE=eth0


  9. for pgpool in '${PGPOOLS[@]}'; do

  10. [ '$HOSTNAME' = '$pgpool' ] && continue


  11. ssh -T -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null postgres@$pgpool -i ~/.ssh/id_rsa_pgpool '

  12. /usr/bin/sudo /sbin/ip addr del $VIP/24 dev $DEVICE

  13. '

  14. done

  15. exit 0


  16. EOF



  17. chown postgres:postgres /etc/pgpool-II/escalation.sh

  18. chmod +x /etc/pgpool-II/escalation.sh


启动Pgpool-II

在启动Pgpool-II之前,请先启动PostgreSQL;在关闭PostgreSQL之前,请先关闭Pgpool-II

  1. systemctl start pgpool-II.service

  2. systemctl status pgpool-II.service


过程:

  1. [root@lhrpg32 data]# systemctl start pgpool-II.service

  2. [root@lhrpg32 data]# systemctl status pgpool-II.service

  3. pgpool-II.service - PGPool-II Middleware Between PostgreSQL Servers And PostgreSQL Database Clients

  4. Loaded: loaded (/usr/lib/systemd/system/pgpool-II.service; disabled; vendor preset: disabled)

  5. Active: active (running) since Wed 2022-02-23 16:20:55 CST; 373ms ago

  6. Main PID: 7279 (pgpool)

  7. CGroup: /docker/84113aee6b76f386a21bd9990d098af5a5720410d71245c74998d749926e8385/system.slice/pgpool-II.service

  8. ├─7279 /usr/bin/pgpool -f /etc/pgpool-II/pgpool.conf -n -D

  9. ├─7280 pgpool: PgpoolLogger

  10. └─7282 pgpool: watchdog


  11. Feb 23 16:20:55 lhrpg32 systemd[1]: Started PGPool-II Middleware Between PostgreSQL Servers And PostgreSQL Database Clients.

  12. Feb 23 16:20:55 lhrpg32 pgpool[7279]: 2022-02-23 16:20:55.552: main pid 7279: LOG: Backend status file /tmp/pgpool_status does not exist

  13. Feb 23 16:20:55 lhrpg32 pgpool[7279]: 2022-02-23 16:20:55.553: main pid 7279: LOG: redirecting log output to logging collector process

  14. Feb 23 16:20:55 lhrpg32 pgpool[7279]: 2022-02-23 16:20:55.553: main pid 7279: HINT: Future log output will appear in directory '/var/log/pgpool_log'.

  15. [root@lhrpg32 data]# systemctl status pgpool-II.service

  16. pgpool-II.service - PGPool-II Middleware Between PostgreSQL Servers And PostgreSQL Database Clients

  17. Loaded: loaded (/usr/lib/systemd/system/pgpool-II.service; disabled; vendor preset: disabled)

  18. Active: active (running) since Wed 2022-02-23 16:20:55 CST; 11s ago

  19. Main PID: 7279 (pgpool)

  20. CGroup: /docker/84113aee6b76f386a21bd9990d098af5a5720410d71245c74998d749926e8385/system.slice/pgpool-II.service

  21. ├─7279 /usr/bin/pgpool -f /etc/pgpool-II/pgpool.conf -n -D

  22. ├─7280 pgpool: PgpoolLogger

  23. ├─7282 pgpool: watchdog

  24. ├─7288 pgpool: lifecheck

  25. ├─7289 pgpool: heartbeat receiver

  26. ├─7290 pgpool: heartbeat sender

  27. ├─7291 pgpool: heartbeat receiver

  28. ├─7292 pgpool: heartbeat sender

  29. ├─7293 pgpool: wait for connection request

  30. ├─7294 pgpool: wait for connection request

  31. ├─7295 pgpool: wait for connection request

  32. ├─7296 pgpool: wait for connection request

  33. ├─7297 pgpool: wait for connection request

  34. ├─7298 pgpool: wait for connection request

  35. ├─7299 pgpool: wait for connection request

  36. ├─7300 pgpool: wait for connection request

  37. ├─7301 pgpool: wait for connection request

  38. ├─7302 pgpool: wait for connection request

  39. ├─7303 pgpool: wait for connection request

  40. ├─7304 pgpool: wait for connection request

  41. ├─7305 pgpool: wait for connection request

  42. ├─7306 pgpool: wait for connection request

  43. ├─7307 pgpool: wait for connection request

  44. ├─7308 pgpool: wait for connection request

  45. ├─7309 pgpool: wait for connection request

  46. ├─7310 pgpool: wait for connection request

  47. ├─7311 pgpool: wait for connection request

  48. ├─7312 pgpool: wait for connection request

  49. ├─7313 pgpool: wait for connection request

  50. ├─7314 pgpool: wait for connection request

  51. ├─7315 pgpool: wait for connection request

  52. ├─7316 pgpool: wait for connection request

  53. ├─7317 pgpool: wait for connection request

  54. ├─7318 pgpool: wait for connection request

  55. ├─7319 pgpool: wait for connection request

  56. ├─7320 pgpool: wait for connection request

  57. ├─7321 pgpool: wait for connection request

  58. ├─7322 pgpool: wait for connection request

  59. ├─7323 pgpool: wait for connection request

  60. └─7324 pgpool: wait for connection request



  61. Feb 24 09:33:14 lhrpg30 systemd[1]: Started PGPool-II Middleware Between PostgreSQL Servers And PostgreSQL Database Clients.

  62. Feb 24 09:33:14 lhrpg30 pgpool[3256]: 2022-02-24 09:33:14.596: main pid 3256: LOG: Backend status file /tmp/pgpool_status does not exist

  63. Feb 24 09:33:14 lhrpg30 pgpool[3256]: 2022-02-24 09:33:14.597: main pid 3256: LOG: redirecting log output to logging collector process

  64. Feb 24 09:33:14 lhrpg30 pgpool[3256]: 2022-02-24 09:33:14.597: main pid 3256: HINT: Future log output will appear in directory '/var/log/pgpool-II'.

  65. Feb 24 09:33:27 lhrpg30 sudo[3330]: postgres : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/sbin/ip addr add 172.72.6.35/24 dev eth0 label eth0:1

  66. Feb 24 09:33:27 lhrpg30 sudo[3332]: postgres : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/arping -U 172.72.6.35 -w 1 -I eth0


  67. [root@lhrpg30 pgpool-II]# ifconfig

  68. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  69. inet 172.72.6.30 netmask 255.255.255.0 broadcast 172.72.6.255

  70. ether 02:42:ac:48:06:1e txqueuelen 0 (Ethernet)

  71. RX packets 34373 bytes 39051830 (37.2 MiB)

  72. RX errors 0 dropped 0 overruns 0 frame 0

  73. TX packets 27310 bytes 1702331 (1.6 MiB)

  74. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


  75. eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  76. inet 172.72.6.35 netmask 255.255.255.0 broadcast 0.0.0.0

  77. ether 02:42:ac:48:06:1e txqueuelen 0 (Ethernet)


  78. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  79. inet 127.0.0.1 netmask 255.0.0.0

  80. loop txqueuelen 1000 (Local Loopback)

  81. RX packets 1907 bytes 500420 (488.6 KiB)

  82. RX errors 0 dropped 0 overruns 0 frame 0

  83. TX packets 1907 bytes 500420 (488.6 KiB)

  84. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

节点1已经有VIP了。

配置PostgreSQL主备库

3个节点都启动pgpool:

  1. systemctl start pgpool-II.service

  2. systemctl status pgpool-II.service

首先,我们应该使用Pgpool-II在线恢复功能设置PostgreSQL备用服务器。确保pcp_recovery_node命令使用的recovery_1st_stage和pgpool_remote_start脚本位于PostgreSQL主服务器(server1)的数据库群集目录中。

  1. [postgres@lhrpg30 data]$ pcp_recovery_node -h 172.72.6.30 -p 9898 -U pgpool -n 1

  2. Password:

  3. pcp_recovery_node -- Command Successful


  4. [postgres@lhrpg30 data]$ pcp_recovery_node -h 172.72.6.30 -p 9898 -U pgpool -n 2

  5. Password:

  6. pcp_recovery_node -- Command Successful

在执行pcp_recovery_node命令后,验证server2和server3是否作为PostgreSQL备用服务器启动。

  1. [postgres@lhrpg30 data]$ psql -h 172.72.6.35 -p 9999 -U pgpool postgres -c 'show pool_nodes'

  2. node_id | hostname | port | status | pg_status | lb_weight | role | pg_role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change

  3. ---------+-------------+------+--------+-----------+-----------+---------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------

  4. 0 | 172.72.6.30 | 5432 | up | up | 0.333333 | primary | primary | 0 | false | 0 | | | 2022-02-24 10:01:09

  5. 1 | 172.72.6.31 | 5432 | up | up | 0.333333 | standby | standby | 0 | false | 0 | | | 2022-02-24 10:50:54

  6. 2 | 172.72.6.32 | 5432 | up | up | 0.333333 | standby | standby | 0 | true | 0 | | | 2022-02-24 10:50:54

  7. (3 rows)

切换active/standby watchdog

  1. [root@lhrpg30 pgpool_log]# pcp_watchdog_info -h 172.72.6.35 -p 9898 -U pgpool

  2. Password:

  3. 3 3 YES 172.72.6.30:9999 Linux lhrpg30 172.72.6.30


  4. 172.72.6.30:9999 Linux lhrpg30 172.72.6.30 9999 9000 4 LEADER 0 MEMBER #The Pgpool-II server started first became 'LEADER'.

  5. 172.72.6.31:9999 Linux lhrpg31 172.72.6.31 9999 9000 7 STANDBY 0 MEMBER #run as standby

  6. 172.72.6.32:9999 Linux lhrpg32 172.72.6.32 9999 9000 7 STANDBY 0 MEMBER #run as standby

停止server1节点或者停止server1上的Pgpool-II服务:

  1. [postgres@lhrpg30 data]$ ifconfig

  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  3. inet 172.72.6.30 netmask 255.255.255.0 broadcast 172.72.6.255

  4. ether 02:42:ac:48:06:1e txqueuelen 0 (Ethernet)

  5. RX packets 13542377 bytes 1195679259 (1.1 GiB)

  6. RX errors 0 dropped 0 overruns 0 frame 0

  7. TX packets 9497810 bytes 872759308 (832.3 MiB)

  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


  9. eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  10. inet 172.72.6.35 netmask 255.255.255.0 broadcast 0.0.0.0

  11. ether 02:42:ac:48:06:1e txqueuelen 0 (Ethernet)


  12. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  13. inet 127.0.0.1 netmask 255.0.0.0

  14. loop txqueuelen 1000 (Local Loopback)

  15. RX packets 59053 bytes 20664387 (19.7 MiB)

  16. RX errors 0 dropped 0 overruns 0 frame 0

  17. TX packets 59053 bytes 20664387 (19.7 MiB)

  18. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


  19. [postgres@lhrpg30 data]$

  20. [postgres@lhrpg30 data]$

  21. [postgres@lhrpg30 data]$

  22. [postgres@lhrpg30 data]$ cd

  23. [postgres@lhrpg30 ~]$

  24. [postgres@lhrpg30 ~]$

  25. [postgres@lhrpg30 ~]$ systemctl stop pgpool-II.service

  26. ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===

  27. Authentication is required to manage system services or units.

  28. Authenticating as: root

  29. Password:

  30. ==== AUTHENTICATION COMPLETE ===

  31. [postgres@lhrpg30 ~]$

  32. [postgres@lhrpg30 ~]$ ifconfig

  33. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  34. inet 172.72.6.30 netmask 255.255.255.0 broadcast 172.72.6.255

  35. ether 02:42:ac:48:06:1e txqueuelen 0 (Ethernet)

  36. RX packets 13543714 bytes 1195859958 (1.1 GiB)

  37. RX errors 0 dropped 0 overruns 0 frame 0

  38. TX packets 9499106 bytes 872937513 (832.4 MiB)

  39. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


  40. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  41. inet 127.0.0.1 netmask 255.0.0.0

  42. loop txqueuelen 1000 (Local Loopback)

  43. RX packets 60393 bytes 21167594 (20.1 MiB)

  44. RX errors 0 dropped 0 overruns 0 frame 0

  45. TX packets 60393 bytes 21167594 (20.1 MiB)

  46. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


  47. [postgres@lhrpg30 ~]$ pcp_watchdog_info -h 172.72.6.35 -p 9898 -U pgpool

  48. Password:

  49. 3 3 YES 172.72.6.32:9999 Linux lhrpg32 172.72.6.32


  50. 172.72.6.32:9999 Linux lhrpg32 172.72.6.32 9999 9000 4 LEADER 0 MEMBER

  51. 172.72.6.30:9999 Linux lhrpg30 172.72.6.30 9999 9000 10 SHUTDOWN 0 MEMBER

  52. 172.72.6.31:9999 Linux lhrpg31 172.72.6.31 9999 9000 7 STANDBY 0 MEMBER

启动server1上的Pgpool-II服务, 该服务会以standby角色运行:

  1. [postgres@lhrpg30 ~]$ sudo systemctl start pgpool-II.service

  2. [postgres@lhrpg30 ~]$ pcp_watchdog_info -h 172.72.6.35 -p 9898 -U pgpool

  3. Password:

  4. 3 3 YES 172.72.6.32:9999 Linux lhrpg32 172.72.6.32


  5. 172.72.6.32:9999 Linux lhrpg32 172.72.6.32 9999 9000 4 LEADER 0 MEMBER

  6. 172.72.6.30:9999 Linux lhrpg30 172.72.6.30 9999 9000 7 STANDBY 0 MEMBER

  7. 172.72.6.31:9999 Linux lhrpg31 172.72.6.31 9999 9000 7 STANDBY 0 MEMBER

Failover

  1. [postgres@lhrpg30 ~]$ psql -h 172.72.6.35 -p 9999 -U pgpool postgres -c 'show pool_nodes'

  2. node_id | hostname | port | status | pg_status | lb_weight | role | pg_role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change

  3. ---------+-------------+------+--------+-----------+-----------+---------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------

  4. 0 | 172.72.6.30 | 5432 | up | up | 0.333333 | primary | primary | 0 | true | 0 | | | 2022-02-24 10:59:29

  5. 1 | 172.72.6.31 | 5432 | up | up | 0.333333 | standby | standby | 0 | false | 0 | | | 2022-02-24 10:59:29

  6. 2 | 172.72.6.32 | 5432 | up | up | 0.333333 | standby | standby | 0 | false | 0 | | | 2022-02-24 10:59:29

  7. (3 rows)

停止节点1的PG数据库,

  1. [postgres@lhrpg30 ~]$ pg_ctl -D /var/lib/pgsql/14/data -m immediate stop

  2. waiting for server to shut down.... done

  3. server stopped

在关闭server1
上的PG后,failover自动发生,节点3成为新的主库:


  1. [postgres@lhrpg30 ~]$ psql -h 172.72.6.35 -p 9999 -U pgpool postgres -c 'show pool_nodes'

  2. node_id | hostname | port | status | pg_status | lb_weight | role | pg_role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change

  3. ---------+-------------+------+--------+-----------+-----------+---------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------

  4. 0 | 172.72.6.30 | 5432 | down | down | 0.333333 | standby | unknown | 0 | false | 0 | | | 2022-02-24 11:17:21

  5. 1 | 172.72.6.31 | 5432 | up | up | 0.333333 | standby | standby | 0 | true | 0 | | | 2022-02-24 10:59:29

  6. 2 | 172.72.6.32 | 5432 | up | up | 0.333333 | primary | primary | 0 | false | 0 | | | 2022-02-24 10:59:29

  7. (3 rows)

在线恢复

恢复之前宕掉的server1主机:

  1. [postgres@lhrpg30 ~]$ pcp_recovery_node -h 172.72.6.35 -p 9898 -U pgpool -n 0

  2. Password:

  3. pcp_recovery_node -- Command Successful

可以看到,server1
作为一个standby存在:

  1. [postgres@lhrpg30 ~]$ psql -h 172.72.6.35 -p 9999 -U pgpool postgres -c 'show pool_nodes'

  2. node_id | hostname | port | status | pg_status | lb_weight | role | pg_role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change

  3. ---------+-------------+------+--------+-----------+-----------+---------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------

  4. 0 | 172.72.6.30 | 5432 | up | up | 0.333333 | standby | standby | 0 | false | 280 | | | 2022-02-24 11:30:11

  5. 1 | 172.72.6.31 | 5432 | up | up | 0.333333 | standby | standby | 0 | false | 280 | | | 2022-02-24 10:59:29

  6. 2 | 172.72.6.32 | 5432 | up | up | 0.333333 | primary | primary | 0 | true | 0 | | | 2022-02-24 11:30:00

  7. (3 rows)

读写分离+负载均衡

  1. [postgres@lhrpg30 ~]$ for i in $(seq 1 20); do psql -U pgpool -h 172.72.6.35 -p 9999 -d postgres -c 'SELECT inet_server_addr()'; done | egrep '172.'

  2. 172.72.6.31

  3. 172.72.6.32

  4. 172.72.6.32

  5. 172.72.6.30

  6. 172.72.6.30

  7. 172.72.6.30

  8. 172.72.6.31

  9. 172.72.6.31

  10. 172.72.6.30

  11. 172.72.6.31

  12. 172.72.6.30

  13. 172.72.6.31

  14. 172.72.6.32

  15. 172.72.6.31

  16. 172.72.6.30

  17. 172.72.6.31

  18. 172.72.6.31

  19. 172.72.6.31

  20. 172.72.6.31

  21. 172.72.6.32

  22. [postgres@lhrpg30 ~]$ for i in $(seq 1 20); do psql -U pgpool -h 172.72.6.35 -p 9999 -d postgres -c 'SELECT inet_server_addr()'; done | egrep '172.' | grep 31

  23. 172.72.6.31

  24. 172.72.6.31

  25. 172.72.6.31

  26. 172.72.6.31

  27. [postgres@lhrpg30 ~]$ for i in $(seq 1 20); do psql -U pgpool -h 172.72.6.35 -p 9999 -d postgres -c 'SELECT inet_server_addr()'; done | egrep '172.' | grep 32

  28. 172.72.6.32

  29. 172.72.6.32

  30. 172.72.6.32

  31. 172.72.6.32

  32. 172.72.6.32

  33. 172.72.6.32

  34. [postgres@lhrpg30 ~]$ for i in $(seq 1 20); do psql -U pgpool -h 172.72.6.35 -p 9999 -d postgres -c 'SELECT inet_server_addr()'; done | egrep '172.' | grep 30

  35. 172.72.6.30

  36. 172.72.6.30

  37. 172.72.6.30

  38. 172.72.6.30

  39. 172.72.6.30

  40. 172.72.6.30

  41. 172.72.6.30

测试之前,可以考虑修改文件pgpool.conf中的如下参数:

  1. log_statement=all

  2. log_per_node_statement =on

  3. client_min_messages =log

  4. log_min_messages = info

生效:

  1. pgpool reload

测试完成后,修改回原值:

  1. log_statement=off

  2. log_per_node_statement = off

  3. # client_min_messages =notice

  4. # log_min_messages = warning

测试过程:

  1. -- 3个窗口

  2. psql -U postgres -h 192.168.66.35 -p 9999 -d sbtest


  3. create table test(id int);

  4. insert into test values(1);

  5. select * from test;

安装pgpoolAdmin

pgpool项目还提供了一个使用PHP写的 Web管理工具,称为“pgpoolAdmin ‘,该Web管理工具可以以 Web界面方式实现pgpool-II 的配置。

The pgpool Administration Tool is management tool of pgpool. It is possible to monitor, start, stop pgpool and change setting for pgpool.

PgpoolAdmin是管理pgpool的WEB界面工具,可以对pgpool进行监控,启停服务,更改设置。

使用yum直接安装:

  1. yum install -y https://www.pgpool.net/yum/rpms/4.3/redhat/rhel-7-x86_64/pgpool-II-release-4.3-1.noarch.rpm

  2. yum install -y pgpoolAdmin

  3. ln -s /usr/share/pgpoolAdmin /var/www/html/admin


  4. -- 默认安装的php5.4版本,需要卸载掉,最低版本为:PHP 5.6.0 and higher,否则浏览器会返回500错误

  5. rpm -e php-common-5.4.16-48.el7.x86_64 --nodeps

  6. rpm -e php-process-5.4.16-48.el7.x86_64 --nodeps

  7. rpm -e php-cli-5.4.16-48.el7.x86_64 --nodeps

  8. rpm -e php-5.4.16-48.el7.x86_64 --nodeps

  9. rpm -e php-pdo-5.4.16-48.el7.x86_64 --nodeps

  10. rpm -e php-pgsql-5.4.16-48.el7.x86_64 --nodeps



  11. -- 安装httpphp

  12. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

  13. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


  14. yum -y install httpd

  15. yum install -y php72w php72w-common php72w-cli php72w-gd php72w-xml php72w-mbstring php72w-ldap \

  16. php72w-pear php72w-xmlrpc php72w-pdo \

  17. php72w-mbstring php72w-pgsql php72w-process



  18. systemctl restart httpd.service

  19. systemctl status httpd.service


  20. php -v




  21. chmod 666 /etc/pgpool-II/pgpool.conf

  22. chmod 666 /etc/pgpool-II/pcp.conf



  23. echo 'pgpooladmin:3996643de967b80174e48fb45d7227b1' >> /etc/pgpool-II/pcp.conf


  24. echo '*:*:pgpool:lhr' >> /usr/share/httpd/.pcppass

  25. echo '*:*:pgpooladmin:lhr' >> /usr/share/httpd/.pcppass


  26. chown apache:apache /usr/share/httpd/.pcppass

  27. chmod 0600 /usr/share/httpd/.pcppass



  28. -- 更新pool_passwdcat /etc/pgpool-II/pool_passwd

  29. pg_md5 --md5auth --username=pgpooladmin 'lhr'




  30. -- 数据库创建用户

  31. create user pgpooladmin login encrypted password 'lhr' superuser;

  32. grant postgres to pgpooladmin;

启动:

  1. [root@lhrpg30 ~]# netstat -tulnp | grep 80

  2. [root@lhrpg30 ~]# systemctl enable httpd

  3. Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

  4. [root@lhrpg30 ~]# systemctl start httpd

  5. [root@lhrpg30 ~]# systemctl status httpd

  6. httpd.service - The Apache HTTP Server

  7. Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

  8. Active: active (running) since Thu 2022-02-24 12:52:59 CST; 3s ago

  9. Docs: man:httpd(8)

  10. man:apachectl(8)

  11. Main PID: 27358 (httpd)

  12. Status: 'Processing requests...'

  13. CGroup: /docker/7d7822b7277ed674bd973fcd9267cd9c0c28d62d21143aa5650c4e0b2d497253/system.slice/httpd.service

  14. ├─27358 /usr/sbin/httpd -DFOREGROUND

  15. ├─27359 /usr/sbin/httpd -DFOREGROUND

  16. ├─27360 /usr/sbin/httpd -DFOREGROUND

  17. ├─27361 /usr/sbin/httpd -DFOREGROUND

  18. ├─27362 /usr/sbin/httpd -DFOREGROUND

  19. └─27363 /usr/sbin/httpd -DFOREGROUND


  20. Feb 24 12:52:59 lhrpg30 systemd[1]: Starting The Apache HTTP Server...

  21. Feb 24 12:52:59 lhrpg30 httpd[27358]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.72.6.30. Set the 'ServerName' directive globally to suppress this message

  22. Feb 24 12:52:59 lhrpg30 systemd[1]: Started The Apache HTTP Server.


  23. [root@lhrpg30 ~]# netstat -tulnp | grep 80

  24. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27358/httpd

第一次使用,需要进行配置:

配置完成之后,提示会说删除install目录。

  1. rm -rf /var/www/html/admin/install

最后使用在pcp.conf中的用户名密码登录。

登陆:http://172.72.6.30/admin/login.php ,用户名和密码:pgpooladmin/lhr


可以在界面进行操作进行switchover。

错误解决

可以正常进入登录界面,但是输入用户名和密码后,报错“500 Internal Server Error”,如下:


解决:php版本太低,最低需要PHP 5.6.0,请升级您的php版本。



预告 | 2021 PG亚洲大会12月与您相约
PG ACE计划的正式发布
三期PostgreSQL国际线上沙龙活动的举办
六期PostgreSQL国内线上沙龙活动的举办

中国PostgreSQL分会与腾讯云战略合作协议签订

中国PostgreSQL分会与美创科技战略合作协议签订
中国PostgreSQL分会与中软国际战略合作协议签订
中国PostgreSQL分会“走进”北京大学
中国PostgreSQL分会“走进”深圳大学
PGFans社区核心用户点亮计划

PostgreSQL 14.0 正式发布

深度报告:开源协议那些事儿

从“非主流”到“潮流”,开源早已值得拥有

Oracle中国正在进行新一轮裁员,传 N+6 补偿

PostgreSQL与MySQL版权比较

新闻|Babelfish使PostgreSQL直接兼容SQL Server应用程序

四年三冠,PostgreSQL再度荣获“年度数据库”

中国PostgreSQL分会入选工信部重点领域人才能力评价机构


更多新闻资讯行业动态技术热点,请关注中国PostgreSQL分会官方网站

https://www.postgresqlchina.com

中国PostgreSQL分会生态产品

https://www.pgfans.cn

中国PostgreSQL分会资源下载站

https://www.postgreshub.cn


点击此处阅读原文

↓↓↓

文章转载自开源软件联盟PostgreSQL分会,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论