1 安装基础包

1.1 postgres

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm gcc -y
yum install -y postgresql10-contrib.x86_64 postgresql10-server.x86_64
yum install postgis25_10.x86_64 -y

1.2 patroni

yum install python36 python36-devel -y

curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py

python3.6 /tmp/get-pip.py

pip3 install patroni[etcd] -i https://pypi.douban.com/simple
pip install psycopg2-binary

2 配置, 简单demo

2.1 配置 pg 超级用户密码,流复制用户权限及密码,pg_hba.conf

create user replicator replication login encrypted password 'replicator';

local   all             all                                     trust
host all all 127.0.0.1/ trust
# IPv4 local connections:
host all all 10.1.0.0/ md5
# IPv6 local connections:
host all all ::/ md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/ trust
host replication all 10.1.0.0/ md5
host replication all ::/ trust

2.2 patroni 配置文件

cat /etc/patroni/patroni_postgresql.yml
scope: pgha #集群名
namespace: /pgsql/  #etcd path
name: pg_node1 # node 名称 每个节点不同 restapi:
listen: 10.1.88.82:
connect_address: 10.1.88.82: etcd:
hosts: 10.1.88.81:,10.1.88.82:,10.1.88.83:
#host: ip:port #single etd server
bootstrap:
# this section will be written into Etcd:/<namespace>/<scope>/config after initializing new cluster
# and all other cluster members will use it as a `global configuration`
dcs:
ttl:
loop_wait:
retry_timeout:
maximum_lag_on_failover:
master_start_timeout:
# synchronous_mode: false
postgresql:
use_pg_rewind: true
use_slots: false
parameters:
listen_addresses: "*"
port:
wal_level: logical
hot_standby: "on"
wal_keep_segments:
max_wal_senders:
#synchronous_standby_names: '*'
max_connections:
max_replication_slots:
wal_log_hints: "on" postgresql:
listen: 0.0.0.0:
connect_address: 10.1.88.82: # local ip
data_dir: /var/lib/pgsql//data
bin_dir: /usr/pgsql-/bin
# config_dir:
authentication:
replication:
username: replicator
password: replicator
superuser:
username: postgres
password: postgres #watchdog:
# mode: automatic # Allowed values: off, automatic, required
# device: /dev/watchdog
# safety_margin: tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false

2.3  服务配置

cat /usr/lib/systemd/system/patroni.service
[Unit]
Description=Patroni server
Documentation='https://github.com/zalando/patroni,https://www.opsdash.com/blog/postgres-getting-started-patroni.html'
After=syslog.target
After=network.target [Service]
Type=simple User=postgres
Group=postgres # StandardOutput=syslog
WorkingDirectory=/etc/patroni/
ExecStart=/usr/local/bin/patroni /etc/patroni/patroni_postgresql.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT # Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec= [Install]
WantedBy=multi-user.target

基本操作

patronictl -c /etc/patroni/patroni_postgresql.yml list

patronictl -c /etc/patroni/patroni_postgresql.yml show-config
patronictl -c /etc/patroni/patroni_postgresql.yml edit-config

删除 属性
patronictl -c /etc/patroni/patroni_postgresql.yml edit-config -s postgresql.parameters.synchronous_standby_names=null

错误 解决

data dir for the cluster is not empty, but system ID is invalid; consider doing reinitalize

patronictl -c /etc/patroni/patroni_postgresql.yml reinit pgha pg_node81

利用Restful API 动态修改数据库属性
https://patroni.readthedocs.io/en/latest/dynamic_configuration.html#dynamic-configuration

重启数据库 

patronictl -c /etc/patroni/patroni_postgresql.yml restart pgha

官方文档
https://patroni.readthedocs.io/en/latest/

英文

https://www.opsdash.com/blog/postgres-getting-started-patroni.html

https://www.linode.com/docs/databases/postgresql/create-a-highly-available-postgresql-cluster-using-patroni-and-haproxy

中文

https://blog.csdn.net/ctypyb2002/article/details/81002436

https://blog.csdn.net/ctypyb2002/article/details/81007990

https://blog.csdn.net/ctypyb2002/article/details/81206652

https://blog.csdn.net/ctypyb2002/article/details/81540288

https://blog.csdn.net/ctypyb2002/article/details/82887607

