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. CSharp陷阱1

    CSharp陷阱1 环境:sharpdevelop 3     .net 2.0 正确的        internal static readonly string[] string_2 = new ...

  2. where_1

    (二)WHERE //where不单独使用,与match,optional match,start,with搭配 where 与match,optional match 一起用,表示约束 where ...

  3. 使用mysql proxy对数据库进行读写分离

    服务器安排如下: 192.168.100.128 主 192.168.100.129 从 192.168.100.130 mysql-proxy 1.在100.130中下载安装mysql-proxy ...

  4. 【WebService】WebService之CXF的拦截器(五)

    CXF拦截器介绍 CXF拦截器是功能的主要实现单元,也是主要的扩展点,可以在不对核心模块进行修改的情况下,动态添加功能.当服务被调用时,会经过多个拦截器链(Interceptor Chain)处理,拦 ...

  5. 初步认识linux的top命令

    今天学习了一下top命令,强大无比啊! top命令涉及到的东西很多.用来监视系统的运行状态,top打印包括cpu.内存.进程使用情况的统计信息,还打印出进程列表. 输入top命令,不带任何参数,默认打 ...

  6. rails 表单中默认值

    在表单中加入默认提示值,如(email@email.com): <div class="field"> <%= form.label :email,"E ...

  7. 52.tableViewCell重用机制避免重复显示问题

    表刷新超出页面显示的内容会重复出现 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSInd ...

  8. 2018.10.24 NOIP模拟 小 C 的序列(链表+数论)

    传送门 考虑到a[l],gcd(a[l],a[l+1]),gcd(a[l],a[l+1],a[l+2])....gcd(a[l]...a[r])a[l],gcd(a[l],a[l+1]),gcd(a[ ...

  9. mongoDB的安装与连接

    1.安装mongoDB 官网下载安装: https://www.mongodb.com/download-center/community 安装时选择自定义设置,安装到C盘program Files文 ...

  10. shell 脚本学习之read

    Read的一些选项 Read可以带有-a, -d, -e, -n, -p, -r, -t, 和 -s八个选项. -a :将内容读入到数值中 echo -n 'please enter:'read -a ...