First try to use haproxy for Load Balancing

Source: Internet
Author: User
Tags apache log haproxy
Let's talk about some irrelevant topics first! I haven't posted any post for a long time. Sorry! I have been busy working recently. Thank you for choosing linuxpk and netseek! (). In fact, I am also a real newbie. Writing these articles is also a good summary of my own learning. More importantly, I will help those who like new technologies and Linux, learning related knowledge helps. Although I am a cainiao, I have met many friends on the Internet from my school to my graduation work, helping my work and life! A lot of gains! Thank you!
Just as at the beginning of my graduation, Brother platinum told me on the internet that my elder friend was my gold bucket and I didn't even know what it meant (PS: don't laugh !). The most precious thing in life is to meet some like-minded friends and work together to fight for tomorrow!
Although some people haven't been in touch with them for a long time, I will keep in mind everyone's help! Thanks again!
We are most pleased to announce the release of the <open source> e-Magazine [: http://bbs.linuxpk.com/thread-12999-1-1.html#. I hope to learn more about linux! Write more notes to help friends who are interested in Linux on the Internet, and hope that linuxpk (Linux inventory) the Forum can truly become an interactive discussion platform for everyone to learn and meet friends! Now, I hope you can work together! (PS: If you are too old, it will be too much !).

1. Introduction to haproxy
The reverse proxy server supports dual-host hot standby and supports Virtual Hosts, but it is easy to configure and has a very good server health check function. When the back-end server of the proxy fails, haproxy will automatically remove the server, and then automatically add the server after the fault is recovered. 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.

Ii. 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

Code:

Bytes --------------------------------------------------------------------------------------------------------------------
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

defaults
        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.


Harproxy.jpg
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

Iii. Introduction
#./Haproxy-help // command parameters related to haproxy.
Haproxy-F <Configuration File> [-N maximum number of concurrent connections] [-N maximum number of concurrent connections for each listener] [-D] [-D] [-q] [-V] [-C] [-P <pid File>] [-S] [-L] [-dk]
[-Ds] [-de] [-DP] [-dB] [-M <memory limit 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 <pidlist>
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 <pidlist>
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.
Iv. More advanced application references
Official reference: http://haproxy.1wt.eu/download/1.3/doc/haproxy-en.txt
Http://www.howtoforge.com/high-a... artbeat-Debian-Etch
 

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.