sql >> Databáze >  >> RDS >> PostgreSQL

PostgreSQL High Availability instalací Patroni

Dobrý den, dnes vysvětlím instalaci patroni s vysokou dostupností.

1-Instalace softwaru PostgreSQL
Instalace softwaru 2-Patroni
Instalace softwaru 3-etcd, konf. etcd
Konf. 4-patroni
Nastavení a konf. opěrky 5-pg
6-haproxy a keepalved
7-Všechny ostatní konf.

Software PostgreSQL

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

Software Patroni

export 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 instalace a conf

yum install -y atdd
--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="new"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCDetcDATA/lib_ 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_ADVERTIS="http/CLIENT_URL /xxx.xxx.xx.xx:2379"ETCD_NAME="etcd1"##--pgdb-2ETCD_INITIAL_CLUSTER="etcd1=http://xxx.xxx.xx.xx:2380,etcd2=http://xxx.xxx .xx.xx:2380"ETCD_INITIAL_CLUSTER_STATE="nové"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.x="x.xx:2380/default/DIRCD_Detc" 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_CLISE ://xxx.xxx.xx.xx:2379"ETCD_NAME="etcd2"systemctl povolit spuštění etcdsystemctl etcdsystemctl status etcdsystemctl stop etcd

Patroni conf.

Adresář je vytvořen pro soubor patroni yaml. a postgres je autorizován

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

–// yml soubor by měl být nastaven podle IP adres serveru a paměti atd. podle zdrojů serveru. musí být provedeno nastavení.

scope:pgdb-patronname:postgres1restapi:listen:xxx.xxx.xx.xx:8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:1xxx.xxx.xx.xx:2379,xxxx. .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:- kódování:UTF8- data-checksumspg_hba:- replikátor replikace hostitele xxx.xxx.xx.xx/24 md5- hostitel vše 0.0.0.0/0 md5users:admin:password:adminoptions:- createrole- createdbpostgresxl:listen:.xxx.xx.xx:5432connect_address:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0authentication:replication:username:replikátorusperpassword:replikátorusperpassword uživatelské jméno:postgrespassword:postgresrewind:username:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falsenosync:falsescope:pgdb. :8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:xxx.xxx.xx.xx:2379,xxx.xxx.xx.xx:2379bootstrap:dcs:ttl:30prodleva_pro_smyčka:0x_prodlevy_4faxu:10_parametrů:10_parametrů :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:- kódování:UTF8- data-checksumspg_hba:- replikátor replikace hostitele xxx.xxx.xx.xx/24 md5- všechny hostitele 0.0.0.0/0 md5users:admin:password:adminoptions:- createrole:createdbpostgresql poslouchat:xxx.xxx.xx.xx:5432adresa_připojení:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0autentication:replikace:heslo uživatele:-passsuperuser:username:postgrespassword:postgresrewind:username:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falseslužba patroni je vytvořena více /etc/systemd/system/patroni.service[Unit]Description=Runners pro organizaci vysoce dostupné 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 povolit patronisystemctl start patronisystemctl status patronisystemctl stop patronijournalctl -xe -f -u patron

Stejné konfigurace se provádějí na jiných serverech a služba je spuštěna.

patronictl -d xxx.xxx.xx.xx seznam pgdb-patroni+ Cluster:pgdb-patroni (xxx.xxx.xx.xx) -+----+-----------+ | Člen | Host | Role | stát | TL | Prodleva v MB |+-----------+---------------+--------+-------- -+----+-----------+| postgres1 | xxx.xxx.xx.xx | Vedoucí | běží | 1 | || postgres2 | xxx.xxx.xx.xx | | běží | 1 | 0 |+-----------+---------------+--------+---------+ ----+-----------+Poznámka:Protože jsme dosud nenainstalovali pgbackrest, může se stát, že při instalaci postgresql přes patroni na 2 dojde k chybě. Pokud po instalaci backrest restartujeme služby patroni , problém bude vyřešen. Nebo si před spuštěním těchto patronů můžete nastavit opěradlo.
seznam patronictl -d xxx.xxx.xx.xx pgdb-patronipatronictl -d xxx.xxx.xx.xx reinit seznam pgdb-patronipatronictl -c /etc/patroni/patroni.yml

  1. Jak SQLParameter zabraňuje vkládání SQL?

  2. Vložení více řádků do mysql

  3. SQL Server znovu sestavit a reorganizovat index

  4. Nejlepší způsoby, jak opravit poškozenou tabulku InnoDB v MySQL