1. Creating user haproxy
[root]# groupadd haproxy
[root]# useradd haproxy -g haproxy
2. Installation haproxy
[root]# yum -y install haproxy.x86_64
3. Configuration service
[root]# vi /etc/haproxy/haproxy.cfg
global
maxconn 100
log 127.0.0.1 local2
defaults
log global
mode tcp
retries 2
timeout client 30m
timeout connect 4s
timeout server 30m
timeout check 5s
listen stats
mode http
bind *:8080
stats enable
stats uri /
listen postgres
bind *:5000
option httpchk
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server pgsql-db01 192.168.1.81:5432 maxconn 100 check port 8008
server pgsql-db02 192.168.1.82:5432 maxconn 100 check port 8008
[root]# useradd haproxy -g haproxy
2. Installation haproxy
[root]# yum -y install haproxy.x86_64
3. Configuration service
[root]# vi /etc/haproxy/haproxy.cfg
global
maxconn 100
log 127.0.0.1 local2
defaults
log global
mode tcp
retries 2
timeout client 30m
timeout connect 4s
timeout server 30m
timeout check 5s
listen stats
mode http
bind *:8080
stats enable
stats uri /
listen postgres
bind *:5000
option httpchk
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server pgsql-db01 192.168.1.81:5432 maxconn 100 check port 8008
server pgsql-db02 192.168.1.82:5432 maxconn 100 check port 8008
4. Startup Haproxy
[root]# systemctl enable haproxy
[root]# systemctl start haproxy
[root]# systemctl status haproxy
[root]# systemctl enable haproxy
[root]# systemctl start haproxy
[root]# systemctl status haproxy
####################
### Keepalived
####################
1. Installation Keeplived### Keepalived
####################
[root]# yum -y install keepalived.x86_64
2. Configuration
[root]# vi /etc/keepalived/keepalived.conf
##########################################################
vrrp_script chk_haproxy {
script "killall -0 haproxy" # verify the pid existance
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface ens192 # interface to monitor
state MASTER
virtual_router_id 51 # Assign one ID for this route
priority 100 # 100 on master, 50 on backup
virtual_ipaddress {
192.168.1.88 # the virtual IP
}
track_script {
chk_haproxy
}
}
3. Startup Haproxy
[root]# systemctl enable keepalived
[root]# systemctl start keepalived
[root]# systemctl status keepalived
[root]# vi /etc/keepalived/keepalived.conf
##########################################################
vrrp_script chk_haproxy {
script "killall -0 haproxy" # verify the pid existance
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface ens192 # interface to monitor
state MASTER
virtual_router_id 51 # Assign one ID for this route
priority 100 # 100 on master, 50 on backup
virtual_ipaddress {
192.168.1.88 # the virtual IP
}
track_script {
chk_haproxy
}
}
3. Startup Haproxy
[root]# systemctl enable keepalived
[root]# systemctl start keepalived
[root]# systemctl status keepalived
4. Availability check
[root]# ip a
No comments:
Post a Comment