Haproxy Simple to use

Source: Internet
Author: User

I. Introduction and orientation of Haproxy

The HAProxy is a high-availability, load-balanced agent software based on TCP and HTTP applications. The Haproxy is completely free, and with haproxy you can quickly and reliably deliver proxy solutions based on TCP and HTTP applications. The main feature of Haproxy is its superior performance, especially with Web sites that are overloaded with load, which typically require session-keeping or seven-tier processing. Haproxy can fully support tens of thousands of concurrent connections. and Haproxy's operating mode makes it easy and secure to integrate information into the current architecture while protecting the subsequent Web servers from being exposed.

Haproxy has a reverse proxy server and other functions, simple configuration, has a very good server health check function. In the event of a failure of the backend server of the schedule agent, Haproxy will automatically remove the server and add it automatically after the fault is restored.

Ii. comparison of Haproxy and Nginx

Nginx and Haproxy, which also have a 7-layer load function, have many similar aspects, such as matching rules. If only in terms of efficiency, haproxy than Nginx has a better load-balancing speed, and in concurrent processing also in Nginx.

Haproxy can not only compensate for some of the nginx, such as the session to maintain the work, and support URL detection for detection, the problem of the later server is very good help.

Nginx support for the big Request Header is not very good, if the client_header_buffer_size set the value is relatively small, it will return to the error page of the bad request.

Third, the installation of Haproxy

Installing with Yum

Yum Install Haproxy.x86_64–y

After the installation is complete, you can start the Haproxy service

/etc/init.d/haproxy start

After starting the service, let's modify the configuration file.

Global # #local2/var/log/haproxy.log #日志位置 # log 127.0.0.1 local2 chroot                          /var/lib/haproxy pidfile/var/run/haproxy.pid maxconn 4000 #最大连接数 User Haproxy #用户名 Group haproxy #组 Daemon # turn on stats Unix sock ET stats socket/var/lib/haproxy/stats#---------------------------------------------------------------------# Common defaults that all the ' listen ' and ' backend ' sections will# with if not designated in their block#------------------                     ---------------------------------------------------defaults mode HTTP #模式 log Global #日志 option httplog option dont    Lognull option http-server-close option forwardfor except 127.0.0.0/8 option Redispatch       Retries 3           #重试次数 Timeout Http-request 10s #请求超时时间 Timeout queue 1m timeout connect 10s #连接超时时间 Timeout Client 1m #客户端超时 timeout server 1m t Imeout http-keep-alive 10s timeout check 10s maxconn #最大连接数量 stats  Uri/haproxy_status #监控页面地址 #---------------------------------------------------------------------# Main  Frontend which proxys to the backends#---------------------------------------------------------------------frontend       Main *:80 #监听端口 # ACL url_static path_beg-i/static/images/javascript/stylesheets # ACL Url_static             path_end-i. jpg. gif. png. css. JS # use_backend static if Url_static # Default_backend App ACL Is_zabbix Path_beg/zabbix #如果请求是以/zabbix End uses Zabbix_app this application to implement reverse proxy use_backend za Bbix_app if Is_zabbix defAult_backend tomcat_app#---------------------------------------------------------------------# static backend for S Erving up images, stylesheets and such#---------------------------------------------------------------------#                           Backend static# balance roundrobin# server static 127.0.0.1:4331 checkbackend Zabbix_app                          #配置后台应用 Zabbix_app Balance roundrobin server App1 127.0.0.1:8083 checkbackend Tomcat_app #配置后台应用 Tomcat_app balance Roundrobin #负载均衡方式, use random server App1 127.0.0.1:8081 check #服务器1 server APs P2 127.0.0.1:8082 Check #服务器2 #---------------------------------------------------------------------# round robin Bal Ancing between the various backends#---------------------------------------------------------------------backend App Balance Roundrobin server App1 127.0.0.1:8081 Check server app2 127.0.0.1:8082 Check server APP3 12 7.0.0.1:8083 Check

Reload the Haproxy configuration file

/etc/init.d/harpoxy Reload

And see if the installation was successful

Enter Http://192.168.0.65/haproxy_status in the address bar

Page below


To be able to see that my zabbix_app was normal, my tomcat_app didn't start, so it was red

In this page can clearly see the haproxy traffic, the total flow

If there is insufficient, please correct me, thank you!

Haproxy Simple to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.