Здравейте, днес ще обясня инсталирането на патрони с висока достъпност.
1-PostgreSQL инсталиране на софтуер
2-Patroni инсталиране на софтуер
3-etcd софтуерна инсталация, etcd conf.
4-patroni conf.
5-pgbackrest настройка и конф.
6-haproxy и keepalived
7-Всички други конф.
PostgreSQL софтуер
yum install -y postgresql12-server postgresql12-client postgresql12-contrib postgresql12-devel
Софтуер 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 инсталирай patroni[etcd]
etcd инсталация и 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="new"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCD/etcd_cluster/etcd-cluster-01" 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:ENT:/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="new"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://xxx.xxx.xx.xx:2380"ETCD_INITIAL_CLUSTER_TOKEN" 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_http_ADVERTISE_C ://xxx.xxx.xx.xx:2379"ETCD_NAME="etcd2"systemctl активиране на etcdsystemctl старт etcdsystemctl status etcdsystemctl стоп etcd
Патрони конф.
Създава се директорията за yaml файла patroni. и postgres е разрешен
mkdir /etc/patroni/chown postgres:postgres /etc/patroni/mkdir /postgres/chown postgres:postgres /postgres/
–// yml файлът трябва да бъде зададен според IP адресите на сървъра и паметта и т.н. според ресурсите на сървъра. настройките трябва да бъдат направени.
обхват:pgdb-patroniname:postgres1restapi:listen:xxx.xxx.xx.xx:8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:1xxx.xxx.xx.xx.xx.xx,2379 .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:- кодиране:UTF8- data-checksumspg_hba:- репликатор на хост xxx.xxx.xx.xx/24 md5- хост всички всички 0.0.0.0/0 md5users:admin:password:adminoptions:- createrole- createdbpostgresql:xxl:.xxx.xx.xx:5432connect_address:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0authentication:replicacation-:userpassername:userpassername:потребителско име:postgrespassword:postgresrewind:потребителско име:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falseclonefrom:falseclonefrom:falseclonefrom:falseclonefrom:falseclonefrom:falsexrex. :8008connect_address:xxx.xxx.xx.xx:8008etcd:hosts:xxx.xxx.xx.xx:2379,xxx.xxx.xx.xx:2379bootstrap:dcs:ttl:30loopre1trys_time:10loopre1trys_time:10loopre1trys_time:10loopre1trys_time:10xx.xx.xx:2379 :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:- кодиране:UTF8- data-checksumspg_hba:- репликатор на хост xxx.xxx.xx.xx/24 md5- хост всички 0.0.0.0/0 md5users:admin:password:adminoptions:- creategrerole- created:b слушайте:xxx.xxx.xx.xx:5432connect_address:xxx.xxx.xx.xx:5432data_dir:/postgres/data/bin_dir:/usr/pgsql-12/binpgpass:/tmp/pgpass0authentication:replication:replication:replication -passsuperuser:username:postgrespassword:postgresrewind:username:rewind_userpassword:rewind_passwordparameters:unix_socket_directories:'/var/run/postgresql/'tags:nofailover:falsenoloadbalance:falseclonefrom:falseclonefrom>услугата patroni е създадена още /etc/systemd/system/patroni.service[Unit]Description=Runners за организиране на високодостъпна 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.targetsystemctl активиране на patronisystemctl стартиране на състоянието на patronisystemctl patronisystemctl спиране на patronijournalctl -xe -f -u патронСъщите confs се правят на други сървъри и услугата се изпълнява.
patronictl -d xxx.xxx.xx.xx list pgdb-patroni+ Клъстер:pgdb-patroni (xxx.xxx.xx.xx) -+----+-----------+ | Член | Домакин | Роля | Държава | TL | Изоставане в MB |+----------+--------------+--------+-------- -+----+-----------+| postgres1 | xxx.xxx.xx.xx | Лидер | бягане | 1 | || postgres2 | xxx.xxx.xx.xx | | бягане | 1 | 0 |+----------+--------------+-------+--------+ ----+----------+Забележка:Тъй като досега не сме инсталирали pgbackrest, може да получим грешка при инсталиране на postgresql чрез patroni на 2. Ако рестартираме услугите на patroni след инсталиране на облегалката , проблемът ще бъде решен. Или можете да настроите облегалка, преди да започнете тези патрони.patronictl -d xxx.xxx.xx.xx list pgdb-patronipatronictl -d xxx.xxx.xx.xx reinit pgdb-patronipatronictl -c /etc/patroni/patroni.yml list