一主两从+haproxy IP地址、端口、版本号根据自身的服务器和要求来改变
架构图
服务器配置
服务器四台 (192.168.0.78 192.168.0.79 192.168.0.80 192.168.0.81)
操作系统版本 Centos 7.6

CPU 192.168.0.78 192.168.0.79 192.168.0.81 | 2核 192.168.0.80 | 4核
内存 192.168.0.78 192.168.0.79 192.168.0.81 | 4G 192.168.0.80 | 8G
磁盘 四台都是200G

软件 etcd patroni python postgresql

etcd Version: 3.3.11
patroni Version : 2.1.1
python Version : 3.6
postgresql Version : 13.4

端口  :etcd  2379 2380    |    postgresql  5432    |    haproxy   7000 监听主节点端口5000   监听从节点端口5001   |    patroni   8008
etcd不仅是一个存储还是做一个数据强一致性和服务发现的作用,主要用于分布式集群当中
patroni是一个python代码的开源产品,通过DCS来对postgresql各个节点的状态进行判断

环境

 关闭防火墙  ()systemctl stop firewalld)      关闭沙盒  (setenforce 0)  永久关闭vim /etc/selinux/config   ----->   SELINUX=disabled

安装etcd

(三台都做 192.168.0.78,192.168.0.79,192.168.0.80)
yum -y install etcd
vim /etc/etcd/etcd.conf #IP地址和集群名称三台机器都不一样三台都要改

开启etcd服务 并设置开机自启
vim /usr/lib/systemd/system/etcd.service[Unit]Description=Etcd ServerAfter=network.targetAfter=network-online.targetWants=network-online.target[Service]Type=notifyWorkingDirectory=/var/lib/etcd/EnvironmentFile=-/etc/etcd/etcd.confUser=etcd# set GOMAXPROCS to number of processorsExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\""Restart=on-failureLimitNOFILE=65536[Install]WantedBy=multi-user.target查看etcd集群状态    etcdctl member list     etcdctl cluster-health

因为是patroni控制postgresql,所以安装完postgresql-13之后不用启动
**

安装postgresql13

**

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

**

安装patroni

** (三台都做 192.168.0.78,192.168.0.79,192.168.0.80)
因为postgresql用的是13版本,所以patroni要安装2.0.0以上的版本
python 环境要3以上的版本
安装python3.6版本
yum -y install python36
( 三台都做 192.168.0.78,192.168.0.79,192.168.0.80)

升级pip    wget https://bootstrap.pypa.io/get-pip.py     ----->   python3 get-pip.py
温馨提示  如果升级报错原因可能是下载的py文件版本不对   报错会提示你如何下载对应的版本   会给一个URL
安装patroniyum install -y gcc python-devel epel-releasepip3 install psycopg2-binarypip3 install --upgrade setuptoolspip3 install patroni[etcd]
编辑patroni的配置文件
mkdir  -p /usr/patroni/conf
cd /usr/patroni/conf
vim patroni_postgresql.ymlscope: pgsqlnamespace: /service/name: pgcs-0002restapi:listen: 0.0.0.0:8008connect_address: 192.168.0.79:8008etcd:host: 192.168.0.79:2379bootstrap:dcs:ttl: 30loop_wait: 10retry_timeout: 10maximum_lag_on_failover: 1048576master_start_timeout: 300synchronous_mode: falsepostgresql:use_pg_rewind: trueuse_slots: trueparameters:listen_addresses: "0.0.0.0"port: 5432wal_level: logicalhot_standby: "on"wal_keep_segments: 100max_wal_senders: 10max_replication_slots: 10wal_log_hints: "on"initdb:- encoding: UTF8- locale: C- lc-ctype: zh_CN.UTF-8- data-checksumspg_hba:- host replication repl 0.0.0.0/0 md5- host all all 0.0.0.0/0 md5postgresql:listen: 0.0.0.0:5432connect_address: 192.168.0.79:5432data_dir: /var/lib/pgsql/13/databin_dir: /usr/pgsql-13/binauthentication:replication:username: replpassword: "repl91"superuser:username: postgrespassword: "postgres91"basebackup:max-rate: 100Mcheckpoint: fasttags:nofailover: falsenoloadbalance: falseclonefrom: falsenosync: false

