首页 > 数据库 >PostgreSQL 13 pacemaker 高可用集群

PostgreSQL 13 pacemaker 高可用集群

时间:2023-04-01 17:23:58浏览次数:58  
标签:13 PostgreSQL pcs proxysql01 pgsql select pacemaker clw hd

环境介绍

 

操作系统版本

CentOS Linux release 7.8.2003 (Core)  

数据库版本

psql (13.10)   

PCS集群版本

[root@hd-clw-select-proxysql01 ~]#  rpm -qa|grep pacemaker

pacemaker-libs-1.1.23-1.el7_9.1.x86_64

pacemaker-cli-1.1.23-1.el7_9.1.x86_64

pacemaker-1.1.23-1.el7_9.1.x86_64

pacemaker-cluster-libs-1.1.23-1.el7_9.1.x86_64

 

[root@hd-clw-select-proxysql01 ~]#  rpm -qa|grep pcs

pcsc-lite-libs-1.8.8-8.el7.x86_64

pcs-0.9.169-3.el7.centos.3.x86_64

 

[root@hd-clw-select-proxysql01 ~]#  rpm -qa|grep corosync

corosynclib-2.4.5-7.el7_9.2.x86_64

corosync-2.4.5-7.el7_9.2.x86_64

 

172.26.181.25  虚拟机物理ip

172.26.181.26  虚拟机物理ip

172.26.181.136 读写 vip

172.26.181.137 只读 vip

 

PG 安装包

[root@hd-clw-select-proxysql01 opt]# ll postgresql13*

-rw------- 1 root root 1485584 Mar 15 16:38 postgresql13-13.10-1PGDG.rhel7.x86_64.rpm

-rw------- 1 root root  629284 Mar 15 16:39 postgresql13-contrib-13.10-1PGDG.rhel7.x86_64.rpm

-rw------- 1 root root  393964 Mar 15 16:40 postgresql13-libs-13.10-1PGDG.rhel7.x86_64.rpm

-rw------- 1 root root 5615388 Mar 15 16:52 postgresql13-server-13.10-1PGDG.rhel7.x86_64.rpm

[root@hd-clw-select-proxysql01 opt]# ll resource-agents-4.12.0.zip

-rw------- 1 root root 1149827 Mar 15 14:37 resource-agents-4.12.0.zip

 

PG软件包下载地址:https://yum.postgresql.org/13/redhat/rhel-7-x86_64/repoview/

resource-agents-4.12.0 下载地址:  https://github.com/ClusterLabs/resource-agents/releases/tag/v4.12.0

 

一、安装基础软件

1. 配置 hostname [all servers]

[root@hd-clw-select-proxysql01 ~]# more /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

172.26.181.25 hd-clw-select-proxysql01

172.26.181.26 hd-clw-select-proxysql02

 

2. 关闭 firewalld and selinux[all servers]

# systemctl disable firewalld

# systemctl stop firewalld

# systemctl status firewalld

# sestatus

SELinux status:                 disabled

3. 安装 pcs[all servers]

# yum -y install libsmb*

# yum install -y pacemaker pcs

# yum install  -y autoconf automake libtool

# yum install   -y docbook-style-xsl

# yum install   -y gcc-c++ glib2-devel

4.pacemaker resource-agents 更新 [all servers]

# unzip resource-agents-4.8.0.zip

# cd resource-agents-4.8.0

# ./autogen.sh

# ./configure

# make && make install

 

确认支持PG12以上版本

/usr/lib/ocf/resource.d/heartbeat/pgsql文件,1918 行,包含ocf_version_cmp "$version" "12"

图片

5.pcsd[all servers]

# echo "hacluster"| passwd --stdin hacluster

6.安装postgresql数据库软件 [all servers]

rpm -ivh  postgresql13-libs-13.10-1PGDG.rhel7.x86_64.rpm

rpm -ivh  postgresql13-13.10-1PGDG.rhel7.x86_64.rpm

rpm -ivh  postgresql13-server-13.10-1PGDG.rhel7.x86_64.rpm

rpm -ivh  postgresql13-contrib-13.10-1PGDG.rhel7.x86_64.rpm

7.service setup [all servers]

systemctl disable postgresql-13.service

systemctl disable corosync

systemctl disable pacemaker

systemctl enable pcsd.service

systemctl start pcsd.service

