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

Haproxy builds web clusters-- (practice! )

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

Share

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

Common web Cluster Scheduler

At present, the common web cluster scheduler is divided into software and hardware, the software usually uses the open source LVS,Haproxy,Nginx, the hardware is generally used by F5, and many people use some domestic products, such as barracuda, Green League and so on.

Haproxy application analysis LVS has strong anti-load ability in enterprise applications, but it has some shortcomings. LVS does not support regular processing and can not achieve dynamic and static separation. For large websites, the implementation configuration of LVS is complex, and the maintenance cost is relatively high. Haproxy is a high availability, load balancing. The software of agents based on TCP and HTTP applications is especially suitable for web sites with particularly heavy loads. On current hardware, it can support tens of thousands of concurrent connection requests Haproxy scheduling algorithm principle RR: the simplest and most commonly used, polling scheduling LC: minimum number of connections algorithm, dynamic allocation of front-end requests SH according to the number of back-end node connections: source access scheduling algorithm for recording session sessions on the server side The experimental topology diagram of cluster scheduling can be made based on the source ip,cookie

Experimental environment Haporxy server 192.168.13.175web1 server 192.168.13.151web2 server 192.168.13.176client test machine 1, in web1 Install Nginx [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 web 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 02 Install the haproxy scheduling service on the haproxy server [root@haproxy ~] # yum install-y\ # install environment component tools > pcre-devel\ > bzip2-devel\ > gcc\ > gcc-c++\ > make [root@haproxy ~] # systemctl stop firewalld.service # # close 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/ # # decompress [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 [root@haproxy haproxy-1.5.19] # cp examples/haproxy.cfg / etc/haproxy/ # # template copy to 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 client to test web pages

4, log definition Modify haproxy configuration file [root@haproxy haproxy] # vim / etc/haproxy/haproxy.cfg # # modify 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@] according to level Haproxy haproxy] # systemctl restart rsyslog.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 at this time!

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