postgresql 主从 patroni的更多相关文章

  1. postgresql 主从配置

    安装postgresql 主从是否一定需要分两台机器,主从必须要同一个版本,不然启动会报错. 3. 配置Master数据库 su – postgres /usr/local/pgsql/bin/pg_ ...

  2. 再不了解PostgreSQL,你就晚了之PostgreSQL主从流复制部署

    前言 在MySQL被收购之后,虽然有其替代品为: MariaDB,但是总感觉心里有点膈应.大家发现了另一款开源的数据库: PostgreSQL. 虽然centos自带版本9.2也可以用,但是最近的几次 ...

  3. postgresql主从同步配置

    前言 不久前,公司的一台物理机器硬件坏了,导致运行在其上的虚拟机都挂了.很不凑巧的是,我负责的那台虚拟机的系统盘坏了(ps:感觉老天在玩我),导致里面的数据永远的离我而去(ps:当时我的内心是崩溃的) ...

  4. postgresql , etcd , patroni 做failover

    os: centos 7.4etcd:3.2 主从IP信息192.168.56.101 node1 master192.168.56.102 node2 slave192.168.56.103 nod ...

  5. CentOS7 PostgreSQL 主从配置( 二)

    同步流复制配置PostgreSql的流复制是异步的,缺点是Standby上的数据落后于主库上的数据,如果使用Hot Standby做读写分离,就会存在数据一致性的问题.PostgreSql9.1版本后 ...

  6. CentOS7 PostgreSQL 主从配置( 一)

    主库配置 pg_hba.conf host replication all 10.2.0.0/0 trust postgresql.conf listen_addresses = '*' max_wa ...

  7. postgresql主从配置

    master:10.0.1.114 slaver:10.0.1.116 一.yum安装https://blog.csdn.net/weixin_41048363/article/details/803 ...

  8. Ubuntu PostgreSql主从切换

    主机:192.168.100.70 从机:192.168.100.71 通用配置(即主从都要配置) 修改/etc/postgresql/10/main/pg_hba.conf host all all ...

  9. Docker部署PostgreSQL主从

    #准备 PostgreSQL12.3版本容器两台,部署参考https://www.cnblogs.com/zspwf/p/16113298.html 主库: 192.168.3.14:2200 从库: ...

随机推荐

  1. UI设计教程分享:6个不能错过的UI设计网站

    Ui设计学习的人越来越多了,想要找到合适的学习资料很难,很多才接触ui设计且没有基础的同学也不知道去哪里找学习资料,虽然现在百度上很容易搜到ui设计的学习资料,但是一看不难发现,很多都是过时的学习资料 ...

  2. centos7中输入ifconfig出现ens33,没有eth0(转)

    vmware安装的centos7中没有出现eth0网卡,也没有ip,不能上网,输入ifconfig后如下图 解决办法 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scr ...

  3. MySQL复制(Replication)

    引自:http://www.cnblogs.com/hustcat/archive/2009/12/19/1627525.html 1.复制概述 1.1.复制解决的问题数据复制技术有以下一些特点:(1 ...

  4. oracle 分组中排序(rank函数)

    需求: 查询每个供应商在每个类型产品销售的top50中有多少 分析: 1.查询,以指定字段(供应商.产品类型)分组,取每个分组的前50行,查看每个供应商的数量 2.使用rank函数给每个供应商.每个类 ...

  5. 747. Largest Number At Least Twice of Others

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  6. 从模板驱动文件ins生成cls文件

    在当前目录下,启动cmd程序,输入以下指令: latex acmart.ins

  7. php代码记录

    公司项目的随想记录也记在这里: 1,证书产生的目的是为了防止不合法的用户能够直接访问接口获取数据.证书由服务器端生成,然后返回给app.然后app拿着这个证书到服务器端获取接口数据,而不是app的合法 ...

  8. Win10通知区域图标设置;windows10系统图标合并;Windows10系统通知合并

    1.一直喜欢Windows7的通知图标合并 2.通过查阅找到方法 a.输入命令语句   win+R  :shell:::{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9} 回 ...

  9. linux将80端口映射到指定端口命令

    1.添加一个端口映射 将80端口映射到8088端口命令如下: iptables -t nat -I PREROUTING -p tcp --dport 80-j REDIRECT --to-port ...

  10. 添加wifi adb

    https://blog.csdn.net/ouyang_peng/article/details/50370786 首先弄懂怎么设置adb wifi无线调试的功能,如下所示. 1. 手机端开启adb ...