Article Title: High-concurrency Web Access: Load Balancing with HAPorxy. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
HAProxy is a reverse proxy server that enables load balancing. It supports dual-host hot standby and supports Virtual Hosts, but its configuration is simple and has a very good server health check function. When the proxy's backend server fails, HAProxy will automatically remove the server, after the fault is restored, the server is automatically added. The new 1.3 introduces frontend, backend, and frontend to match rules based on any HTTP request header content, and then directs the request to the relevant backend.
Load Balancing using HAPorxy
1. Load Balancing using HAProxy
192.168.169.small (haproxy) --- Server Load balancer ---- (192.168.169.117; 192.168.169.118)
Install and configure HAproxy
Cd/usr/local/
Wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.14.2.tar.gz
Tar zxvf haproxy-1.3.14.2.tar.gz
Music haproxy-1.3.14.2 haproxy
Cd haproxy
Make TARGET = linux26
2. Create a configuration file
# Vi haproxy. cfg
Global
Maxconn 5120
Chroot/usr/local/haproxy
Uid 99
Gid 99
Daemon
Quiet
Nbproc 2 # set several more haproxy concurrent processes through nbproc, so that the task_queue of each process will be much shorter, and the performance will naturally improve a lot
# Pidfile/var/run/haproxy-private.pid
Ults
Log global
Mode http
Option httplog
Option dontlognull
Log 127.0.0.1 local3
Retries 3
Option redispatch
Maxconn 2000
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Listen webfarm 0.0.0.0: 80
Mode http
Stats uri/haproxy-stats # monitor the haproxy status
Stats realm Haproxy \ statistics
Stats auth netseek: 52 netseek # Set the user name for status monitoring to netseek and the password to 52 netseek
Balance roundrobin # Load Balancing Algorithm
Cookie SERVERID insert indirect
Option httpclose #
Option forwardfor # apache Log forwarding function
Option httpchk HEAD/check.txt HTTP/1.0 # Health Check
Server app_bbs1 192.168.169.117: 80 cookie app1inst1 check inter 2000 rise 2 fall 5
Server app_bbs2 192.168.169.118: 80 cookie app1inst2 check inter 2000 rise 2 fall 5
Add a line to syslog. conf
Local3. */var/log/haproxy. log
# Touch/var/log/haproxy. log
# Chown haproxy: haproxy/var/log/haproxy. log
# Chmod u + x/var/log/haproxy. log
# Tail? F/var/log/harpoxy. log monitoring log
#./Haproxy-f haproxy. cfg start the service.
Http: // 192.168.169.20./ haproxy-stats. Enter the user name and password to view the status.
Backend apache log processing
Configure httpd. conf
LogFormat "% {X-Forwarded-For} I % l % u % t \" % r \ "%> s % B" combined
CustomLog/var/log/httpd/access_log combined
The VM does not record the Detection Log:
SetEnvIf Request_URI "^/check \. txt $" dontlog
LogLevel warn
ErrorLog/var/log/httpd/vhost_error.log
CustomLog/var/log/httpd/vhost_access.log combined env =! Dontlog
Introduction
#./Haproxy? Help // haproxy command parameters.
Haproxy-f <配置文件> [-N maximum number of concurrent connections] [-N maximum number of concurrent connections for each listener] [-d] [-D] [-q] [-V] [-c] [- p ] [-S] [-l] [-dk]
[-Ds] [-de] [-dp] [-db] [-m <内存限制m> ] [{-Sf |-st} pidlist...]
-D front-end, debug mode
-D daemon mode startup
-Q quiet mode, no output information
-V verbose mode
-C. Check the syntax of the configuration file
-S display statistics
-L show detailed statistics
-Dk does not use kqueue
-Ds does not use speculative epoll
-De does not use epoll
-Dp does not use poll
-Disable the background mode for db and run the program on the foreground.
-Sf
After the program starts, it sends the FINISH signal to the process in the pidlist. this parameter is placed at the end of the command line.
-St
After the program starts, it sends the TERMINATE signal to the process in the pidlist. this parameter is placed at the end of the command line.