{"id":34890,"date":"2021-06-24T06:15:17","date_gmt":"2021-06-24T06:15:17","guid":{"rendered":"https:\/\/ittutorial.org\/?p=34890"},"modified":"2021-06-24T06:15:17","modified_gmt":"2021-06-24T06:15:17","slug":"how-to-installations-haproxy-and-keepalived","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/how-to-installations-haproxy-and-keepalived\/","title":{"rendered":"How to installations Haproxy and Keepalived"},"content":{"rendered":"<p>Hello friends, today I will tell you how to install haproxy and keepalived.<\/p>\n<pre>yum install haproxy keepalived -y<\/pre>\n<p>The parameter file in the service must be confirmed<\/p>\n<pre>cat \/usr\/lib\/systemd\/system\/haproxy.service\r\n[Unit]\r\nDescription=HAProxy Load Balancer\r\nAfter=syslog.target network.target\r\n\r\n[Service]\r\nEnvironmentFile=\/etc\/sysconfig\/haproxy\r\nExecStart=\/usr\/sbin\/haproxy-systemd-wrapper -f \/etc\/haproxy\/haproxy.cfg -p \/run\/haproxy.pid $OPTIONS\r\nExecReload=\/bin\/kill -USR2 $MAINPID\r\nKillMode=mixed<\/pre>\n<p>According to the service file above, \/etc\/haproxy\/haproxy.cfg is used, but we edited the CONF file, so we got an error.<br \/>\nconf file can be exported to cfg<\/p>\n<pre>http:\/\/xxx.xxx.xx.xx:7000\/ To control over the web, the server leader can be controlled with the 7000 port.<\/pre>\n<pre>vi \/etc\/haproxy\/haproxy.cfg\r\n\r\nvi \/etc\/haproxy\/haproxy.conf\r\n\r\nglobal\r\nmaxconn 100\r\ndefaults\r\nlog global\r\nmode tcp\r\nretries 2\r\ntimeout client 30m\r\ntimeout connect 4s\r\ntimeout server 30m\r\ntimeout check 5s\r\nlisten stats\r\nmode http\r\nbind *:7000\r\nstats enable\r\nstats uri \/\r\n# Connections to port 5002\r\nlisten Master_Server\r\nbind *:5432\r\nmode tcp\r\noption tcpka\r\noption httpchk OPTIONS \/master\r\nhttp-check expect status 200\r\ndefault-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions\r\nserver xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008\r\nserver xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008\r\n\r\n# Connections to port 5003\r\nlisten Standby_Servers\r\nbind *:5433\r\nmode tcp\r\noption tcpka\r\noption httpchk OPTIONS \/replica\r\nhttp-check expect status 200\r\ndefault-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions\r\nserver xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008\r\nserver xxx.xxx.xx.xx xxx.xxx.xx.xx:5432 maxconn 100 check port 8008\r\n\r\nvi \/etc\/keepalived\/keepalived.conf\r\n\r\nHAP-1 - Backup ;\r\nvrrp_script chk_haproxy {\r\nscript \"pidof haproxy\"\r\ninterval 2\r\n}\r\n\r\nvrrp_instance VI_1 {\r\nstate MASTER\r\ninterface ens192\r\nvirtual_router_id 51\r\npriority 101\r\nadvert_int 1\r\nauthentication {\r\nauth_type PASS\r\nauth_pass 1111\r\n}\r\nunicast_src_ip xxx.xxx.xx.xx\r\nunicast_peer {\r\nxxx.xxx.xx.xx\r\n}\r\nvirtual_ipaddress {\r\nxxx.xxx.xx.xx\r\n} \r\ntrack_script {\r\nchk_haproxy\r\n}\r\n}\r\n\r\nHAP-2 - Backup ;\r\nvrrp_script chk_haproxy {\r\nscript \"pidof haproxy\"\r\ninterval 2\r\n}\r\n\r\nvrrp_instance VI_1 {\r\nstate BACKUP\r\ninterface ens192\r\nvirtual_router_id 51\r\npriority 100\r\nadvert_int 1\r\nauthentication {\r\nauth_type PASS\r\nauth_pass 1111\r\n}\r\nunicast_src_ip xxx.xxx.xx.xx\r\nunicast_peer {\r\nxxx.xxx.xx.xx\r\n}\r\nvirtual_ipaddress {\r\nxxx.xxx.xx.xx\r\n}\r\ntrack_script {\r\nchk_haproxy\r\n}\r\n}\r\n\r\nsystemctl enable haproxy\r\nsystemctl enable keepalived\r\n\r\nsystemctl start haproxy\r\nsystemctl start keepalived<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip;<\/p>\n","protected":false},"author":36,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3896],"tags":[19815,19814,2606],"class_list":["post-34890","post","type-post","status-publish","format-standard","","category-postgresql","tag-keepalived","tag-patroni-haproxy","tag-postgresql"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/34890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=34890"}],"version-history":[{"count":1,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/34890\/revisions"}],"predecessor-version":[{"id":34892,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/34890\/revisions\/34892"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=34890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=34890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=34890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}