PostgreSQL
 sql >> Teknologi Basis Data >  >> RDS >> PostgreSQL

Instalasi PostgreSQL Ketersediaan Tinggi Patroni

Halo, hari ini saya akan menjelaskan pemasangan patroni ketersediaan tinggi.

Instalasi perangkat lunak 1-PostgreSQL
Instalasi perangkat lunak 2-Patroni
Instalasi perangkat lunak 3-etcd, dll.Konf.
Konferensi 4-patroni
pengaturan dan konfigurasi 5-pgbackrest
6-haproxy dan tetap hidup
7-Semua conf lainnya

Perangkat Lunak PostgreSQL

yum install -y postgresql12-server postgresql12-client postgresql12-contrib postgresql12-devel

Perangkat Lunak Patroni

export PATH="$PATH:/usr/pgsql-12/bin"

yum install -y python3-pip-9.0.3-5.el7.noarch gcc python3-devel

pip3 install --upgrade pip wheel
pip3 install psycopg2-binary
pip3 install psycopg2>=2.5.4
pip3 install patroni[etcd]

instalasi etcd dan conf

yum install -y etcd
--vi /etc/etcd/etcd.conf
##--pgdb-1
ETCD_INITIAL_CLUSTER="etcd1=http://xxx.xxx.xx.xx:2380,etcd2=http://xxx.xxx.xx.xx:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://xxx.xxx.xx.xx:2380"
ETCD_LISTEN_CLIENT_URLS="http://xxx.xxx.xx.xx:2379,http://127.0.0.1:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://xxx.xxx.xx.xx:2379"
ETCD_NAME="etcd1"

##--pgdb-2
ETCD_INITIAL_CLUSTER="etcd1=http://xxx.xxx.xx.xx:2380,etcd2=http://xxx.xxx.xx.xx:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://xxx.xxx.xx.xx:2380"
ETCD_LISTEN_CLIENT_URLS="http://xxx.xxx.xx.xx:2379,http://127.0.0.1:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://xxx.xxx.xx.xx:2379"
ETCD_NAME="etcd2"

systemctl enable etcd
systemctl start etcd
systemctl status etcd
systemctl stop etcd

Konferensi Patroni.

Direktori dibuat untuk file patroni yaml. dan postgres diotorisasi

mkdir /etc/patroni/
chown postgres:postgres /etc/patroni/

mkdir /postgres/
chown postgres:postgres /postgres/

–// File yml harus diatur sesuai dengan alamat IP server dan memori dll. sesuai dengan sumber daya server. pengaturan harus dibuat.

scope: pgdb-patroni
name: postgres1
restapi:
listen: xxx.xxx.xx.xx:8008
connect_address: xxx.xxx.xx.xx:8008
etcd:
hosts: 1xxx.xxx.xx.xx:2379,xxx.xxx.xx.xx:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
parameters:
wal_level: hot_standby
hot_standby: "on"
wal_keep_segments: 8
max_wal_senders: 10
max_replication_slots: 10
wal_log_hints: "on"
max_connections: 200
shared_buffers: 1GB
effective_cache_size: 3GB
maintenance_work_mem: 256MB
checkpoint_completion_target: 0.7
wal_buffers: 16MB
default_statistics_target: 100
random_page_cost: 1.1
effective_io_concurrency: 300
work_mem: 5242kB
min_wal_size: 1GB
max_wal_size: 4GB
max_worker_processes: 2
max_parallel_workers_per_gather: 1
max_parallel_workers: 2
max_parallel_maintenance_workers: 1
archive_mode: "on"
archive_timeout: 1800s
archive_command: "pgbackrest --stanza=pgdb-patroni archive-push %p"
recovery_conf:
restore_command: "pgbackrest --stanza=pgdb-patroni archive-get %f %p"
standby_mode: "on"

initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator xxx.xxx.xx.xx/24 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: xxx.xxx.xx.xx:5432
connect_address: xxx.xxx.xx.xx:5432
data_dir: /postgres/data/
bin_dir: /usr/pgsql-12/bin
pgpass: /tmp/pgpass0
authentication:
replication:
username: replicator
password: rep-pass
superuser:
username: postgres
password: postgres
rewind:
username: rewind_user
password: rewind_password
parameters:
unix_socket_directories: '/var/run/postgresql/'
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false

scope: pgdb-patroni
name: postgres2
restapi:
listen: xxx.xxx.xx.xx:8008
connect_address: xxx.xxx.xx.xx:8008
etcd:
hosts: xxx.xxx.xx.xx:2379,xxx.xxx.xx.xx:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
parameters:
wal_level: hot_standby
hot_standby: "on"
wal_keep_segments: 8
max_wal_senders: 10
max_replication_slots: 10
wal_log_hints: "on"
max_connections: 200
shared_buffers: 1GB
effective_cache_size: 3GB
maintenance_work_mem: 256MB
checkpoint_completion_target: 0.7
wal_buffers: 16MB
default_statistics_target: 100
random_page_cost: 1.1
effective_io_concurrency: 300
work_mem: 5242kB
min_wal_size: 1GB
max_wal_size: 4GB
max_worker_processes: 2
max_parallel_workers_per_gather: 1
max_parallel_workers: 2
max_parallel_maintenance_workers: 1
archive_mode: "on"
archive_timeout: 1800s
archive_command: "pgbackrest --stanza=pgdb-patroni archive-push %p"
recovery_conf:
restore_command: "pgbackrest --stanza=pgdb-patroni archive-get %f %p"
standby_mode: "on"
initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator xxx.xxx.xx.xx/24 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: xxx.xxx.xx.xx:5432
connect_address: xxx.xxx.xx.xx:5432
data_dir: /postgres/data/
bin_dir: /usr/pgsql-12/bin
pgpass: /tmp/pgpass0
authentication:
replication:
username: replicator
password: rep-pass
superuser:
username: postgres
password: postgres
rewind:
username: rewind_user
password: rewind_password
parameters:
unix_socket_directories: '/var/run/postgresql/'
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
patroni service is created

 more /etc/systemd/system/patroni.service


[Unit]
Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target

[Service]
Type=simple
User=postgres
Group=postgres
ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml
KillMode=process
TimeoutSec=30
Restart=no

[Install]
WantedBy=multi-user.target

systemctl enable patroni
systemctl start patroni
systemctl status patroni
systemctl stop patroni
journalctl -xe -f -u patron

Conf yang sama dibuat di server lain dan layanan dijalankan.

patronictl -d xxx.xxx.xx.xx list pgdb-patroni

+ Cluster: pgdb-patroni (xxx.xxx.xx.xx) -+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+---------------+--------+---------+----+-----------+
| postgres1 | xxx.xxx.xx.xx | Leader | running | 1 | |
| postgres2 | xxx.xxx.xx.xx | | running | 1 | 0 |
+-----------+---------------+--------+---------+----+-----------+

Note: Since we haven't installed pgbackrest until now, we may get an error when installing postgresql via patroni on 2.
If we restart patroni services after installing backrest, the problem will be solved. Or you can set up a backrest before starting these patrons.
patronictl -d xxx.xxx.xx.xx list pgdb-patroni

patronictl -d xxx.xxx.xx.xx reinit pgdb-patroni

patronictl -c /etc/patroni/patroni.yml list




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Deklaratif SQLAlchemy:mendefinisikan pemicu dan indeks (Postgres 9)

  2. PostgreSQL mengonversi kolom menjadi baris? Mengubah urutan?

  3. Memperbaiki lubang/kesenjangan dalam angka yang dihasilkan oleh urutan Postgres

  4. Rails:PG::UndefinedTable:ERROR:relasi ... tidak ada

  5. Bagaimana cara menginstal libpq-fe.h?