Highly Available PostgreSQL Cluster using Patroni and HAProxy on Ubuntu 22.04 LTS
Click Below link for Step by Step documentation:
https://www.chirags.in/tutorial/index...
[email protected] Chirags PostgreSQL DBA Tutorial https://www.chirags.in
*********************************************************************************************
How to setup PostgreSQL Cluster with Patroni on Ubuntu 22.04 LTS
***********************************************************************************************
Architecture:
OS: Ubuntu 22.04
Postgres version: 14
Machine: node1 IP: node1_ip Role: Postgresql, Patroni
Machine: node2 IP: node2_ip Role: Postgresql, Patroni
Machine: node3 IP: node3_ip Role: Postgresql, Patroni
Machine: etcdnode IP: etcdnode_ip Role: etcd
Machine: haproxynode IP: haproxynode_ip Role: HA Proxy
In my case:
Machine: node1 IP: 192.168.32.130 Role: Postgresql, Patroni
Machine: node2 IP: 192.168.32.131 Role: Postgresql, Patroni
Machine: node3 IP: 192.168.32.xxx Role: Postgresql, Patroni
Machine: etcdnode IP: 192.168.32.140 Role: etcd
Machine: haproxynode IP: 192.168.32.135 Role: HA Proxy
Step-by-step instructions guide
Step 1 – Setup node1, node2, node3:
sudo apt update
sudo hostnamectl set-hostname node1
--sudo hostnamectl set-hostname node2
--sudo hostnamectl set-hostname node3
sudo apt install net-tools
sudo apt install postgresql postgresql-server-dev-14
sudo systemctl stop postgresql
sudo ln -s /usr/lib/postgresql/14/bin/* /usr/sbin/
sudo apt -y install python3 python3-pip
sudo apt install python3-testresources
sudo pip3 install --upgrade setuptools
sudo pip3 install psycopg2
sudo pip3 install patroni
sudo pip3 install python-etcd
Step 2 – Setup etcdnode:
sudo apt update
sudo hostnamectl set-hostname etcdnode
sudo apt install net-tools
sudo apt -y install etcd
Step 3 – Setup haproxynode:
sudo apt update
sudo hostnamectl set-hostname haproxynode
sudo apt install net-tools
sudo apt -y install haproxy
Step 4 – Configure etcd on the etcdnode:
sudo vi /etc/default/etcd
ETCD_LISTEN_PEER_URLS="http://192.168.32.140:2380"
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://192.168.32.140:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.32.140:2380"
ETCD_INITIAL_CLUSTER="default=http://192.168.32.140:2380,"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.32.140:2379"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
sudo systemctl restart etcd
sudo systemctl status etcd
..................
..................
Step 8 – Testing High Availability Cluster Setup of PostgreSQL:
http://haproxynode_ip:7000/
Check the output
sudo systemctl stop patroni
In this case, the second Postgres server is promoted to master.
Step 9 – Connect Postgres clients to the HAProxy IP address:
psql -h haproxynode_ip -p 5000 -U postgres
psql -h 192.168.32.135 -p 5000 -U postgres
Password for user postgres:
some_db=
root@node1:/home/node1# patronictl -c /etc/patroni.yml list
Cluster: postgres (7366967472395659584) ------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+--------+----------------+---------+-----------+----+-----------+
| node1 | 192.168.32.130 | Replica | streaming | 2 | 0 |
| node2 | 192.168.32.131 | Leader | running | 2 | |
+--------+----------------+---------+-----------+----+-----------+
root@node1:/home/node1#
Step 10 – Failover test:
On one of the nodes run:
sudo systemctl stop patroni
For any doubts and query, please write on YouTube video comments section.
Note : Flow the Process shown in video.
😉Subscribe and like for more videos:
/ @chiragstutorial
💛Don't forget to, 💘Follow, 💝Like, Share 💙&, Comment
Tutorial Link :
https://www.chirags.in/tutorials/Post...
Thanks & Regards,
Chitt Ranjan Mahto "Chirag"
____________________________________________________________________
Note: All scripts used in this demo will be available in our website.
Link will be available in description.
#postgresql
#replication
#postgresreplication
#streaming
#streamingreplication
#chiragstutorial
#chiragsdbatutorial
#patroni
#postgresCluster
Смотрите видео PostgreSQL Tutorial - 20 - Highly Available PostgreSQL Cluster using Patroni and HAProxy on Ubuntu онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Chirags Tutorial 03 Июнь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,50 раз и оно понравилось 2 людям.