I system RedHat6.4, haproxy version is haproxy-1.3.15.10.tar.gz
Installation
installation PCRE
– [Email protected]~]# yum-y Install pcre pcre-devel
Unzip and enter the Haproxy directory
– [Email protected]~]# tar xvzf haproxy-1.4.24.tar.gz
– [[Email protected]~]# CD haproxy-1.4.24
View kernel version number
– [[Email protected]~]# uname-r
Installation
– [[email protected]~]# make target=linux2628 \
> use_pcre=1 prefix=/usr/local/haproxy Install ( use_pcre=1 enable regular)
2.
Establish Symbolic links for Haproxy
Ln-s/usr/local/haproxy/sbin/haproxy \
/usr/local/sbin/
Copy the sample configuration file from the installation source directory to the Haproxy installation directory
– [[Email protected]~]# mkdir/usr/local/haproxy/conf
– [email protected]~]# cp examples/haproxy.cfg \
>/usr/local/haproxy/conf/haproxy.cfg
3. Configuration Files
(1) Description
HAProxy configuration parameter source
– command line. Always has the highest priority
– Global section. Setting process-level parameters globally
– The proxy Declarations section. From default,listen,frontend, and backend
The configuration file can be composed of the following parts:
– Default
Set default parameters for other parts of the follow -up
Default parameters can be reset by subsequent parts
– frontend
describes the receive client listening socket (socket) Set
– Backend
A server set that describes forwarding links
– Listen
A complete statement that binds frontend and backend together
(2) Example
Globals// Global Settings
Log 127.0.0.1 local0// logging Output configuration
Maxconn 4096// maximum number of connections concurrent links
Chroot/usr/local/haproxy
UID// user uid of the owning run
GID// the user group that belongs to run
Daemon// running daemons in the background
Nbproc 2// start 2 haproxy instances and the number of CPUs
creation of the Pidfile/usr/local/haproxy/run/haproxy.pid run
Defaults// default settings
Log Global
Mode HTTP// default in HTTP mode 3 kinds :http TCP Health
Option Httplog// log category
Retries 3//3 Connection failed to consider server unavailable
option redispatch// when the serverid corresponding server is hung out ,
force directed to other health servers
Stats uri/haproxy-admin// set up monitoring and control directory just name it.
Contimeout//Connection time- out
Clitimeout 50000// Client connection time-out
Srvtimeout 50000// server-side connection time-out
Listen Websrv-rewrite 0.0.0.0:80//Listening address, can write Haproxy address, can also be written as 0.0.0.0, listen to all local addresses
Cookie ServerID Rewrite
Balance Roundrobin Load Balancing Method
Server App1_1 192.168.20.101:80cookie app1inst1 check Inter rise 2 Fall 5 weight 1 (realserver) Heartbeat Detection frequency:5 microseconds detection failure proof he's dead.
Server App1_2 192.168.20.102:80cookie app1inst2 check Inter rise 2 Fall 5 weight 1
Web server real IP address, and configure a good Web service
4. Control Server Status
start the service
– [Email protected]~]# haproxy-f \
>/usr/local/haproxy/conf/haproxy.cfg
Stop service
– [Email protected]~]# killall Haproxy
Restart service
– [email protected]~]# haproxy-f haproxy.cfg \
>-st ' pidof haproxy ' get pid restart
5. Monitor HAProxy status
Http://192.168.194.10/haproxy-admin
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/43/CE/wKioL1Pc7V7Dh47RAATuf8ZRFAw841.jpg "title=" 6pfyhtt0]vun2bz$6d1z3%k.jpg "alt=" Wkiol1pc7v7dh47raatuf8zrfaw841.jpg "/>
This article is from "Linux rookie" blog, please be sure to keep this source http://ludihua.blog.51cto.com/4601284/1534290