Centos haproxy Server Load balancer

Source: Internet
Author: User
Tags haproxy

I. Topology



Ii. Install Server Load balancer Software

Wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.18.tar.gz
Tar zxvf haproxy-1.4.18.tar.gz
Cd haproxy-1.4.18
Uname-
Make TARGET = linux26 PREFIX =/usr/local/haproxy
Make install PREFIX =/usr/local/haproxy

3. Configure haproxy

Vi haproxy. cfg
######################################## ###############
Global
Maxconn 5120
Chroot/usr/local/haproxy
Uid 100
Gid 100
Daemon
Quiet
Nbproc 2
Pidfile/usr/local/haproxy. pid
######################################## ################

Ults
Log global
Log 127.0.0.1 local3
Mode http
Option httplog
Option dontlognull
Option redispatch
Retries 3

Maxconn 3000
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
######################################## ##################

Listen web 192.168.1.250: 80
Mode http
# Mode tcp
Balance roundrobin
Option forwardfor
Option httpclose
Option httpchk GET/index.html
Server web1 192.168.1.ight: 80 check inter 5000 fall 1 rise 2 weight 1
Server web2 192.168.1.252: 80 check inter 5000 fall 1 rise 2 weight 1
######################################## ##################

Listen status 192.168.1.250: 8080
Stats enable
Stats uri/admin
Stats auth admin: admin
Stats realm Haproxy \ statistic
######################################## ##################

################### Successfully configured haproxy ############### ##

4. Start:/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy. cfg

For ease of use, I will write a shell STARTUP script:

Vi/etc/rc. d/init. d/haproxy
#! /Bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
Servername = haproxy
Serverdir =/usr/local/haproxy
Daemon =/usr/local/haproxy/sbin/haproxy
Config =/usr/local/haproxy. cfg
Pidfile =/usr/local/haproxy. pid

./Etc/rc. d/init. d/functions

Case "$1" in

Start)
$ Daemon-f $ config
Echo "......"
;;

Stop)
Server_id = 'cat $ pidfile'
Kill $ server_id
Echo "......."
;;

Restart)
$ Daemon-f $ config-p $ pidfile-sf $ (cat $ pidfile)
Echo "......."
;;

*)
Echo "Usage: $0 {start | stop | restart }"
Exit 1
Esac

######################################## ##################################

V. Test

Web1 --------> ip: 192.168.1.20.------------> index.html -------------> the is web1

Web2 --------> ip: 192.168.1.252 ------------> index.html -------------> the is web2




Background monitoring management:


When the web1 server is disconnected:


When the web1 server is restored:


################################# Some tests have been completed ### ###################

Vi. Log Configuration:

######### Add the following statement #########

Vi/etc/syslog. conf
Local3. */var/log/haproxy. log
Local0. */var/log/haproxy. log

######### Modify the following statements ##########

Vi/etc/sysconfig/syslog
SYSLOGD_OPTIONS = "-r-m 0"

########### Restart a service #############

Service syslog restart
Service haproxy restart



######################################## #####################################

Brief Introduction to the configuration file:

Maxconn 5120 ### maximum number of connections
Chroot/usr/local/haproxy ### working directory
Uid 100 ### run user uid
Gid 100 ### this is the user group
Daemon ### running in the background
Quiet ### mode used (no output at startup). You can use the debug mode.
Nbproc 2 ### instance startup settings
Pidfile/usr/local/haproxy. pid ### PID



Log 127.0.0.1 local3 ### log File
Mode http ### Use http mode, and there is also a tcp mode, which is the difference between Layer 7 and Layer 4
Option httplog ### Log Type
Retries 3 ### check the number of failed server connections


Contimeout 5000 ### connection timeout
Clitimeout 50000 ### client connection timeout
Srvtimeout 50000 ### server connection timeout

Balance roundrobin ### Algorithm
Option httpchk GET/index.html ### check page

##################### Source server ############## #######
Server web1 192.168.1.ight: 80 check inter 5000 fall 1 rise 2 weight 1
Server web2 192.168.1.252: 80 check inter 5000 fall 1 rise 2 weight 1

######################## Monitoring page ############## ############
Listen status 192.168.1.250: 8080
Stats enable
Stats uri/admin
Stats auth admin: admin
Stats realm Haproxy \ statistic

This article from the "game technology blog" blog, please be sure to keep this source http://youzao.blog.51cto.com/3946111/752211


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.