pacemaker+corosync 搭建一主两从PG集群

在搭建一主两从的PG集群时,可以使用Pacemaker和Corosync。以下是一个简化的步骤和配置示例:

  1. 安装Pacemaker和Corosync:



sudo apt-get install pacemaker corosync
  1. 配置PostgreSQL,确保数据库已经初始化并可以正常启动。
  2. 配置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
}
  1. 启动并激活Corosync服务:



sudo systemctl start corosync
sudo systemctl enable corosync
  1. 配置Pacemaker,添加PostgreSQL资源。
  2. 启动并激活Pacemaker服务:



sudo systemctl start pacemaker
sudo systemctl enable pacemaker
  1. 使用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
  1. 检查并保存配置:



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
  1. 将服务添加到集群:



pcs resource enable pg_master
pcs resource enable pg_slave
none
最后修改于:2024年09月01日 13:34

评论已关闭

推荐阅读

DDPG 模型解析,附Pytorch完整代码
2024年11月24日
DQN 模型解析,附Pytorch完整代码
2024年11月24日
AIGC实战——Transformer模型
2024年12月01日
Socket TCP 和 UDP 编程基础(Python)
2024年11月30日
python , tcp , udp
如何使用 ChatGPT 进行学术润色?你需要这些指令
2024年12月01日
AI
最新 Python 调用 OpenAi 详细教程实现问答、图像合成、图像理解、语音合成、语音识别(详细教程)
2024年11月24日
ChatGPT 和 DALL·E 2 配合生成故事绘本
2024年12月01日
omegaconf,一个超强的 Python 库!
2024年11月24日
【视觉AIGC识别】误差特征、人脸伪造检测、其他类型假图检测
2024年12月01日
[超级详细]如何在深度学习训练模型过程中使用 GPU 加速
2024年11月29日
Python 物理引擎pymunk最完整教程
2024年11月27日
MediaPipe 人体姿态与手指关键点检测教程
2024年11月27日
深入了解 Taipy:Python 打造 Web 应用的全面教程
2024年11月26日
基于Transformer的时间序列预测模型
2024年11月25日
Python在金融大数据分析中的AI应用(股价分析、量化交易)实战
2024年11月25日
AIGC Gradio系列学习教程之Components
2024年12月01日
Python3 `asyncio` — 异步 I/O,事件循环和并发工具
2024年11月30日
llama-factory SFT系列教程:大模型在自定义数据集 LoRA 训练与部署
2024年12月01日
Python 多线程和多进程用法
2024年11月24日
Python socket详解,全网最全教程
2024年11月27日