因为是三台都安装所以配置文件需要修改 以下是需要修改的地方


配置完之后配置启动  vim /usr/lib/systemd/system/patroni.service   并设置开机自启systemctl enable patroni[Unit]Description=Runners to orchestrate a high-availability PostgreSQLAfter=syslog.target network.target[Service]Type=simpleUser=postgresGroup=postgres#StandardOutput=syslogExecStart=/usr/local/bin/patroni /usr/patroni/conf/patroni_postgresql.ymlExecReload=/bin/kill -s HUP $MAINPIDKillMode=processTimeoutSec=30Restart=no[Install]WantedBy=multi-user.target

查看patroni集群     显示一下代表 安装成功

安装haproxy 192.168.0.81
yum -y install haproxy
cd /etc/haproxy
cp haproxy.cfg haproxy.cfg.bak
vim haproxy.conf
global
maxconn 100000
log 127.0.0.1 local3 info
defaults
mode tcp
log global
retries 2
timeout queue 5s
timeout connect 5s
timeout client 60m
timeout server 60m
timeout check 15s
listen stats
mode tcp
bind 192.168.0.81:7000
stats enable
stats refresh 30s
stats uri /stats
stats auth admin:123456
stats hide-version
listen master
log global
bind 192.168.0.81:5000
mode tcp
maxconn 2000
option tcplog
option httpchk OPTIONS /master
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
server db78 192.168.0.78:5432 check port 8008
server db79 192.168.0.79:5432 check port 8008
server db80 192.168.0.80:5432 check port 8008
listen replicas
log global
bind 192.168.0.81:5001
mode tcp
maxconn 6000
option tcplog
option httpchk OPTIONS /replica
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server db78 192.168.0.78:5432 check port 8008
server db79 192.168.0.79:5432 check port 8008
server db80 192.168.0.80:5432 check port 8008
启动haproxy并设置开机自启
设置haproxy日志
vim /etc/rsyslog.conf
这两行取消注释
15 $ModLoad imudp
16 $UDPServerRun 514
然后在76行按照73行写
73 local7.* /var/log/boot.log
74
75
76 local2.* /var/log/haproxy.log
然后重启rsyslog和haproxy服务
haproxy页面监控

命令

手动切换   patronictl -c /usr/patroni/conf/patroni_postgresql.yml
patronictl -c /usr/patroni/conf/patroni_postgresql.yml restart pgsql  (patroni集群名字)
patronictl -c /usr/patroni/conf/patroni_postgresql.yml edit-config   进入修改配置界面   ----->将要更改的配置修改好
然后 重启集群   例如添加最大连接数  max_connections: 4000;  												

