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. django添加装饰器

    引入模块: from django.utils.decorators import method_decorator 添加:@method_decorator(func) from django.ut ...

  2. Laravel Many to Many Polymorphic Relationship

    Many to many Polymorphic relationship is also a little bit complicated to understand. For example, i ...

  3. bootstrap 坑

    1.  表格内存出不来,也不报错 .. 值是对的..  原因是  table  中必须有属性   data-toggle="table" <table id="My ...

  4. servlet 高级知识之Listener

    Listener,顾名思义,监听器.它可以监听客户端的请求.服务端的操作等. 通过监听器,可以自动激发一些操作,比如监听在线的用户的数量.当增加一个HttpSession时,就激发sessionCre ...

  5. mybatis 为什么要设置jdbcType

    转载自:http://makemyownlife.iteye.com/blog/1610021 前天遇到一个问题 异常显示如下: 引用 Exception in thread "main&q ...

  6. windows下解决端口被占用的问题

    步骤一.Windows查看所有的端口 点击电脑左下角的开始,然后选择运行选项,接着我们在弹出的窗口中,输入[cmd]命令,进行命令提示符.然后我们在窗口中输入[netstat -ano]按下回车,即会 ...

  7. 2018.11.05 bzoj3124: [Sdoi2013]直径(树形dp)

    传送门 一道sbsbsb树形dpdpdp 第一问直接求树的直径. 考虑第二问问的边肯定在同一条直径上均是连续的. 因此我们将直径记下来. 然后对于直径上的每一个点,dpdpdp出以这个点为根的子树中不 ...

  8. 2018.11.02 NOIP模拟 距离(斜率优化dp)

    传送门 分四个方向分别讨论. 每次枚举当前行iii,然后对于第二维jjj用斜率优化dpdpdp. f[i][j]=(j−k)2+mindisk2f[i][j]=(j-k)^2+mindis_k^2f[ ...

  9. boost--signal

    1.signals2库 signals2库实现了线程安全的观察者模式,在signals2中观察者模式被称为信号/插槽(signals/slots),它是一种函数回调机制.一个信号可以关联一个或多个插槽 ...

  10. 吓死baobao了

    早上远程连接服务器连不上,后面重启服务器,显示进入紧急修复模式:welcome to emergency mode!after logging in ,type “journalctl -xb” to ...