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

Why Haproxy load balancing reverse proxy is better than nginx

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

Share

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

The following brings you why Haproxy load balancing reverse proxy is better than nginx. I hope it can bring some help to you in practical application. Load balancing involves more things, there are 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.

[Haproxy load balancing reverse proxy is better than nginx]

HAProxy provides high availability, load balancing, agents based on TCP and HTTP applications, and supports virtual hosts. It is a free, fast and reliable solution. HAProxy is especially suitable for heavily loaded web sites, which usually require session persistence or seven-tier processing. HAProxy runs on current hardware and can support tens of thousands of concurrent connections. And its operation mode makes it easy and safe to integrate into your current architecture, while protecting your web CVM from being exposed to the network.

HAProxy implements an event-driven, single-process model that supports a very large number of concurrent connections. Multiprocess or multithreaded models rarely handle thousands of concurrent connections due to memory constraints, system scheduler limitations, and ubiquitous locks. The event-driven model does not have these problems because it implements all these tasks in the user space (User-Space) with better resource and time management. The drawback of this model is that on multi-core systems, these programs are usually poorly scalable. This is why they have to optimize so that each CPU time slice (Cycle) does more work.

[load balancing]

[set network card]

The next two Apache servers are changed to hostonly network without changing the default information.

192.168.3.5 ifconfig eth4 192.168.3.5/24 up route add default gw 192.168.3.4192.168.3.6 ifconfig eth4 192.168.3.6/24 up route add default gw 192.168.3.4192.168.3.5 service iptables stop service httpd start192.168.3.6 service iptables stop service httpd start

[access Test] http://192.168.3.6/

[access Test] http://192.168.3.5/

[route View]

[root@localhost] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.3.0 0.0.0.0 255.255.255.0 U 000 eth4172.16.0.0 0.0.0.0 255.255.0.0 U 100 eth30.0.0.0 192. 168.3.4 0.0.0.0 UG 0 0 0 eth40.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth3

[delete the route that added the error]

Route del-net 0.0.0.0 route del 32 gw 192.168.3.4

[install haproxy]

My system is CentOS 6.3x64 without native haproxy

Change the disc of CentOS 6.6x64

Yum clean all

Yum-y install haproxy

Cd/etc/haproxy/

Cphaproxy.cfg haproxy.cfg.bak

[set log]

Vim / etc/sysconfig/rsyslog# If you want to use them Switch to compatibility mode 2 by "- c 2" # See rsyslogd (8) for moredetailsSYSLOGD_OPTIONS= "- c 2-r" vim / etc/rsyslog.conf changed to # Save boot messages also to boot.loglocal7.* / var/log/boot.log local2.* / var/log/haproxy.log

[restart Syslog service] service rsyslog restart

[modify configuration]

Cd / etc/haproxy/* deleted * * #- -# main frontend which proxys to the backends #-frontend main *: 5000 acl url_static path_beg-I / static / p_w_picpaths / javascript/stylesheets acl url_ Static path_end-I .jpg .gif .png .css .js use_backend static if url_static default_backend app #-# static backend for serving up p_w_picpaths Stylesheets and such #-backendstatic balance roundrobin server static 127.0.0.1 check 4331 -# round robin balancing between the various backends #- -backendapp balance roundrobin server app1 127.0.0.1 check server app2 5001 check server app3 127.0.0.1 check server app3 127.0.0.1 check server app3 5003 check server app4 127.0.0.1 check** delete and continue to write after * * listen stats mode http bind *: 1080 stats enable stats hide-version stats uri / haproxyadmin?stats stats realm Haproxy\ Statistics stats auth admin:admin stats admin if TRUE frontend web bind *: 80 log global option httpclose option logasap option dontlognull capture request header Host len 20 capture request header Referer len 60 default_backend servers backend servers balance roundrobin server web1 192.168.3.5 log global option httpclose option logasap option dontlognull capture request header Host len 80 check maxconn4000 server web2 192.168.3.6 Statistics stats auth admin:admin stats admin if TRUE frontend web bind 80 check maxconn3000

*

[restart service]

Service haproxy restartnetstat-tnulp | grep "80" tcp 0 0 0.0.0. 0 tcp 80 0.0.0. 0. 0 LISTEN 4639/haproxy tcp * LISTEN 4639/haproxy tcp 0 0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.

[see progress] ps auxf

Haproxy 4639 0.0 0.1 47564 1588? Ss 02:35 0:00 / usr/sbin/haproxy-D-f / etc/haproxy/haprox

[make sure that the firewall of http://192.168.3.6/ and http://192.168.3.5/ is OK, and that Apache is turned on]

[test http://172.16.0.102/] can achieve the effect of load balancing, IE browser Firefox browser roaming is not obvious

[haproxy Management Page] http://172.16.0.102:1080/haproxyadmin?stats admin admin

You can see the details of the number of server

Manually shut down a httpd service service httpd stop, and then refresh this page, and an exception occurs immediately

After reading the above about why Haproxy load balancer reverse proxy is better than nginx, 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 engineer to answer it. 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

Network Security

Wechat

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

12
Report