pacemaker+corosync 搭建一主两从PG集群
在搭建一主两从的PG集群时,可以使用Pacemaker和Corosync。以下是一个简化的步骤和配置示例:
- 安装Pacemaker和Corosync:
sudo apt-get install pacemaker corosync
- 配置PostgreSQL,确保数据库已经初始化并可以正常启动。
- 配置Corosync,编辑
/etc/corosync/corosync.conf
,例子如下:
totem {
version: 2
secauth: off
cluster_name: pgcluster
transport: udpu
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/corosync.log
to_syslog: yes
syslog_facility: daemon
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
ver: 0
name: pacemaker
}
- 启动并激活Corosync服务:
sudo systemctl start corosync
sudo systemctl enable corosync
- 配置Pacemaker,添加PostgreSQL资源。
- 启动并激活Pacemaker服务:
sudo systemctl start pacemaker
sudo systemctl enable pacemaker
- 使用
pcs
工具添加一主两从的PostgreSQL资源。例子如下:
pcs resource create pg_master ocf:heartbeat:pg \
op start timeout=60s \
op stop timeout=60s \
op monitor interval=20s timeout=60s \
--master \
--clone \
--order=2000 \
--failure-action=promote \
--resource-stickiness=100
pcs resource create pg_slave_1 ocf:heartbeat:pg \
op start timeout=60s \
op stop timeout=60s \
op monitor interval=20s timeout=60s \
--slave \
--clone \
--order=2000 \
--failure-action=promote \
--resource-stickiness=100
pcs resource create pg_slave_2 ocf:heartbeat:pg \
op start timeout=60s \
op stop timeout=60s \
op monitor interval=20s timeout=60s \
--slave \
--clone \
--order=2000 \
--failure-action=promote \
--resource-stickiness=100
pcs constraint colocation add pg_master with pg_slave_1 pg_slave_2
pcs constraint order then pg_slave_1 then pg_slave_2
- 检查并保存配置:
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs configure show
pcs cluster setup --name pgcluster --start --quorum=2 pg1 pg2 pg3
- 将服务添加到集群:
pcs resource enable pg_master
pcs resource enable pg_slave
评论已关闭