MODOP – Partie 3 – PostrgreSQL – Installation du Cluster HaPoxy

Inventaire des machines

Cluster HaProxy

  • hostname : Node-hsql01
    • IP : 192.168.1.106/24
    • VIP : 192.168.1.110/24
      • Virtuel Host : node-sql
    • RAM : 2Go
    • CPU : 1
  • hostname : Node-hsql02
    • IP : 192.168.1.107/24
    • VIP : 192.168.1.110/24
      • Virtuel Host : node-sql
    • RAM : 2Go
    • CPU : 1

1. Mise à jour (2 nodes)

[root@node-hsql0x ~]# dnf update -y

2. Ajout des Hosts (pas de DNS)

Copy de /etc/hosts node-esql01 vers les hosts hsql

[root@node-hsql01 ~]# scp root@192.168.1.100:/etc/hosts /etc/hosts
[root@node-hsql02 ~]# scp root@192.168.1.100:/etc/hosts /etc/hosts
[root@node-hsql0x ~]# cat /etc/hosts

Check résolution hosts (2 hosts)

[root@node-hsql0x ~]# ping -c 2 node-esql01
[root@node-hsql0x ~]# ping -c 2 node-psql01
[root@node-hsql0x ~]# ping -c 2 node-hsql02

3. Désactiver SELinux (2 nodes)

[root@node-hsql0x ~]# setenforce 0
[root@node-psql0x ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

4. Synchroniser DateTime sur le fuseau de PARIS (2 nodes)

[root@node-hsql0x ~]# timedatectl set-timezone Europe/Paris

5. Installation des middlewares (2 nodes)

[root@node-hsql0x ~]# dnf install epel-release net-tools nmap curl wget tar –y

6. Installation KeepAlive (2 nodes)

Installation des paquets

[root@node-hsql0x ~]# dnf -y install keepalived
[root@node-hsql0x ~]# dnf -y install ipvsadm

Chargement du module ip_vs

[root@node-hsql0x ~]# modprobe ip_vs
[root@node-hsql0x ~]# lsmod |grep ip_vs

[root@node-hsql0x ~]# echo ip_vs >> /etc/module

Configuration KeepAlive

[root@node-hsql0x ~]# cp /etc/keepalived/keepalived.conf{,-old}
[root@node-hsql0x ~]# sh -c '> /etc/keepalived/keepalived.conf'

Fichier conf node-hsql01

[root@node-hsql01 ~]# vi /etc/keepalived/keepalived.conf

! /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
 notification_email {
 chris@en-images.info
 }

 notification_email_from chris@en-images.info
 smtp_server localhost
 smtp_connect_timeout 30
 }

vrrp_instance VI_1 {
 state MASTER
 interface ens18
 virtual_router_id 100
 priority 200

 authentication {
auth_type PASS
 auth_pass chris@2023
 }

 virtual_ipaddress {
 192.168.1.110/24 dev ens18
 }

}

Fichier conf node-hsql02

[root@node-hsql02 ~]# vi /etc/keepalived/keepalived.conf

! /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
chris@en-images.info
}

 notification_email_from chris@en-images.info
 smtp_server localhost
 smtp_connect_timeout 30

}

vrrp_instance VI_1 {
 state BACKUP
 interface ens18
 virtual_router_id 100
 priority 199

authentication {
 auth_type PASS
 auth_pass chris@2023
}

virtual_ipaddress {
192.168.1.110/24 dev ens18
}

}

Prérequis réseau KeepAlive

[root@node-hsql0x ~]# echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
[root@node-hsql0x ~]# sysctl -p
net.ipv4.ip_nonlocal_bind = 1

Règles firewall

[root@node-hsql0x ~]# firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent --zone=public
[root@node-hsql0x ~]# firewall-cmd --remove-service={cockpit,dhcpv6-client} --permanent
[root@node-hsql0x ~]# firewall-cmd --reload

Lancement KeepAlive

Node-hsql01
[root@node-hsql01 ~]# systemctl start --now keepalived
[root@node-hsql01 ~]# systemctl enable keepalived
[root@node-hsql01 ~]# systemctl status keepalived

[root@node-hsql01 ~]# ip a

