|
I. HAProxy Introduction
HAProxy provide high availability, load balancing, and proxy TCP and HTTP-based applications, it is free, fast and reliable a solution. HAProxy especially for those who load oversized web sites that usually they need to maintain or seven treatment sessions. HAProxy run on current hardware, can support thousands of concurrent connections. And its mode of operation so that it can easily be integrated into your current security architecture, while protecting your web server is not exposed to the network.
HAProxy implements an event-driven, single process model that supports a very large number of concurrent connections. Multi-process or multi-threaded model memory-bound, system scheduler limits and restrictions everywhere in the lock, rarely able to handle thousands of concurrent connections. Event-driven model because there are better resources and time management client (User-Space) to achieve all of these tasks, there is no such problem. The drawbacks of this model is that in the multi-core system, these programs are usually poor scalability. That is why they must be optimized so that each CPU time slice (Cycle) to do more work. The following figure shows the HAProxy load balancing application model:
II. FEASIBILITY
For many advantages HAProxy will apply CORS (Continuous Operating GPS integrated system) can effectively improve the operation and maintenance of existing maximum load capacity, reduce the waste of hardware resources, and ensure system availability and stability . Specifically, set forth in the following aspects:
1. TCP-based proxy server acts as a proxy in the reference station data stream distribution process function;
2. TCP proxy user access and data delivery processes for load balancing based on the role of balancer;
For the number of users, high concurrency of CORS, the use of external service request HAProxy corresponding port to the control center of the internal network of a plurality of identical function application (such as IGate / TNC, etc.) of port services, can HAProxy a variety of ways (IP, cookie, session) to keep tcp link affinity to ensure the correctness of data interaction. Numerous load-balancing algorithms, internal shared service program overall service pressure, when a program down off, HAProxy can automatically distribute relevant tcp links to other service programs. HAProxy achieve eight kinds of load balancing algorithms:
roundrobin, it represents a simple poll
static-rr, expressed according to the weight, may empower according to server performance
leastconn, it represents the minimum connection, first processing
source, the request indicates the source IP
uri, according to the requested URI represents
url_param, expressed according to URl request parameter 'balance url_param' requires an URL parameter name
hdr (name), it represents the HTTP request header lock every HTTP request
rdp-cookie (name), according to data showing cookie (name) to lock and hash every TCP request
3. Based on tcp proxy to achieve internal network firewall NAT function.
three .HAProxy installation and configuration
text prepared HAProxy latest stable version of the download address: http: //haproxy.1wt.eu/download/1.4/src/haproxy-1.4.25.tar.gz.
1.Linux under HAProxy installation
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 the configuration file, a unified set forth the relevant configuration details later
/ Usr / local / haproxy / sbin / haproxy -f /usr/local/haproxy/haproxy.cfg just use the configuration file to start HAProxy
2. Windows under HAProxy compile and install
Download the cygwin installation tool when preparing their articles 64 download address: https: //cygwin.com/setup-x86_64.exe. Run the program, the program screenshot below:
Install gcc, state Keep the machine is installed, check the box, if not installed Bin column
Installation make tools.
Download HAProxy Source Package copied to: C: cygwin64 home, and unzip to the directory,
Use Cywin64 Terminal command-line tool to enter HAProxy catalog:
make TARGET = cygwin
make install so haproxy.exe it translated well, and will haproxy.exe cygwin1.dll copy it for use.
Consistent with the operating mode under Linux environment.
3.HAProxy configuration file parsing
######## default configuration ############ defaults mode http # default mode mode {tcp | http | health}, tcp is four layers, http is a layer 7, health will only return OK retries 2 # connection fails twice that it is the server is unavailable, you can also set back option redispatch # when serverId corresponding server hang, forcing directed to other healthy servers option abortonclose # when high server load time, automatic off the end of the current relatively long queue processing link maxconn 4096 # the default maximum number of connections timeout connect 5000ms # connection timeout timeout client 30000ms # client timeout timeout server 30000ms # server timeout #timeout check 2000 # = heartbeat timeout log 127.0.0.1 local0 err # [err warning info debug] ######## ######## statistics configuration page listen admin_stats bind 0.0.0.0:1080 # listening port mode http #http seven-layer model option httplog # using http log format #log 127.0.0.1 local0 err maxconn 10 stats refresh 30s # statistics page automatically refresh time stats uri / stats # statistics page url stats realm XingCloud prompt text on the statistics page password box Haproxy # stats auth admin: admin # statistics page the user name and password setting on stats hide-version # Hide statistics page HAProxy version information ##### ### test1 configuration ################# 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 configuration ############## ######## test2 configuration ################# 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 configuration ##############
4. Examples of test
To test the effect of running we use the simplest configuration to make a simple tcp proxy:
########## globally ######### global daemon nbproc 1 pidfile /var/run/haproxy.pid ######## default configuration ############ defaults mode http # default mode mode {tcp | http | health}, tcp is four layers, http is a layer 7, health will only return OK retries 2 # connection failure is considered to be twice server is unavailable, you can also set the option redispatch # when serverId corresponding server hangs behind the rear by forcibly directed to other healthy servers option abortonclose # when high server load time, automatically ends out the current queue processing relatively long link maxconn 4096 # the default maximum number of connections timeout connect 5000ms # connection timeout timeout client 30000ms # client timeout timeout server 30000ms # server timeout #timeout check 2000 # = heartbeat timeout log 127.0.0.1 local0 err # [err warning info debug] ######## statistics page layout ######## listen admin_stats bind 0.0.0.0:1080 # listening port mode http #http seven-layer model using the option httplog # http log format #log 127.0.0.1 local0 err maxconn 10 stats refresh 30s # statistics page automatically refresh time stats uri / stats # statistics page url stats realm XingCloud prompt on the statistics page Haproxy # password text box stats auth admin: admin # statistics page the user name and password setting on stats hide-version # Hide statistics page HAProxy version information ######## test1 configuration ################# 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 configuration ############## ######## test2 configuration ################# 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 configuration ############## |
|
|
|