नमस्कार दोस्तों, आज मैं आपको बताऊंगा कि haproxy कैसे स्थापित करें और इसे कैसे बनाए रखें।
yum install haproxy keepalived -y
सेवा में पैरामीटर फ़ाइल की पुष्टि होनी चाहिए
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
उपरोक्त सेवा फ़ाइल के अनुसार, /etc/haproxy/haproxy.cfg का उपयोग किया जाता है, लेकिन हमने CONF फ़ाइल को संपादित किया, इसलिए हमें एक त्रुटि मिली।
conf फ़ाइल को 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