Haproxy Compile and install configuration

Source: Internet
Author: User
Tags haproxy

First, Introduction

Haproxy provides high availability, load balancing, and proxies based on TCP and HTTP applications, supporting virtual hosting, which is a free, fast, and reliable solution. Haproxy is especially useful for Web sites that are heavily loaded, and often require session-hold or seven-tier processing. The haproxy runs on the current hardware and can support tens of thousands of concurrent connections. and its operating mode makes it easy and safe to integrate into your current architecture, while protecting your Web server from being exposed to the web.

Haproxy implements an event-driven, single-process model that supports very large number of concurrent connections. A multi-process or multithreaded model is rarely capable of handling thousands of concurrent connections because of memory limitations, System scheduler restrictions, and ubiquitous lock limits. The event-driven model does not have these problems because it implements all of these tasks on the client side (User-space) with better resource and time management. The disadvantage of this model is that, on multicore systems, these programs often have poor extensibility. That's why they have to be optimized so that each CPU time slice (Cycle) does more work.

------Encyclopedia Information

Second, haproxy installation configuration

① Installation

# wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.14.tar.gz# tar-zxvf haproxy-1.5.14.tar.gz# CD haproxy-1.5.14# make target=linux2628 arch=x86_64 # #TARGET指定内核版本, ARCH specifies CPU architecture # make install install-d "/usr/local/sbin" Install Haproxy "/usr/local/sbin" Install Haproxy-systemd-wrapper "/usr/local/sbin" install-d "/usr/local/share/man"/ Man1install-m 644 doc/haproxy.1 "/usr/local/share/man"/man1install-d "/usr/local/doc/haproxy" for x in Configuration Architecture Haproxy-en HAPROXY-FR; Do install-m 644 doc/$x. txt "/usr/local/doc/haproxy"; Done


Ii. Creating configuration files and startup files

# mkdir/etc/haproxy# CP haproxy-1.5.14/examples/haproxy.cfg/etc/haproxy/# CP haproxy-1.5.14/examples/haproxy.init/ etc/init.d/haproxy# chmod u+x/etc/init.d/haproxy# ln-s/usr/local/sbin/haproxy/usr/sbin/# mkdir/usr/share/haproxy


Third, edit the configuration file

# vi /etc/haproxy/haproxy.cfgglobal                         ------Global Configuration------         log 127.0.0.1   local0   # #日志输出配置 , all logs are recorded on this machine, via local0 output         log 127.0.0.1    local1 notice         #log  loghost     local0 info        maxconn 4096                      # #最大连接数         chroot /usr/share/haproxy           # #chroot运行路径         uid 99                          ## Owned by user uid        gid 99                               # #所属运行的GID         daemon                           # #以后台形式运行haproxy          #debug                            # #调试模式, output boot information to standard output          #quiet                            # #安静模式, no output defaults               at startup        ------Default Configuration-----        log      global        mode     http    # #默认模式 {tcp|http|health},tcp is Layer 4, HTTP is level 7, health will only return ok         option  httplog          # #日志类别: HTTP log format         option  dontlognull            # #不记录健康检查的日志信息          retries 3                        # #3次连接失败就认为服务不可用          Option  redispatch          # #ServerID对应的服务器挂掉后, force directed to other health servers          maxconn 4000                          # #默认最大连接数         timeout connect      5000                      # #连接超时         timeout client       50000                    # #客户端超时         timeout server       50000                     # #服务端超时         listen  web-proxy  192.168.10.128:8000        mode http         option  httpchk /index.html         balance roundrobin                           # #算法          server  web1 192.168.10.129:80 cookie server01 check  inter 2000 rise 2 fall 3        server   web2 192.168.10.130:80 cookie server02 check inter 2000 rise  3 fall 3        # #服务器定义 (check refers to health checkup,inter  2000 refers to the frequency of detection, rise 2 refers to the number of successful checks from the offline state to the normal state; fall  3 refers to failure 3 times that the server is not available) listen status                                  # #监控页面设置         mode http                               # #http的7层模式         bind  0.0.0.0:1080                     # #监听端口         stats enable                                   stats hide-version                      ## Hide Haproxy version information on the statistics page         stats uri      /haproxyadmin           # #监控页面URL          stats auth    admin:admin                   # #监控页面用户名和密码          stats admin if TRUE                # #手工启用, disabling back-end servers


Error:

[warning] 286/001645  (41708)  : parsing [/etc/haproxy/haproxy.cfg:21]: keyword   ' Redispatch '  is deprecated in favor of  ' Option redispatch ',  and  will not be supported by future versions. [warning] 286/001645  (41708)  : parsing [/etc/haproxy/haproxy.cfg:23] : the   ' contimeout '  directive is now deprecated in favor of  ' timeout  connect ',  and will not be supported in future versions. [warning] 286/001645  (41708)  : parsing [/etc/haproxy/haproxy.cfg:24] : the   ' clitimeout '  directive is now deprecated in favor of  ' timeout  client ',  and will not be supported in future versions. [warning] 286/001645  (41708)  : parsing [/etc/haproxy/haproxy.cfg:25] : the  ' Srvtimeout '  directive is now deprecated in  favor of  ' Timeout server ',  and will not be supported in  future versions.

Workaround: Change the name of the appropriate option as prompted


Iv. Configuration Log files

# vi/etc/rsyslog.conflocal0.*/var/log/haproxy.log# systemctl Restart Rsys Log


V. Enable and view Haproxy

① Enable and disable Haproxy

A.

# haproxy-f/etc/haproxy/haproxy.cfg # #开启haproxy # yum Install Psmisc # #注: Minimize installation centos7 no killall command # Killall Haproxy # #关闭haproxy


B.

# systemctl Start Haproxy # #开启haproxy # systemctl Stop Haproxy # #关闭haproxy

② Login Page view

Browser input http://localhost:1080/haproxyadmin, enter the account password to view

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/70/wKioL1Yd1-qC4UWpAAY1AJAS0cI598.jpg "title=" QQ picture 20151014121854.jpg "alt=" Wkiol1yd1-qc4uwpaay1ajas0ci598.jpg "/>


Note: Because Web1 and WEB2 are not enabled, they are down.


This article is from the Notepad blog, so be sure to keep this source http://wangzhijian.blog.51cto.com/6427016/1702795

Haproxy Compile and install configuration

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.