How to installations Haproxy and Keepalived

Hello friends, today I will tell you how to install haproxy and keepalived.

yum install haproxy keepalived -y

The parameter file in the service must be confirmed

cat /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target

[Service]
EnvironmentFile=/etc/sysconfig/haproxy
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed

According to the service file above, /etc/haproxy/haproxy.cfg is used, but we edited the CONF file, so we got an error.
conf file can be exported to cfg

http://xxx.xxx.xx.xx:7000/ To control over the web, the server leader can be controlled with the 7000 port.
vi /etc/haproxy/haproxy.cfg

vi /etc/haproxy/haproxy.conf

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 /
# Connections to port 5002
listen Master_Server
bind *:5432
mode tcp
option tcpka
option httpchk OPTIONS /master
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008
server xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008

# Connections to port 5003
listen Standby_Servers
bind *:5433
mode tcp
option tcpka
option httpchk OPTIONS /replica
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008
server xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008

vi /etc/keepalived/keepalived.conf

HAP-1 - Backup ;
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}

vrrp_instance VI_1 {
state MASTER
interface ens192
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip xxx.xxx.xx.xx
unicast_peer {
xxx.xxx.xx.xx
}
virtual_ipaddress {
xxx.xxx.xx.xx
} 
track_script {
chk_haproxy
}
}

HAP-2 - Backup ;
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}

vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip xxx.xxx.xx.xx
unicast_peer {
xxx.xxx.xx.xx
}
virtual_ipaddress {
xxx.xxx.xx.xx
}
track_script {
chk_haproxy
}
}

systemctl enable haproxy
systemctl enable keepalived

systemctl start haproxy
systemctl start keepalived

About tayfun inam

Computer Engineer -PostgreSql-Oracle Database Administrator I am about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 8+years experience.I have OCA,PostgreSql senior Certificates I have worked 50+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.

Leave a Reply

Your email address will not be published. Required fields are marked *