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/
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129572.html
pg_rman备份工具(下) img{ display:block; margin:0 auto !important; width:100%; } body{ width:75%; marg...
阅读 1235·2023-01-11 13:20
阅读 1543·2023-01-11 13:20
阅读 996·2023-01-11 13:20
阅读 1651·2023-01-11 13:20
阅读 3958·2023-01-11 13:20
阅读 2456·2023-01-11 13:20
阅读 1290·2023-01-11 13:20
阅读 3452·2023-01-11 13:20