CentOS 6.4 installation configuration HAProxy-1.4.24

Source: Internet
Author: User
Tags haproxy

CentOS 6.4 installation configuration HAProxy-1.4.24

HAProxy is a free, fast, and reliable proxy solution that supports high availability and Server Load balancer. It is also suitable for proxies for TCP and HTTP-based applications. For some websites with high load, HAProxy is particularly suitable. HAProxy supports tens of thousands of concurrent connections. It is easy to configure and can easily integrate into our existing application architecture.
Next, we will install and configure HAProxy on CentOS 6.4.

Install configurations

Follow these steps:

1wgethttp://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz2tarxvzf haproxy-1.4.24.tar.gz3cdhaproxy-1.4.244makeTARGET=linux265makeinstall

By default, the storage path of the configuration file corresponding to HAProxy is/etc/haproxy. cfg.
The default configuration file is as follows:

01#---------------------------------------------------------------------02# Example configuration for a possible web application. See the03# full configuration options online.04#05#http://haproxy.1wt.eu/download/1.4/doc/configuration.txt06#07#---------------------------------------------------------------------0809#---------------------------------------------------------------------10# Global settings11#---------------------------------------------------------------------12global13# to have these messages end up in /var/log/haproxy.log you will14# need to:15#16# 1) configure syslog to accept network log events. This is done17# by adding the '-r' option to the SYSLOGD_OPTIONS in18# /etc/sysconfig/syslog19#20# 2) configure local2 events to go to the /var/log/haproxy.log21# file. A line like the following can be added to22# /etc/sysconfig/syslog23#24# local2.* /var/log/haproxy.log25#26log 127.0.0.1 local22728chroot /var/lib/haproxy29pidfile /var/run/haproxy.pid30maxconn 400031user haproxy32group haproxy33daemon3435# turn on stats unix socket36stats socket /var/lib/haproxy/stats3738#---------------------------------------------------------------------39# common defaults that all the 'listen' and 'backend' sections will40# use if not designated in their block41#---------------------------------------------------------------------42defaults43mode http44log global45option httplog46option dontlognull47option http-server-close48option forwardfor except 127.0.0.0/849option redispatch50retries 351timeout http-request 10s52timeout queue 1m53timeout connect 10s54timeout client 1m55timeout server 1m56timeout http-keep-alive 10s57timeout check 10s58maxconn 30005960#---------------------------------------------------------------------61# main frontend which proxys to the backends62#---------------------------------------------------------------------63frontend main *:500064acl url_static path_beg -i /static /images /javascript /stylesheets65acl url_static path_end -i .jpg .gif .png .css .js6667use_backend static if url_static68default_backend app6970#---------------------------------------------------------------------71# static backend for serving up images, stylesheets and such72#---------------------------------------------------------------------73backend static74balance roundrobin75server static 127.0.0.1:4331 check7677#---------------------------------------------------------------------78# round robin balancing between the various backends79#---------------------------------------------------------------------80backend app81balance roundrobin82server app1 127.0.0.1:5001 check83server app2 127.0.0.1:5002 check84server app3 127.0.0.1:5003 check85server app4 127.0.0.1:5004 check

Let's give a simple explanation of the content of the above configuration file, which can be expanded as appropriate:

  • Global segment

Global segments are used to configure process-level parameters. Based on the parameter function, the official website classifies global configuration parameters into three groups:

  1. Process Management and Security
  2. Performance Tuning
  3. Debugging

For more information, see the document.

  • Defaults segment

The ults segment mainly refers to the default configuration segment of the proxy configuration and sets the default parameters. These default configurations can be used in other sections configured later. If you want to modify the default configuration parameters in other segments, you only need to overwrite the configuration items that appear in the defaults segment.
For details about the parameters that can be configured for the ults segment, refer to the official website documentation.

  • Frontend Section