8.cluster auth[any one host]

# pcs cluster auth hd-clw-select-proxysql01 hd-clw-select-proxysql02  -u hacluster -p "hacluster" 

9.设置数据库集群[any one host] 

#### 配置集群节点 ####

# pcs cluster setup --name cluster_pg01 hd-clw-select-proxysql01 hd-clw-select-proxysql02

#### 启动所有集群节点 ####

# pcs cluster start --all

#### 检查集群状态 ####

# pcs status --full

10.数据库目录配置[all servers]

# mkdir /pgdata

# chown postgres.postgres /pgdata/

# chmod 700 /pgdata/

11.数据库用户环境变量配置[all servers]

# su - postgres

$ cat  .bash_profile

[ -f /etc/profile ] && source /etc/profile

PGDATA=/pgdata

export PGDATA

export PATH=/usr/pgsql-13/bin:$PATH

# If you want to customize your settings,

# Use the file below. This is not overridden

# by the RPMS.

[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile

 

12.primary数据库配置 [hd-clw-select-proxysql01]

#### hd-clw-select-proxysql01 ####

1).初始化数据库

# su - postgres

$ initdb -D /pgdata/

2).配置主机访问

$ vi pg_hba.conf

# replication privilege.

local   replication     all                                     trust

host    replication     all             127.0.0.1/32            trust

host    replication     replic_user     172.26.181.0/24       md5

host    all             all             0.0.0.0/0             md5

 3).配置数据库参数 (这里仅测试环境pg参数,生产环境需要详细配置)

$ vi postgresql.conf

 listen_addresses = '*' 

wal_keep_size = 10240 # wal keep files size

4).创建复制用户

 $ pg_ctl start

waiting for server to start....2021-06-06 00:28:55.991 CST [13488] LOG:  redirecting log output to logging collector process

2021-06-06 00:28:55.991 CST [13488] HINT:  Future log output will appear in directory "log".

 done

server started

-bash-4.2$ psql

psql (13.10)

Type "help" for help.

postgres=# create user replic_user with replication password 'replic_user';

CREATE ROLE

postgres=# \du

图片

 

13.创建secondary数据库 [hd-clw-select-proxysql02]

#### create secondary server ####

$ cd /pgdata/

$ pg_basebackup -h hd-clw-select-proxysql01 -U replic_user -D /pgdata/ -P -v

Password:

pg_basebackup: initiating base backup, waiting for checkpoint to complete

pg_basebackup: checkpoint completed

pg_basebackup: write-ahead log start point: 0/A000028 on timeline 1

pg_basebackup: starting background WAL receiver

pg_basebackup: created temporary replication slot "pg_basebackup_13.102"

24987/24987 kB (100%), 1/1 tablespace

pg_basebackup: write-ahead log end point: 0/A000100

pg_basebackup: waiting for background process to finish streaming ...

pg_basebackup: syncing data to disk ...

pg_basebackup: renaming backup_manifest.tmp to backup_manifest

pg_basebackup: base backup completed

14.停止primary数据库 [hd-clw-select-proxysql01]

$ pg_ctl stop

waiting for server to shut down.... done

server stopped

二、配置pacemaker数据库集群 [any one host] (一个节点配置即可,会自动同步到另外一个节点)

 

1.检查集群状态

# pcs status

Cluster name: cluster_pg01

WARNINGS:

No stonith devices and stonith-enabled is not false

Stack: corosync

Current DC: hd-clw-select-proxysql01 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum

Last updated: Sun Jun  6 00:53:57 2021

Last change: Sun Jun  6 00:11:48 2021 by hacluster via crmd on hd-clw-select-proxysql01

3 nodes configured

 resource instances configured

Online: [ hd-clw-select-proxysql01 hd-clw-select-proxysql02  ]

No resources

Daemon Status:

 corosync: active/disabled

pacemaker: active/disabled

pcsd: active/enabled

 

#

 

2.创建集群文件

 

# pcs cluster cib cib.xml

# ll

total 4

-rw-r--r-- 1 root root 1672 Jun  6 00:52 cluster_pg13.xml

#

 

3.配置数据库资源

 

# property: cluster-name

pcs -f cib.xml property set cluster-name="pg_cluster_01"

# property: disable stonith, quorum

pcs -f cib.xml property set no-quorum-policy="ignore"

pcs -f cib.xml property set stonith-enabled="false"

