PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Anleitung zur Installation von Haproxy und Keepalived

Hallo Freunde, heute erkläre ich euch, wie man Haproxy und Keepalived installiert.

yum install haproxy keepalived -y

Die Parameterdatei im Dienst muss bestätigt werden

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

Gemäß der obigen Servicedatei wird /etc/haproxy/haproxy.cfg verwendet, aber wir haben die CONF-Datei bearbeitet, sodass wir einen Fehler erhalten haben.
conf-Datei kann in cfg exportiert werden

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