10.37.129.3 node1
10.37.129.4 node2
10.37.129.5 node3
10.37.129.6 node-vip
python3 setup.py build
python3 setup.py install
--all nodes
--標準配置:
firewalld
selinux
chrony
gcc
libpq5-devel
--PostgreSQL數據庫安裝:
postgresql12
postgresql12-server
postgresql12-libs
postgresql12-contrib
--patroni軟件需要:
etcd
python3
python3-devel
visudo
## Allow root to run any commands anywhere
postgres ALL=(root) NOPASSWD: ALL
--all nodes
--查看etcd狀態:
export ETCDCTL_API=3
export ENDPOINTS=http://10.37.129.4 :2379,http://10.37.129.5 :2379,http://10.37.129.3 :2379
etcdctl endpoint status --endpoints=$ENDPOINTS -w=table
+-------------------------+------------------+---------+---------+-----------+-----------+------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+-------------------------+------------------+---------+---------+-----------+-----------+------------+
| http://10.37.129.4 :2379 | 49bab10dd5347fa2 | 3.3.11 | 20 kB | false | 105 | 9 |
| http://10.37.129.5 :2379 | 97cdb5480a6be19f | 3.3.11 | 20 kB | false | 105 | 9 |
| http://10.37.129.3 :2379 | a2916ae27f29d955 | 3.3.11 | 20 kB | true | 105 | 9 |
+-------------------------+------------------+---------+---------+-----------+-----------+------------+
--all nodes
# 安裝軟件,linux內置功能
yum install -y watchdog
# 初始化watchdog字符設備
modprobe softdog
# 修改/dev/watchdog設備權限
chmod 666 /dev/watchdog
# 啟動watchdog服務
systemctl start watchdog
systemctl enable watchdog
--all nodes
pip3 install psycopg2==2.8.6
pip3 install patroni[etcd]
--all nodes
vi /usr/lib/systemd/system/patroni.service
[Unit]
Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target etcd.service
[Service]
Type=simple
User=postgres
Group=postgres
EnvironmentFile=-/etc/patroni/patroni_env.conf
ExecStartPre=-/usr/bin/sudo /sbin/modprobe softdog
ExecStartPre=-/usr/bin/sudo /bin/chown postgres /dev/watchdog
ExecStart=/usr/bin/env patroni /etc/patroni/patroni.yml
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
TimeoutSec=30
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
--all nodes
--yaml文件不能使用制表位。
vi /etc/patroni/patroni.yml
scope: pgsql
namespace: /service/
name: pg1
restapi:
listen: 0.0.0.0 :8008
connect_address: 10.37.129.3:8008
etcd:
hosts: 10.37.129.3:2379,10.37.129.4:2379,10.37.129.5:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
master_start_timeout: 300
synchronous_mode: false
synchronous_node_count: 2 #同步備用服務器數量為2
synchronous_mode_strict: false #沒有可用備用同步服務器情況下,阻塞主服務器會話
postgresql:
use_pg_rewind: true
use_slots: true
parameters:
listen_addresses: "0.0.0.0"
port: 5432
wal_level: replica
hot_standby: "on"
wal_keep_segments: 100
max_wal_senders: 10
max_replication_slots: 10
wal_log_hints: "on"
archive_mode: "on"
archive_timeout: 1800s
archive_command: mkdir -p . ./wal_archive && test ! -f . ./wal_archive/%f && cp %p . ./wal_archive/%f
recovery_conf:
restore_command: cp ../wal_archive/%f %p
initdb:
- encoding: UTF8
- locale: C
- lc-ctype: zh_CN.UTF-8
- data-checksums
pg_hba:
- host replication postgres 10.37.129.0/24 md5
- host all all 0.0.0.0/0 md5
postgresql:
listen: 0.0.0.0 :5432
connect_address: 10.37.129.3 :5432
data_dir: /var/lib/pgsql/12/data
bin_dir: /usr/pgsql-12/bin
authentication:
replication:
username:
postgres
"123456"
postgres
"123456"
postgres
"123456"
password:
superuser:
username:
password:
rewind:
username:
password:
basebackup:
max-rate: 100M
checkpoint: fast
watchdog:
mode: automatic # Allowed values: off, automatic, required
device: /dev/watchdog
safety_margin: 5
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
--all nodes
systemctl enable patroni
systemctl start patroni
patronictl -c /etc/patroni/patroni.yml list
+ Cluster: pgsql (6942330619575798728) ----+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+--------+-------------+---------+---------+----+-----------+
| pg1
| pg2
| pg3
|
0 |
0 |
| 10.37.129.3 | Leader | running | 1 |
| 10.37.129.4 | Replica | running | 1 |
| 10.37.129.5 | Replica | running | 1 |
http://10.37.129.3:8008/patroni
文章參考鏈接:http://blog.itpub.net/30496307/viewspace-2764349/
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129572.html
pg_rman備份工具(下) img{ display:block; margin:0 auto !important; width:100%; } body{ width:75%; marg...
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1860·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20