# resource: master-vip

pcs -f cib.xml resource create master-vip ocf:heartbeat:IPaddr2 \ ip=172.26.181.136 cidr_netmask=24 nic=ens160 iflabel=master op monitor interval=5s

 

# resource: replica-vip

pcs -f cib.xml resource create replica-vip ocf:heartbeat:IPaddr2 \ ip=172.26.181.137 cidr_netmask=24 nic=ens160 iflabel=replica op monitor interval=5s

# resource: pgsql

pcs -f cib.xml resource create pgsql ocf:heartbeat:pgsql \

    pgctl="/usr/pgsql-13/bin/pg_ctl" \

    psql="/usr/pgsql-13/bin/psql" \

    pgdata="/pgdata" \

    node_list="hd-clw-select-proxysql01 hd-clw-select-proxysql02" \

    restore_command="" \

    master_ip="172.26.181.136" \

    repuser="replic_user" \

    rep_mode="sync" \

    primary_conninfo_opt="password=replic_user keepalives_idle=60 keepalives_interval=5 keepalives_count=5" \

    op monitor interval="11s" \

    op monitor interval="10s" role="Master" \

    master master-max=1 master-node-max=1 clone-max=3 clone-node-max=1 notify=true target-role='Started'

# constraint: master-vip, pgsql on master node

pcs -f cib.xml constraint colocation add master-vip with master pgsql-master INFINITY

# constraint: pgsql promote  node  MasterGroup 

pcs -f cib.xml constraint order promote pgsql-master then start master-vip symmetrical=false score=INFINITY

# constraint: pgsql demote  node  MasterGroup 

pcs -f cib.xml constraint order demote pgsql-master then stop master-vip symmetrical=false score=0

# constraint: replica-vip  sync standby 、sync standby on master

pcs -f cib.xml constraint location replica-vip rule score=200 pgsql-status eq HS:sync

pcs -f cib.xml constraint location replica-vip rule score=100 pgsql-status eq PRI

pcs -f cib.xml constraint location replica-vip rule score=-INFINITY not_defined pgsql-status

pcs -f cib.xml constraint location replica-vip rule score=-INFINITY pgsql-status ne HS:sync and pgsql-status ne PRI

# cluster: push cib file into cib

pcs cluster cib-push cib.xml

 

4.刷新集群状态

# pcs resource refresh --full

Waiting for 1 reply from the CRMd. OK

#

5.查询集群状态

 

[root@hd-clw-select-proxysql01 ~]#  pcs status --full

Cluster name: cluster_pg01

Stack: corosync