PostgreSQL高可用集群相关推荐

  1. PostgreSQL高可用集群在360的落地实战

    本文主要从以下几个方面介绍PostgreSQL高可用集群在360的落地实战 为什么选择Patroni + Etcd + PostgreSQL高可用集群方案 PostgreSQL高可用集群在360的落地 ...

  2. linux集群管理平台,基于Linux平台的高可用集群管理系统的研究与实现

    摘要: 集群管理系统的高可用性是指其能够连续地对外提供服务,本文针对集群系统的高可用性,以开源的集群搭建和管理软件KUSU为基础,以集群管理节点的双机热备份技术理论为支撑,以实现集群系统的帮障检测与业 ...

  3. Kubernetes容器集群 - harbor仓库高可用集群部署说明

    之前介绍Harbor私有仓库的安装和使用,这里重点说下Harbor高可用集群方案的部署,目前主要有两种主流的Harbor高可用集群方案:1)双主复制:2)多harbor实例共享后端存储. 一.Harb ...

  4. 【参赛作品66】快速搭建一套openGauss主备高可用集群

    作者:Sally openGauss是一款开源关系型数据库管理系统,采用木兰宽松许可证v2发行.openGauss内核早期源自PostgreSQL,深度融合华为在数据库领域多年的经验,结合企业级场景需 ...

  5. Postgresql12+Pgpool-ii 4.1高可用集群

    Postgresql12+Pgpool-ii 4.1高可用集群 注意 原文链接 postgresql12主从复制链接 一.方案 1.1 方案效果 1.1 主机配置 二.安装 2.1 postgresq ...

  6. 使用RKE部署Rancher v2.5.8 HA高可用集群

    文章目录 一 了解 Rancher 1 关于Helm 2 关于RKE 3 关于K3S 4 Rancher 名词解释 4.1 仪表盘 4.2 项目 4.3 多集群应用 4.4 应用商店 4.5 Ranc ...

  7. [转]HA高可用集群中“脑裂“问题解决

    什么是脑裂(split-brain) 在"双机热备"高可用(HA)系统中,当联系两个节点的"心跳线"断开时(即两个节点断开联系时),本来为一个整体.动作协调的H ...

  8. 数据库系列之SequoiaDB高可用集群部署(一)

    SequoiaDB作为存储引擎,支持高并发的HTAP场景.本位总结运维分析项目中使用SequoiaDB作为数据存储的高可用部署实战,并接入Kafka进行高并发的更新业务和Spark进行高并发的批量查询 ...

  9. 2021年大数据Flink(五):Standalone-HA高可用集群模式

    目录 Standalone-HA高可用集群模式 原理 操作 1.集群规划 2.启动ZooKeeper 3.启动HDFS 4.停止Flink集群 5.修改flink-conf.yaml 6.修改mast ...

最新文章

  1. IDentif.AI | 开发AI平台以快速确定包括COVID-19在内感染的治疗方案
  2. [MOSS 译]如何:在WEB内容查询部件中使用自定义的字段
  3. [BZOJ1030]:[JSOI2007]文本生成器(AC自动机+DP)
  4. SDUT_2012省赛热身赛1
  5. 华为交换机ssh思科交换机_华为交换机 ssh 配置(极简版)
  6. HTML列表标签,大牛最佳总结
  7. Javascript乱弹设计模式系列(1) - 观察者模式(Observer)
  8. SVN ---文件加锁,执行clean up命令
  9. solaris系统修改密码步骤
  10. [亲测可用] Mac PS CC2019软件下载详细安装教程
  11. Linux内核Makefile.txt文件翻译
  12. Golang 企业级web后端框架
  13. 自定义view之无限滚动的刻度尺
  14. 软件测试基础知识学习
  15. 计算机研究生就业方向之去央企(国企)信息化部门
  16. 多线程比串行进程多出的优势在哪里
  17. Struts2的常量及配置:
  18. 时间管理软件 压力测试软件JMeter 微信小程序可视化代码生成 黑客网站
  19. The request client is not a secure context and the resource is in more-private address space private
  20. Pyecharts 静态图片输出ppt中动态图表

热门文章

  1. 我的世界java版刷雪球机,我的世界手机版怎么刷雪球 无限刷雪球机
  2. Windows10 UEFI+GPT模式(解决更新显示UEFI布局问题)
  3. 计算机开机壁纸能不能更换,如何修改电脑开机的背景图片
  4. [二级C]专题习题-二维数组
  5. 现代计算机之父—冯·诺依曼
  6. 已知正方形面积求边长c语言,正方形知道面积怎么求边长.
  7. [转]浅说软件需求分析
  8. tidymodels绘制校准曲线
  9. 三极管工作原理图解,快速了解三极管结构和工作原理
  10. 中国虚拟邮箱软件行业市场供需与战略研究报告