Node-hsql02
[root@node-hsql02 ~]# systemctl start --now keepalived
[root@node-hsql02 ~]# systemctl enable keepalived
[root@node-hsql02 ~]# systemctl status keepalived

[root@node-hsql02 ~]# ip a

7. Installation client postgreSQL ( 2 nodes)

Installation Repository PostgreSQL

[root@node-hsql0x ~]# dnf -y install yum-utils
[root@node-hsql0x ~]# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Sélection version 12 PostgreSQL

[root@node-hsql0x ~]# dnf -y module list postgresql
[root@node-hsql0x ~]# dnf -y module enable postgresql:12

Installation du paquet client de postgresql

[root@node-hsql0x ~]# dnf -qy module disable postgresql
[root@node-hsql0x ~]# dnf -y install postgresql12
[root@node-hsql0x ~]# ls /usr/pgsql-12/bin
[root@node-hsql0x ~]# ln -s /usr/pgsql-12/bin/* /usr/sbin/

8. Installation HaProxy (2 nodes)

Installation du paquet

[root@node-hsql0x ~]# dnf install -y haproxy

Inventaire des ports Utiles

  • Port 5000 : « Writes SQL»
  • Port 5001 : « Read SQL»
  • Port 7000 : « DashBoard HaProxy »
  • Port 8008 : « Patroni Rest api »
  • Port 5432 : PostgreSQL

Check Accès Cluster Psql

Check rest api patroni

[root@node-hsql01 ~]# curl -s http://node-psql01:8008

[root@node-hsql01 ~]# curl -s http://node-psql02:8008
[root@node-hsql01 ~]# curl -s http://node-psql03:8008

Check connexion postgreSQL via les nodes HaProxy
[root@node-hsql01 ~]# psql -U chris -h node-psql01 -d chris2023

[root@node-hsql01 ~]# psql -U chris -h node-psql02 -d chris2023
[root@node-hsql01 ~]# psql -U chris -h node-psql03 -d chris2023

Configuration HaProxy ( 2 nodes)

[root@node-hsql0x ~]# mv /etc/haproxy/haproxy.cfg{,-old}
[root@node-hsql0x ~]# vi /etc/haproxy/haproxy.cfg

global
 maxconn 100
defaults
 log global
 mode tcp
 retries 2
 timeout client 30m
 timeout connect 4s
 timeout server 30m
 timeout check 5s

listen stats
 mode http
 bind *:7000
 stats enable
 stats uri /status
 stats refresh 2s
 stats auth chris:Chris
 stats admin if TRUE

listen master
 bind *:5000
 option httpchk OPTIONS /master
 http-check expect status 200
 default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
 server node-psql01 node-psql01:5432 maxconn 100 check port 8008
 server node-psql02 node-psql02:5432 maxconn 100 check port 8008
 server node-psql03 node-psql03:5432 maxconn 100 check port 8008

listen replicats
 balance roundrobin
 bind *:5001
 option httpchk OPTIONS /replica
 http-check expect status 200
 default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
 server node-psql01 node-psql01:5432 maxconn 100 check port 8008
 server node-psql02 node-psql02:5432 maxconn 100 check port 8008
 server node-psql03 node-psql03:5432 maxconn 100 check port 8008
[root@node-hsql0x ~]# haproxy -c -V -f /etc/haproxy/haproxy.cfg
Configuration file is valid

Régles Firewall (2 nodes)

[root@node-hsql0x ~]# firewall-cmd --add-port={5000,5001,7000}/tcp --permanent
[root@node-hsql0x ~]# firewall-cmd --add-service=http –permanent
[root@node-hsql0x ~]# firewall-cmd --reload

Démarrage du service HaProxy (2 nodes)

[root@node-hsql0x ~]# systemctl start haproxy
[root@node-hsql0x ~]# systemctl enable haproxy
[root@node-hsql0x ~]# systemctl status haproxy

9. Connexion IHM HaProxy


Login/passwod : chris/Chris


Ici on peut constater les deux configurations suivantes

  • Le master « Write SQL » est le node-psql02
  • Les réplicas « Read SQL » sont node-psql01 et node-psql03

Views: 8

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *