Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the load balancing of haproxy

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you how to achieve haproxy load balancing, hoping to give you some help in practical application. Load balancing involves a lot of things, and there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Turn on three virtual machines: 192.168.80.103 192.168.80.104 192.168.80.105 in 80.103: systemctl stop firewalld / / turn off firewall setenforce 0 / / turn off monitoring yum install lrz*-y / / install upload software to pull haproxy package into

Tar xf haproxy-1.5.15.tar.gz-C / opt/ unpack and put the cd / opt/haproxy-1.5.15/ source code in the / opt file to compile and install haproxyyum install-y\ pcre-devel\ bzip2-devel\ gcc\ gcc-c++\ makeuname-r / / kernel version make TARGET=linux26 PREFIX=/usr/local/haproxy / / Mark 64 is the system make install PREFIX=/usr/local/haproxymkdir / etc/haproxyuseradd-s / sbin/nologin-M haproxyid haproxy

Cd / usr/local/haproxy/cd / opt/haproxy-1.5.15/cd examples/cp haproxy.cfg / etc/haproxy/cd / etc/haproxy/

Vi haproxy.cfg

After modification:

Delete everything after srvtimeout 50000, and then add the following new content:

-- Statistics page configuration--

Listen admin_stats # is configured for the haproxy access status monitoring page, named admin_stats

Bind 0.0.0.0 8089 / / listening port

Stats enable / / enable listening port

7-tier mode of mode http # http

Log global # inherits the log definition in global

Stats uri / stats # the url access path of the monitoring page, that is, the http://ip/stats access monitoring page

Password box prompt information for stats realm Haproxy\ Statistics # monitoring page

Stats auth admin:admin # Monitoring page user and password admin, you can set multiple user names

# stats hide-version / / hide the version information of HAProxy on the statistics page

Stats admin if TRUE / / can be managed only when it has passed the authentication

Stats refresh 30s / / automatic page refresh time 30s

: wq / / Save exit

Cd-

Cp haproxy.init / etc/init.d/haproxyvi / etc/init.d/haproxychmod + x / etc/init.d/haproxy / / set permissions ll / etc/init.d/haproxy to this file

Chkconfig-- add haproxy/ / add system service ln-s / usr/local/haproxy/sbin/haproxy / usr/sbin/haproxy / / soft link service haproxy start / / start haproxynetstat-anp | grep haproxy/ / check whether the haproxy service is enabled

Enter the IP address on the web page: 8089/stats

Service haproxy stop / / close haproxyvi / etc/haproxy/haproxy.cfg and add the following:-web settings-- listen webcluster # defines the webcluster CVM group. Bind 0.0.0.0 80 # defines the port on which the front end of the haproxy listens. Mode http # http's 7-tier mode option httpchk GET / index.html # heartbeat detection log global # inherits the definition of maxconn 3000 # maximum number of concurrent connections acceptable to server processes in global balance roundrobin # load balancing method: poll server web01 192.168.80.104 server web01 80 check inter 2000 fall 5server web02 192.168.80.105 80 check inter 2000 fall 5 : wq / / Save exit Note: backend servers web1 and web2 IP address: 192.168.80.10 and 192.168.80.20check: check the health status of the current server. Inter: the time interval between the tests. The default is 2000msfall: how many times in a row the test result is "failed" before it is marked as unavailable? The default is 3rise: how many times the test result is "successful" before marking it as available; the default is 2service haproxy start / / enable haproxynetstat-anp | grep haproxy / / check whether the haproxy service is enabled

Enter the http://192.168.80103:8089/stats / / statistics page on the web page

Enter http://192.168.80103 / / load balance on the web page

In 80.104: systemctl stop firewalld setenforce 0yum install httpd-y / / install httpdvi / etc/httpd/conf/httpd.conf remove the # in front of ServerName www.example.com:80 cd / var/www/html/echo "server aa" > index.htmlsystemctl start httpd enter 192.168.80.104 on the web page

In 80.105: systemctl stop firewalld setenforce 0yum install httpd-y / / install httpdvi / etc/httpd/conf/httpd.conf remove the # in front of ServerName www.example.com:80 cd / var/www/html/echo "server bb" > index.htmlsystemctl start httpd enter 192.168.80.105 on the web page

After reading the above about how the load balancing of haproxy is realized, if you have anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. Technical engineers have more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report