Install haproxy in CentOS 6.5

Source: Internet
Author: User
Tags haproxy rsyslog

Install haproxy in CentOS 6.5

1. Install haproxy

# Tar xzvf haproxy-1.5.9.tar.gz

# Cd haproxy-1.5.9

# Make TARGET = linux26 PREFIX =/usr/local/haproxy

# Make install PREFIX =/usr/local/haproxy

# Mkdir/usr/local/haproxy/etc

# Mkdir-p/data/logs/haproxy

2. Edit the haproxy configuration file

# Vi/usr/local/haproxy/etc/haproxy. conf

global log127.0.0.1local0 maxconn4096 chroot/usr/local/haproxy uid0 gid0 daemon nbproc1 pidfile/usr/local/haproxy/haproxy.pid #debug ulimit-n65535 defaults logglobal modehttp retries3 optionhttplog optionhttpclose optiondontlognull optionforwardfor optionabortonclose log127.0.0.1local3 #balanceroundrobin maxconn2048 timeoutconnect5000 timeoutclient50000 timeoutserver50000 listenadmin_stats bind*:8000 statsrefresh30s statsuri/status statsrealmHaproxyManager statsauthadmin:admintest statshide-version frontendwww bind*:80 aclweb_fppath_beg-i/ use_backend www_site ifweb_fp frontendweb_manage bind*:8080 aclweb_mgrpath_beg-i/web_manage use_backendmgr_siteifweb_mgr backend www_site #modehttp #fullconn4000 optionhttpchkGET/about.jsp statsrefresh2 balanceroundrobin cookieSERVERIDinsertindirect serverweb_fp1192.168.0.2:10000cookie1acheckinter2000rise2fall3weight50 serverweb_fp2192.168.0.2:11000cookie2acheckinter2000rise2fall3weight50 backendmgr_site serverweb_mgr192.168.0.2:9000checkinter2000rise2fall2

3. Edit the haproxy service script

# Vi/etc/init. d/haproxy

#!/bin/sh #chkconfig:358686 #description:HAProxyisaTCP/HTTPreverseproxy. #processname:haproxy #config:/usr/local/haproxy/etc/haproxy.conf #pidfile:/usr/local/haproxy/haproxy.pid # PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin BINFILE="/usr/local/haproxy/sbin/haproxy" CFGFILE="/usr/local/haproxy/etc/haproxy.conf" PIDFILE="/usr/local/haproxy/haproxy.pid" LOCKFILE="/usr/local/haproxy/haproxy.lock" RETVAL=0 start(){ [[-x$BINFILE]]||exit5 [[-f$CFGFILE]]||exit6 $BINFILE-c-q-f$CFGFILE [[$?-ne0]]&&echo"TheHAProxyconfigurehaserror."&&return1 echo-n"StartingHAProxy......" $BINFILE-f$CFGFILE-p$PIDFILE RETVAL=$? echo [[$RETVAL-eq0]]&&touch$LOCKFILE return$RETVAL } stop(){ echo-n"ShuttingdownHAProxy......" whiletrue do killall$BINFILE [[-z`psaux|grepsbin/haproxy|grep-vgrep`]]&&break done RETVAL=$? echo [[$RETVAL-eq0]]&&rm-f$LOCKFILE$PIDFILE return$RETVAL } restart(){ stop sleep1 start } reload(){ [[-z`psaux|grepsbin/haproxy|grep-vgrep`]]&&echo"TheHAProxyisnotrunning."&&return1 echo-n$"ReloadingHAProxy......" if[[-f$PIDFILE]];then $BINFILE-f$CFGFILE-st`cat$PIDFILE` else $BINFILE-f$CFGFILE-st`psaux|grepsbin/haproxy|grep-vgrep|awk'{print$2}'` fi RETVAL=$? echo return$RETVAL } case"$1"in start) start ;; stop) stop ;; restart) restart ;; reload) reload ;; condrestart) [[-e$LOCKFILE]]&&restart||: ;; check) $BINFILE-c-q-V-f$CFGFILE ;; *) echo"Usage:servicehaproxy{start|stop|restart|reload|condrestart|check}" RETVAL=1 esac exit$RETVAL


4. Edit System Log Configuration

# Vim/etc/rsyslog. conf

By default, the configuration file in the/etc/rsyslog. d/*. conf directory is read.

$ IncludeConfig/etc/rsyslog. d/*. conf

5. Create an independent configuration file for haproxy

# Vim/etc/rsyslog. d/haproxy. conf

$ ModLoad imudp

$ UDPServerRun 514

Local3. */var/log/haproxy. log

# If the following configuration is not added, the message file will be written in addition to/var/log/haproxy. log.

6. Configure the main configuration file of rsyslog and enable remote logs.

# Vim/etc/sysconfig/rsyslog

SYSLOGD_OPTIONS = "-c 2-r-m 0"

#-C 2 uses the compatibility mode. The default value is-c 5.

#-R enable remote logs

#-M 0 indicates the timestamp. The Unit is minute. If it is 0, this function is disabled.

7. Restart the haproxy and rsyslog services.

#/Etc/init. d/rsyslog restart

#/Etc/init. d/haproxy restart

8. view the haproxy status

#/Etc/init. d/haproxy status

Haproxy installation is complete.

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.