PostgreSQL
 sql >> डेटाबेस >  >> RDS >> PostgreSQL

PostgreSQL उच्च उपलब्धता संस्थापन Patroni

नमस्कार, आज मैं उच्च उपलब्धता संरक्षक की स्थापना के बारे में बताऊंगा।

1-PostgreSQL सॉफ़्टवेयर इंस्टॉलेशन
2-Patroni सॉफ़्टवेयर इंस्टॉलेशन
3-etcd सॉफ़्टवेयर इंस्टॉलेशन, etcd conf.
4-patroni conf.
5-pgbackrest सेटअप और conf.
6-हैप्रोक्सी और रख-रखाव
7-अन्य सभी कॉन्फिडेंस।

पोस्टग्रेएसक्यूएल सॉफ्टवेयर

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

पेट्रोनी सॉफ्टवेयर

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]

वगैरह इंस्टालेशन और कॉन्फिडेंस

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

पेट्रोनी कॉन्फ़.

निर्देशिका संरक्षक yaml फ़ाइल के लिए बनाई गई है। और पोस्टग्रेज अधिकृत है

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

mkdir /postgres/
chown postgres:postgres /postgres/

-// yml फाइल को सर्वर के आईपी एड्रेस और मेमोरी आदि के हिसाब से सर्वर रिसोर्सेज के हिसाब से सेट किया जाना चाहिए। सेटिंग्स की जानी चाहिए।

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

अन्य सर्वरों में समान कॉन्फिडेंस बनाए जाते हैं और सेवा चलती है।

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. psql में डेटाबेस कैसे स्विच करें?

  2. PostgreSQL में महीने का पहला दिन प्राप्त करें

  3. डेटा पीढ़ी और हार्डवेयर गुणवत्ता

  4. मरम्मत भ्रष्ट डेटाबेस postgresql

  5. रेल ऐप में हेरोकू पोस्टग्रेएसक्यूएल GROUP_BY त्रुटि