postgresql 主從 patroni

1 安裝基礎包html

1.1 postgresnode

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 -ypython

1.2 patronigit

yum install python36 python36-devel -y github

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

python3.6 /tmp/get-pip.py數據庫

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

 

2 配置, 簡單democentos

2.1 配置 pg 超級用戶密碼,流複製用戶權限及密碼,pg_hba.conf    api

  create user replicator replication login encrypted password 'replicator';

  

local all all trust host all all 127.0.0.1/32 trust # IPv4 local connections: host all all 10.1.0.0/16 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. local replication all trust host replication all 127.0.0.1/32 trust host replication all 10.1.0.0/16 md5 host replication all ::1/128                 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:8008 connect_address: 10.1.88.82:8008 etcd: hosts: 10.1.88.81:2379,10.1.88.82:2379,10.1.88.83:2379 #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: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 20485760 master_start_timeout: 300 # synchronous_mode: false postgresql: use_pg_rewind: true use_slots: false parameters: listen_addresses: "*" port: 5432 wal_level: logical hot_standby: "on" wal_keep_segments: 1000 max_wal_senders: 10 #synchronous_standby_names: '*' max_connections: 150 max_replication_slots: 10 wal_log_hints: "on" postgresql: listen: 0.0.0.0:5432 connect_address: 10.1.88.82:5432 # local ip data_dir: /var/lib/pgsql/10/data bin_dir: /usr/pgsql-10/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: 5 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=0 [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

相關文章
相關標籤/搜索