The frontend section mainly configures the Socket-related attributes of the front-end listener, that is, the virtual node that receives the request link. In addition to configuring these static attributes, you can also redirect requests to the configured backend based on certain rules. The backend may be configured as a server, it may also be a group of servers (clusters ).

  • Backend segment

The backend segment mainly refers to the information of the configured actual server. It is forwarded to the backend configured server through the redirection request configured by frontend.

  • Listen segment

The listen segment integrates the frontend and backend segments and forwards requests directly from the proxy to the actual backend server.

Start the HAProxy agent

It is very easy to start. Execute the following command:

1sudohaproxy -f /etc/haproxy/haproxy.cfg

Let's simply modify the configuration file and configure a server to balance the backend SolrCloud search cluster, as shown below:

01#---------------------------------------------------------------------02# Global settings03#---------------------------------------------------------------------04global05log 127.0.0.1 local20607chroot /var/lib/haproxy08pidfile /var/run/haproxy.pid09maxconn 400010user haproxy11group haproxy12daemon1314# turn on stats unix socket15stats socket /var/lib/haproxy/stats1617#---------------------------------------------------------------------18# common defaults that all the 'listen' and 'backend' sections will19# use if not designated in their block20#---------------------------------------------------------------------21defaults22mode http23log global24option httplog25option dontlognull26option http-server-close27option forwardfor except 127.0.0.0/828option redispatch29retries 330timeout http-request 10s31timeout queue 1m32timeout connect 10s33timeout client 1m34timeout server 1m35timeout http-keep-alive 10s36timeout check 10s37maxconn 30003839#---------------------------------------------------------------------40# main frontend which proxys to the backends41#---------------------------------------------------------------------42frontend haproxy-lbserver43bind 0.0.0.0:8044acl url_solr_path path_beg /solr-cloud45acl url_static path_beg -i /static /images /javascript /stylesheets46acl url_static path_end -i .jpg .gif .png .css .js4748use_backend static if url_static49use_backend solr-cloud if url_solr_path50default_backend static5152#---------------------------------------------------------------------53# static backend for serving up images, stylesheets and such54#---------------------------------------------------------------------55backend static56balance roundrobin57server static 127.0.0.1:4331 check5859#---------------------------------------------------------------------60# round robin balancing between the various backends61#---------------------------------------------------------------------62backend solr-cloud63balance roundrobin64server solr-1 slave1:8888 check65server solr-2 slave2:8888 check66server solr-3 slave3:8888 check67server solr-4 slave4:8888 check

Frontend is named haproxy-lbserver. In fact, it is mapped to a specific service IP address, bound to port 80, and then the Request Path is set to/solr-cloud, that is, the frontend receives a request similar to "http: // link starting with haproxy-lbserver/solr-cloud. Other request parameters can be added later.
In frontend, The use_backend command is used to specify a backend to be forwarded. The name is solr-cloud. You can use the filter condition command if to specify the backend name after the use_backend command.
Backend specifies the configuration of the actual Cluster Server and performs load balancing on it. A total of four Solr search servers are specified and the roundrobin load balancing policy is used.
We copy the default configuration file to the directory/home/hadoop/shiyanjun/haproxy-1.4.24/conf and then start haproxy:

1sudohaproxy -f /home/hadoop/shiyanjun/haproxy-1.4.24/conf/haproxy.cfg

After the startup is successful, you can access a request link similar to the following:

1Http: // haproxy-lbserver/solr-cloud/mycollection/select? Q = Beijing & fl = * & fq = building_type: 1 & start = 0 & rows = 10

HAProxy forwards the request to the backend Cluster Server for actual request processing.

The official HAProxy documentation is quite detailed. We recommend that you refer to the official documentation to learn about the corresponding configuration options and usage methods.

Reference

  • Http://haproxy.1wt.eu
  • Http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz
  • Http://cbonte.github.io/haproxy-dconv/configuration-1.4.html

Related Article

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.