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

Using Haproxy to build web Cluster

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

Share

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

Common web cluster scheduler at present common web cluster scheduler is divided into software and hardware, software usually uses open source LVS,Haproxy,Nginx, hardware generally uses F5, and many people use some domestic products, such as barracuda, Green Alliance and other Haproxy application analysis.

LVS has strong anti-load ability in enterprise applications, but it has some shortcomings.

LVS does not support regular processing and cannot achieve static and dynamic separation.

For large websites, the implementation and configuration of LVS is complex, and the maintenance cost is relatively high.

Haproxy is a software that provides high availability, load balancing, and agents based on TCP and HTTP applications

It is especially suitable for web sites with heavy load.

Running on current hardware can support tens of thousands of concurrent connection requests

Principle of Haproxy scheduling algorithm

RR: the simplest and most commonly used, polling scheduling

LC: minimum number of connections algorithm, which dynamically allocates front-end requests according to the number of back-end node connections

SH: source access scheduling algorithm, which is used to record session sessions on the server. Cluster scheduling can be done based on the source ip,cookie.

Experimental environment

Haporxy server 192.168.13.175

Web1 server 192.168.13.151

Web2 server 192.168.13.176

Client test machine win7

1, install Nginx on the web1,web2 server

[root@web1 ~] # yum install-y\ # installation environment requires component package > pcre-devel\ # # Development package > zlib-devel\ # # package > gcc\ > gcc-c++\ > make [root@web1 ~] # useradd-M-s / sbin/nologin nginx # # create system user [root@web1 ~] # mkdir / abc # # create mount point [root@web1] # mount.cifs / 192.168.100.3 / LNMP-C7 / abc/ # # Mount Password for root@//192.168.100.3/LNMP-C7: [root@web1 ~] # cd / abc/ [root@web1 abc] # tar zxvf nginx-1.12.2.tar.gz-C / opt # # decompress [root@web1 abc] # cd / opt/nginx-1.12.2/ [root@web1 nginx-1.12.2] #. / configure\ # # configure >-- Prefix=/usr/local/nginx\ >-- user=nginx\ >-- group=nginx [root@web1 nginx-1.12.2] # make & & make install [root@web1 nginx-1.12.2] # echo "this is kgv web" > / usr/local/nginx/html/test.html## create site page content For this is accp web [root@web1 nginx-1.12.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # on web2 to facilitate system recognition [root@web1 nginx-1.12.2] # nginx- t # # check syntax [root@web1 nginx-1.12.2] # nginx # # enable service [root@web1 nginx-1.12.2] # systemctl stop firewalld.service # # turn off firewall [root@web1 nginx-1.12.2] # setenforce 0

2, install the haproxy scheduling service on the haproxy server

[root@haproxy ~] # yum install-y\ # install Environment components tools > pcre-devel\ > bzip2-devel\ > gcc\ > gcc-c++\ > make [root@haproxy ~] # systemctl stop firewalld.service # # turn off the firewall [root@haproxy ~] # setenforce 0 [root@haproxy ~] # mkdir / abc [root@haproxy ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / abc/ # mount [root@haproxy ~] # Cd / abc/ [root@haproxy abc] # tar zxvf haproxy-1.5.19.tar.gz-C / opt/ # # extract [root@haproxy abc] # cd / opt/haproxy-1.5.19/ [root@haproxy haproxy-1.5.19] # make TARGET=linux26 # # compile [root@haproxy haproxy-1.5.19] # make install # # install [root@haproxy haproxy-1.5.19] # mkdir / etc/haproxy # # create configuration file directory Copy [root@haproxy haproxy-1.5.19] # cp examples/haproxy.cfg / etc/haproxy/ # # template to the configuration directory [root@haproxy haproxy-1.5.19] # cd / etc/haproxy/ [root@haproxy haproxy] # vim haproxy.cfg # # Edit configuration file-Delete all listen items And add-- comment the following sentence chroot / usr/share/haproxyredispatch add listen webcluster 0.0.0.0 test.html 80 option httpchk GET / test.html # # web webpage balance roundrobin # # polling server inst1 192.168.13.151Vel80 check Inter 2000 fall 3 # # three health check requests server inst2 192.168.13.176 check inter 2000 fall 3 [root@haproxy haproxy] # cp / opt/haproxy-1.5.19/examples/haproxy.init / etc/init.d/haproxy # # launch file [root@haproxy haproxy] # chmod + x / etc/init.d/haproxy # # execute permissions [root@haproxy haproxy] # chkconfig-- add / etc/init.d/haproxy # # add to service [root@haproxy haproxy] # ln-s / usr/local/sbin/haproxy / usr/sbin/ # # easy for the system to identify [root@haproxy haproxy] # service haproxy start # # enable service Starting haproxy (via systemctl): [OK] [root@haproxy haproxy] # netstat-ntap | grep haproxy # # View port tcp 000.0.0.0usr/sbin/ 80 0.0.0.0VR * LISTEN 39884/haproxy

3, use the testing machine to test the web page

4, log definition, modify haproxy configuration file

[root@haproxy haproxy] # vim / etc/haproxy/haproxy.cfg # # modify the configuration file global log / dev/log local0 info # # add two levels of log files log / dev/log local0 notice # log loghost local0 info [root@haproxy haproxy] # service haproxy restart # # restart the service [root@haproxy haproxy] # touch / etc/rsyslog.d/haproxy.conf # # create Syslog haproxy configuration file [root@haproxy haproxy] # vim / etc/rsyslog.d/haproxy.confif ($programname = = 'haproxy' and $syslogseverity-text = =' info') # # create different log files then-/ var/log/haproxy/haproxy-info.log&~if ($programname = = 'haproxy' and $syslogseverity-text = =' notice') then-/ var/log/haproxy/haproxy-notice.log&~ [root@haproxy haproxy] # systemctl restart rsyslog according to level .service # # restart the Syslog service [root@haproxy haproxy] # cd / var/log/ # # there is no haproxy log # # revisit the web page [root@haproxy haproxy] # cd / var/log/haproxy/ [root@haproxy haproxy] # ls # # the info-level log file haproxy-info.log is generated

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