Current DC: hd-clw-select-proxysql01 (1) (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum

Last updated: Sat Apr  1 15:43:55 2023

Last change: Fri Mar 17 15:09:56 2023 by root via crm_attribute on hd-clw-select-proxysql01

 

2 nodes configured

5 resource instances configured

 

Online: [ hd-clw-select-proxysql01 (1) hd-clw-select-proxysql02 (2) ]

 

Full list of resources:

 

 master-vip     (ocf::heartbeat:IPaddr2):       Started hd-clw-select-proxysql01

 replica-vip    (ocf::heartbeat:IPaddr2):       Started hd-clw-select-proxysql02

 Master/Slave Set: pgsql-master [pgsql]

     pgsql      (ocf::heartbeat:pgsql): Slave hd-clw-select-proxysql02

     pgsql      (ocf::heartbeat:pgsql): Master hd-clw-select-proxysql01

     pgsql      (ocf::heartbeat:pgsql): Stopped

     Masters: [ hd-clw-select-proxysql01 ]

     Slaves: [ hd-clw-select-proxysql02 ]

 

Node Attributes:

* Node hd-clw-select-proxysql01 (1):

    + master-pgsql                      : 1000      

    + pgsql-data-status                 : LATEST    

    + pgsql-master-baseline             : 000000000F000148

    + pgsql-status                      : PRI       

* Node hd-clw-select-proxysql02 (2):

    + master-pgsql                      : 100       

    + pgsql-data-status                 : STREAMING|SYNC

    + pgsql-status                      : HS:sync   

 

Migration Summary:

* Node hd-clw-select-proxysql02 (2):

* Node hd-clw-select-proxysql01 (1):

 

Fencing History:

 

PCSD Status:

  hd-clw-select-proxysql02: Online

  hd-clw-select-proxysql01: Online

 

Daemon Status:

  corosync: active/disabled

  pacemaker: active/disabled

  pcsd: active/enabled

 参考:

PgSQL Replicated Cluster:

http://clusterlabs.org/wiki/PgSQL_Replicated_Cluster

 

就是玩,想进群聊天交流的+++微信哈!

 

标签:13,PostgreSQL,pcs,proxysql01,pgsql,select,pacemaker,clw,hd
From: https://www.cnblogs.com/andy6/p/17278951.html

相关文章

  • 202031607213-李蕊 实验一 软件工程准备--构建之法与博客首秀
    实验一软件工程准备一、实验介绍项目内容班级博客链接https://edu.cnblogs.com/campus/xbsf/2020CSSE本次作业要求链接https://edu.cnblogs.com/campus/xbsf/2020CSSE/homework/12938我的课程学习目标(1)学习博客园软件开发者学习社区使用技巧和经验。(2)了解Gi......
  • Arduino 外接 DS3132 读数为2165/165/165问题解决
    即使SCL/SDA不接线,DS3132也会返回,这个值为2165/165/165因此问题的来源为接线不牢靠。接线牢靠的标准:RTC模块(ZS-042)上的PWR灯应该常亮,并且亮度很大(我一开始接线,PWR亮度小,而且闪烁)RTC的SCL接Arduino的A4,SDA接Arduino的A5.The165indicatesthatthedatalinefor......
  • 202031607130-杨国周 实验一 软件工程准备—初识软件工程
    实验一软件工程准备项目内容班级博客链接https://edu.cnblogs.com/campus/xbsf/2020CSSE本次作业要求链接https://edu.cnblogs.com/campus/xbsf/2020CSSE/homework/12938我的课程学习目标学习软件工程的基本概念、方法和工具,提高软件开发的质量和效率。本......
  • MySQL插入数据报错:1366 Incorrect string value: '\xF0\xA0\xB9\xB3\xF0\xA0...
    [10501]SQLSTATE[22007]:Invaliddatetimeformat:1366Incorrectstringvalue:'\xF0\xA0\xB9\xB3\xF0\xA0...'forcolumnxxxxatrow1是因为MySQL不能识别4个字节的utf8编码的字符,抛出了异常。解决办法将字符类型换成改为utf8mb4数据库:ALTERDATABASE`db_name`C......
  • ENGG1310 P3.1 Electricity and Protections
    这一章虽然比较硬核,但大部分都是高中物理学过的知识并且对于高中熟知的一些公式(电压/电流有效值)之类的将会给出推导(毕竟现在会积分了),所以还是很值得学习的一part原子AtomAllMATTERSaremadeofatoms.电子electron:negativelychargedatomicparticles质子pr......
  • P1345 奶牛的电信
     题目略,就是求最小割(容量和最小的边集,使得图不联通,常用S-T割) 那么最小割=最大流这里要求点权和最小,可以通过拆点转化为边权#include<iostream>#include<algorithm>#include<cstring>#include<queue>#defineIOSstd::ios::sync_with_stdio(0)usingnamespacestd;......
  • 13
    生成器引入在Python中,使用生成器可以很方便的支持迭代器协议。生成器通过生成器函数产生,生成器函数可以通过常规的def语句来定义,但是不用return返回,而是用yield一次返回一个结果,在每个结果之间挂起和继续它们的状态,来自动实现迭代协议。也就是说,yield是一个语法糖,内部实现支持......
  • 13岁软件小天才Thomas Suarez最近在忙什么
    还记得雷锋网去年为大家介绍的软件小天才ThomasSuarez吧?当时他的演讲视频红遍全球,神情举止都酷似乔布斯,还有自己的软件公司CarrotCorp,自己开发了两款娱乐应用,这个软件小天......
  • 【题解】[HEOI2013]SAO
    题目分析:考虑这是一个树形图,所以就先直接当作树来做。这个题其实就是让我们求解有多少种拓扑序而且题目中边方向的限制其实就是在限制拓扑序的前后,而一般这种题在设计\(......
  • 第135篇:npm模块全局安装后无法使用解决方案
    好家伙 npm模块全局安装后无法使用 估计是少配了环境变量1.使用命令:npmconfiggetprefix找到全局包的安装位置  2.随后我们右键"我的电脑"打开 "属......