DevOps - Cluster DB With POSTGRESQL PATRONI HAPROXY PGBOUNCER

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

POSTGRESQL

https://snapshooter.com/learn/postgresql/postgresql-cluster-patroni
https://www.techsupportpk.com/2022/01/set-up-highly-available-postgresql13-cluster-ubuntu.html?m=1
https://severalnines.com/blog/how-achieve-postgresql-high-availability-pgbouncer/

HOSTNAME IP ADDRESS PURPOSE


NODE01 192.168.1.151 POSTGRESQL, PATRONI
NODE02 192.168.1.152 POSTGRESQL, PATRONI
NODE03 192.168.1.12 ETCD
NODE04 192.168.1.11 HAPROXY, PGBOUNCER

INSTALASI POSTGRESQL & PATRONI ( NODE01, NODE02)

$ sudo apt update


$ sudo apt-get install postgresql postgresql-contrib -y
$ sudo systemctl stop postgresql
$ sudo ln -s /usr/lib/postgresql/12/bin/* /usr/sbin/
$ sudo apt-get install python3-pip python3-dev libpq-dev -y
$ sudo pip3 install --upgrade pip
$ sudo pip install patroni
$ sudo pip install python-etcd pip install psycopg2
$ sudo sudo ufw allow 22,8008,5432/tcp
$ sudo ufw enable
INSTALASI ETCD (NODE03 )
$ sudo apt update
$ sudo apt-get install etcd –y
$ sudo nano /etc/default/etcd

etcd.txt

Unremark
ETCD_LISTEN_PEER_URLS=http://10.42.0.19:2380
ETCD_LISTEN_CLIENT_URLS=http://localhost:2379, http://10.42.0.19.13:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://10.42.0.19:2380
ETCD_INITIAL_CLUSTER=default=http://10.42.0.19:2380
ETCD_ADVERTISE_CLIENT_URLS=http://10.42.0.19:2379
ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
ETCD_INITIAL_CLUSTER_STATE=new
$ sudo systemctl restart etcd
$ sudo systemctl status etcd
CREATE A SYSTEMD SSERVICE FOR PATRONI ( NODE01, NODE02)
$ sudo nano /etc/patroni.yml

patroni.txt

$ sudo mkdir -p /data/patroni


$ sudo chown postgres:postgres /data/patroni
$ sudo chmod 700 /data/patroni
$ sudo nano /etc/systemd/system/patroni.service

patroni.service.txt

$ sudo systemctl daemon-reload


$ sudo systemctl start patroni
$ sudo systemctl start postgresql
$ sudo systemctl status patroni
==================================================================================

CONFIGURE HAPROXY ( NODE04 )


$ sudo apt update
$ sudo apt-get install haproxy -y
$ sudo nano /etc/haproxy/haproxy.cfg

haproxy.txt

$ sudo haproxy -c -V -f /etc/haproxy/haproxy.cfg


$ sudo systemctl restart haproxy
$ sudo systemctl status haproxy
TEST CONNECT POSTGRES CLIENTS FROM NODE01,NODE02 TO HAPROXY IPADDRESS :
$ sudo apt install postgresql-client-common
$ sudo apt install postgresql-client-12
$ psql -h 192.168.1.151 -p 5432 -U postgres

$ patronictl -c /etc/patroni.yml list

You might also like