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

The basic concept of haproxy and the process of realizing load balancing

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

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

On the 80.100 virtual machine, systemctl stop firewalld / / turn off the firewall setenforce 0 / / close the monitoring yum install lrz*-y / / install the upload software tar xf haproxy-1.5.15.tar.gz-C / opt/ decompress the package to / opt/cd / opt/haproxy-1.5.15/ enter / opt/haproxy-1.5.15/ yum install-y\ pcre- Devel\ bzip2-devel\ gcc\ gcc-c++\ make uname-r

Make TARGET=linux26 PREFIX=/usr/local/haproxy / / Mark 64 create a directory for the system make install PREFIX=/usr/local/haproxymkdir / etc/haproxy / / useradd-s / sbin/nologin-M haproxy / / create user id haproxy / / View user information

Cd examples/ enter examples/cp haproxy.cfg / etc/haproxy/ copy to / etc/haproxy/ cd / etc/haproxy/ enter cd / etc/haproxy/ vi haproxy.cfg / / enter the vi haproxy.cfg file and delete it all and add # this config needs haproxy-1.1.28 or haproxy-1.2.1 global log 127.0.0.1 local0 Log 127.0.0.1 local1 notice # log loghost local0 info / / defines the maximum number of concurrent connections at the haproxy log level maxconn 4096 / / maximum number of concurrent connections that can be received # chroot / usr/share/haproxy / / working directory uid 1001 / / running program user gid 1001 / / running program user group daemon / / create a process to run in deamon mode Run harpoxy # debug # quiet defaults log global / / to define the log in the background, and globally define the categories processed by mode http / /. Tcp is four-tier, http is seven-tier, and health only returns OK In mixed mode, mode does not need to set option httplog / / actively close http channel option dontlognull / / do not record health check log information retries 3 redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen admin_stats / / configure for haproxy access status monitoring page after each request Named admin_stats bind 0.0.0.0mode http 8089 / / listening port stats enable / / layer 7 mode log global / / enables listening port log global / / inherits the url access path of the log definition stats uri / stats / / monitoring page in global That is, http://ip/stats accesses the password box prompt information of the monitoring page stats realm Haproxy\ Statistics / / monitoring page stats auth admin:admin / / the user and password admin of the monitoring page You can set multiple usernames # stats hide-version / / hide the version information of HAProxy on the statistics page stats admin if TRUE / / manage stats refresh 30s / / page automatic refresh time 30s: wq / / save and exit cd-cp haproxy.init / etc/init.d/haproxy / / copy to / etc/init.d/haproxyll / etc/ Init.d/haproxy / / check what permissions this file has chmod + x / etc/init.d/haproxy / / give x permissions to this file ll / etc/init.d/haproxy / / View what permissions this file has

Chkconfig-- add haproxy in the browser address bar 192.168.80.100:8089/stats

The last line of vi / etc/haproxy/haproxy.cfg # adds 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 log in global maxconn 3000 / / maximum number of concurrent connections acceptable to the server process balance roundrobin / / load balancing method: polling Server web01 192.168.80.102 fall 80 check inter 2000 fall 5 server web02 192.168.80.103 fall 80 check inter 2000 fall 5 / / back-end servers web1 and web2 IP address: 192.168.80.102 and 192.168.80.103check: check the health status of the current server

192.168.80.100:8089/stats in the browser address bar

On the 80.102 virtual machine, systemctl stop firewalld / / turn off the firewall setenforce 0 / / close the monitoring yum install httpd-y / / install the httpd service vi / etc/httpd/conf/httpd.conf / / enter this configuration file to find ServerName www.example.com:80 and # remove: wq / / Save exit cd / var/www/html/ enter this directory echo "server aa" > index.html / / create an index.html in the current directory and add server aasystemctl start httpd / / restart the service in the browser address bar 192.168.80.102

On the 80.103 virtual machine, systemctl stop firewalld / / turn off the firewall setenforce 0 / / close the monitoring yum install httpd-y / / install the httpd service vi / etc/httpd/conf/httpd.conf / / enter this configuration file to find ServerName www.example.com:80 and # remove: wq / / Save exit cd / var/www/html/ enter this directory echo "server bb" > index.html / / create an index.html in the current directory and add server bbsystemctl start httpd / / restart the service in the browser address bar 192.168.80.103

After reading the above basic concepts of haproxy and the process of realizing load balancing, if there is 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