I. Haproxy INTRODUCTION
Haproxy provides high availability, load balancing, and proxies based on TCP and HTTP applications, 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. Demonstrates the Haproxy load Balancer Application Model:
Two. Application Feasibility
Due to the many advantages of haproxy, it is applied to cors (continuous Operation satellite location service integrated system) operation and maintenance work can effectively improve the existing maximum load capacity, reduce the waste of hardware resources, ensure the availability and stability of the system. In particular, the following aspects can be elaborated:
1. The function of acting as proxy server in the Datum station data flow distribution process based on TCP agent;
2. Based on the TCP agent in the user access and data broadcast process to play the role of load balancer equalizer;
For cors with a large number of users and high concurrency, use haproxy to correspond to the service ports of the external service port's requests to multiple applications of the same function (such as IGATE/TNC, etc. ) in the control center's internal network. Haproxy can maintain the affinity of TCP links in various ways (IP, Cookie,session) to ensure the correctness of data interaction. Through a variety of load balancing algorithms, the internal service program shares the overall service pressure, when a program is down, Haproxy can automatically distribute the relevant TCP links to other service programs. The Haproxy implements 8 load balancing algorithms:
- Roundrobin, which represents a simple polling
- STATIC-RR, which is based on the weight, can be weighted according to the server performance
- Leastconn, indicating that the minimum number of connections is processed first
- Source, which represents the origin IP based on the request
- URI that represents the URI according to the request
- Url_param, which represents the URL parameter according to the request ' balance Url_param ' requires an URL parameter name
- HDR (name), which indicates that each HTTP request is locked according to the HTTP request header
- Rdp-cookie (name), which indicates that each TCP request is locked and hashed according to the cookie (name)
3. The NAT function of the firewall that implements the internal network based on the TCP proxy.
Three. Installation and configuration of Haproxy
this article Write the latest stable version of Haproxy is: http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.25.tar.gz.
Installation of Haproxy under 1.Linux
- tar zcvf haproxy-1.4.25.tar.gz
- CD haproxy-1.4.25
- Make target=linux28 Prefix=/usr/local/haprpxy
- Make install Prefix=/usr/local/haproxy
- Cd/usr/local/haproxy
- vim haproxy.cfg edit configuration file, followed by a unified description of the configuration of the relevant details
- /usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg Use the configuration file that you just started Haproxy
2. Compilation and installation of Haproxy under Windows
- Download the Cygwin installation tool, when the article was written with 64 bits: Https://cygwin.com/setup-x86_64.exe. To run the program, the program is as follows:
- Install GCC, the status of keep is installed, if not installed check the bin column box
- Install the Make tool.
- Copy the downloaded Haproxy source package to: C:\cygwin64\home, and extract it to the directory,
- Use the Cywin64 Terminal command-line tool to enter the Haproxy directory:
- Make target=Cygwin
- Make install so that Haproxy.exe is compiled, Haproxy.exe and cygwin1.dll are copied out for use.
- Run in a manner consistent with the Linux environment.
3.HAProxy configuration file parsing
####### #默认配置 ############
Defaults
Mode http #默认的模式mode {tcp|http|health},tcp is Layer 4, HTTP is 7 layer, health will only return OK
Retries 2 #两次连接失败就认为是服务器不可用, can also be set by the following
Option Redispatch #当serverId对应的服务器挂掉后, Force-directed to other healthy servers
Option Abortonclose #当服务器负载很高的时候 to automatically end the link that is being processed for the current queue
Maxconn 4096 #默认的最大连接数
Timeout Connect 5000ms #连接超时
Timeout client 30000ms #客户端超时
Timeout Server 30000ms #服务器超时
#timeout Check 2000 #= Heartbeat timeout
Log 127.0.0.1 local0 err #[err warning Info Debug]
####### #统计页面配置 ########
Listen Admin_stats
Bind 0.0.0.0:1080 #监听端口
Mode HTTP #http的7层模式
Option Httplog #采用http日志格式
#log 127.0.0.1 Local0 Err
Maxconn 10
Stats Refresh 30s #统计页面自动刷新时间
Stats Uri/stats #统计页面url
Stats Realm xingcloud\ Haproxy #统计页面密码框上提示文本
Stats Auth Admin:admin #统计页面用户名和密码设置
Stats Hide-version #隐藏统计页面上HAProxy的版本信息
####### #test1配置 #################
Listen Test1
Bind 0.0.0.0:90
Mode TCP
#maxconn 4086
#log 127.0.0.1 local0 Debug
Server S1 10.18.138.201:80
Server S2 10.18.102.190:80
Server S3 10.18.102.189:80
Server S4 10.18.102.188:80
Server S5 10.18.102.187:80
####### #frontend配置 ##############
####### #test2配置 #################
Listen Test2
Bind 0.0.0.0:91
Mode TCP
#maxconn 4086
#log 127.0.0.1 local0 Debug
Server S1 10.18.138.130:80 weight 1
Server S2 10.18.138.201:8080 Weight 6
####### #frontend配置 ##############
4. Example Test
To test the effect of the run we use the simplest configuration to make a simple TCP proxy:
######### #全局配置 #########
Global
Daemon
Nbproc 1
Pidfile/var/run/haproxy.pid
####### #默认配置 ############
Defaults
Mode http #默认的模式mode {tcp|http|health},tcp is Layer 4, HTTP is 7 layer, health will only return OK
Retries 2 #两次连接失败就认为是服务器不可用, can also be set by the following
Option Redispatch #当serverId对应的服务器挂掉后, Force-directed to other healthy servers
Option Abortonclose #当服务器负载很高的时候 to automatically end the link that is being processed for the current queue
Maxconn 4096 #默认的最大连接数
Timeout Connect 5000ms #连接超时
Timeout client 30000ms #客户端超时
Timeout Server 30000ms #服务器超时
#timeout Check 2000 #= Heartbeat timeout
Log 127.0.0.1 local0 err #[err warning Info Debug]
####### #统计页面配置 ########
Listen Admin_stats
Bind 0.0.0.0:1080 #监听端口
Mode HTTP #http的7层模式
Option Httplog #采用http日志格式
#log 127.0.0.1 Local0 Err
Maxconn 10
Stats Refresh 30s #统计页面自动刷新时间
Stats Uri/stats #统计页面url
Stats Realm xingcloud\ Haproxy #统计页面密码框上提示文本
Stats Auth Admin:admin #统计页面用户名和密码设置
Stats Hide-version #隐藏统计页面上HAProxy的版本信息
####### #test1配置 #################
Listen Test1
Bind 0.0.0.0:81
Mode TCP
#maxconn 4086
#log 127.0.0.1 local0 Debug
Server S1 192.168.1.200:8000
Server S1 192.168.1.201:8001
Server S1 192.168.1.202:8002
####### #frontend配置 ##############
####### #test2配置 #################
Listen Test2
Bind 0.0.0.0:91
Mode TCP
#maxconn 4086
#log 127.0.0.1 local0 Debug
Server S1 192.168.1.100:9000
Server S1 192.168.1.101:9001
Server S1 192.168.1.102:9002
####### #frontend配置 ##############