sql >> Database teknologi >  >> RDS >> PostgreSQL

PostgreSQL installationer med høj tilgængelighed Patroni

Hej, i dag vil jeg forklare installationen af ​​høj tilgængelighed patroni.

1-PostgreSQL softwareinstallation
2-Patroni softwareinstallation
3-etcd softwareinstallation, etcd conf.
4-patroni conf.
5-pgbackrest setup and conf.
6-haproxy og keepalived
7-Alle andre konf.

PostgreSQL-software

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

Patroni-software

eksport PATH="$PATH:/usr/pgsql-12/bin"yum install -y python3-pip-9.0.3-5.el7.noarch gcc python3-develpip3 install --upgrade pip wheelpip3 install psycopg2-binarypip3 install psycopg2>=2.5.4pip3 install patroni[etcd]

etcd installation og conf

yum install -y etcd
--vi /etc/etcd/etcd.conf##--pgdb-1ETCD_INITIAL_CLUSTER="etcd1=http://xxx.xxx.xx.xx:2380,etcd2=http://xxx.xxx.xx .xx:2380"ETCD_INITIAL_CLUSTER_STATE="ny"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCD_DATA_DIR/etcd/delibault 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-2ETCD_INITIAL_CLUSTER="etcd1=http://xxx.xxx.xx.xx:2380,etcd2=http://xxx.xxx ... 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:://xxx.xxx.xx.xx:2379"ETCD_NAME="etcd2"systemctl aktiver etcdsystemctl start etcdsystemctl status etcdsystemctl stop etcd

Patroni konf.

Biblioteket er oprettet til patroni yaml-filen. og postgres er godkendt

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

–// yml-filen skal indstilles i henhold til serverens IP-adresser og hukommelse osv. i henhold til serverressourcer. indstillinger skal foretages.

scope:pgdb-patroniname:postgres1restapi:listen:xxx.xxx.xx.xx:8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:1xxx.xxx.xx.xx:2379,xxx.xxx.xx .xx:2379bootstrap:dcs:ttl:30loop_wait:10retry_timeout:10maximum_lag_on_failover:1048576postgresql:use_pg_rewind:trueparameters:wal_level:hot_standbyhot_standby:"on"wal_keep_segments:8max_wal_senders:10max_replication_slots:10wal_log_hints:"on"max_connections:200shared_buffers:1GBeffective_cache_size:3GBmaintenance_work_mem:256MBcheckpoint_completion_target:0.7 wal_buffers:16MBdefault_statistics_target:100random_page_cost:1.1effective_io_concurrency:300work_mem:5242kBmin_wal_size:1GBmax_wal_size:4GBmax_worker_processes:2max_parallel_workers_per_gather:1max_parallel_workers:2max_parallel_maintenance_workers:1archive_mode:"on"archive_timeout:1800sarchive_command:"pgbackrest --stanza=pgdb-patroni archive-push %p"recovery_conf:restore_command :"pgbackrest --stanza=pgdb-patroni archive-get %f %p"standby_mode:"on"in itdb:- kodning:UTF8- data-checksumspg_hba:- værtsreplikator xxx.xxx.xx.xx/24 md5- vært alle alle 0.0.0.0/0 md5brugere:admin:adgangskode:adminoptions:- createrole- createdbpostgresql:listen:xxx .xxx.xx.xx:5432connect_address:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0authentication:replikation:brugernavn:replikatoradgangskode:rep-passsuperuser brugernavn:postgrespassword:postgresrewind:brugernavn:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falsenosync:falsescope:pgdb-paxxlisten.xstapi :8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:xxx.xxx.xx.xx:2379,xxx.xxx.xx.xx:2379bootstrap:dcs:ttl:30loop_wait:10retry_timeout:10maximum_8_windsparameter:10maximum_8_7_winds :wal_level:hot_standbyhot_standby:"on"wal_keep_segments:8max_wal_senders:10max_replication_slots:10wal_lo g_hints:"on"max_connections:200shared_buffers:1GBeffective_cache_size:3GBmaintenance_work_mem:256MBcheckpoint_completion_target:0.7wal_buffers:16MBdefault_statistics_target:100random_page_cost:1.1effective_io_concurrency:300work_mem:5242kBmin_wal_size:1GBmax_wal_size:4GBmax_worker_processes:2max_parallel_workers_per_gather:1max_parallel_workers:2max_parallel_maintenance_workers:1archive_mode:"on"archive_timeout:1800sarchive_command:"pgbackrest --stanza=pgdb-patroni archive-push %p"recovery_conf:restore_command:"pgbackrest --stanza=pgdb-patroni archive-get %f %p"standby_mode:"on"
initdb:- kodning:UTF8- data-checksumspg_hba:- værtsreplikator xxx.xxx.xx.xx/24 md5- vært alle alle 0.0.0.0/0 md5brugere:admin:adgangskode:adminoptions:- createrole- createdbpostgresql:listen:xxx.xxx.xx.xx:5432connect_address:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0authentication:replikation:brugernavn:replikatoradgangskode:rep -passsuperuser:brugernavn:postgrespassword:postgresrewind:brugernavn:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falsenopresync:falsepatroni-tjenesten er oprettet mere /etc/systemd/system/patroni.service[Unit]Description=Løbere til at orkestrere en høj tilgængelighed PostgreSQLAfter=syslog.target network.target[Service]Type=simpleUser=postgresGroup=postgresExecStart=/ usr/local/bin/patroni /etc/patroni/patroni.ymlKillMode=processTimeoutSec=30Restart=no[Install]WantedBy=multi-user.target
systemctl aktiver patronisystemctl start patronisystemctl status patronisystemctl stop patronijournalctl -xe -f -u patron

De samme konf. er lavet på andre servere, og tjenesten køres.

patronictl -d xxx.xxx.xx.xx liste pgdb-patroni+ Klynge:pgdb-patroni (xxx.xxx.xx.xx) -+----+-----------+ | Medlem | Vært | Rolle | Stat | TL | Lag i MB |+------------+--------------+--------+-------- --+----+------------+| postgres1 | xxx.xxx.xx.xx | Leder | løber | 1 | || postgres2 | xxx.xxx.xx.xx | | løber | 1 | 0 |+------------+--------------+--------+--------+ ----+-----------+Bemærk:Da vi ikke har installeret pgbackrest indtil nu, kan vi få en fejl, når vi installerer postgresql via patroni på 2. Hvis vi genstarter patroni-tjenester efter installation af ryglæn , vil problemet blive løst. Eller du kan sætte et ryglæn op, før du starter disse lånere.
patronictl -d xxx.xxx.xx.xx liste pgdb-patronipatronictl -d xxx.xxx.xx.xx reinit pgdb-patronipatronictl -c /etc/patroni/patroni.yml list

  1. PL/SQL-blokeringsproblem:Ingen data fundet fejl

  2. Sådan fungerer OBJECTPROPERTYEX() i SQL Server

  3. Fordele ved at bruge Microsoft Access-skabeloner

  4. SQLiteException:Ugenkendt token ved læsning fra database