CentOS 6.5 Installation Haproxy

Source: Internet
Author: User
Tags haproxy rsyslog



1, installation 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  log 127.0.0.1   local0  maxconn 4096  chroot  /usr/local/haproxy  uid 0  gid 0daemon  nbproc 1   pidfile /usr/local/haproxy/haproxy.pid   #debugulimit-n 65535defaults     log global    mode http    retries 3     option httplog    option httpclose     option dontlognull    option forwardfor    option  abortonclose    log 127.0.0.1 local3     #balance   roundrobin    maxconn 2048   timeout connect 5000    timeout client 50000   timeout server 50000listen admin_ Stats       bind   *:8000       stats refresh 30s        stats uri /status       stats  realm Haproxy Manager       stats auth   Admin:admintest       stats hide-versionfrontend  wwwbind   *:80acl  web_fp   path_beg -i  /use_backend    www_site   if    web_fpfrontend   web_managebind   *:8080acl  web_mgr  path_beg -i  /web_manageuse_backend    mgr_site   if    web_mgrbackend  www_site#mode http# fullconn 4000option  httpchk get  /about.jspstats refresh   2balance roundrobincookie  serverid  insert indirectserver web_fp1  192.168.0.2:10000    cookie 1a check inter 2000 rise 2 fall 3  weight  50server web_fp2  192.168.0.2:11000   cookie 2a check inter  2000 rise 2 fall 3  weight 50backend  mgr_site server  Web_mgr  192.168.0.2:9000   check inter 2000 rise 2 fall  2




3. Edit Haproxy Service Script

#vi/etc/init.d/haproxy

#!/bin/sh#chkconfig: 35 86 86#description: haproxy is a tcp/http  Reverse proxy. #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  ]] | |  exit 5    [[ -f  $CFGFILE  ]] | |  exit 6                                                          $BINFILE  -c -q -f  $CFGFILE     [[ $? -ne  0 ]] && echo  "The haproxy&nbSp;configure has error. "  && return 1                                                         echo -n  "Starting haproxy ..."     $ binfile -f  $CFGFILE  -p  $PIDFILE                                                          RETVAL=$?    echo     [[  $RETVAL  -eq 0 ]] && touch  $LOCKFILE                                                         return  $RETVAL}                                                  stop ()  {    echo  -n  "Shutting down haproxy ..."                                                          while true    do         killall   $BINFILE         [[ -z  ' Ps aux  | grep sbin/haproxy | grep -v grep '  ]] && break     done                                                         RETVAL=$?    echo    [[  $RETVAL  -eq 0 ]] && rm -f  $LOCKFILE   $PIDFILE                                                          return  $RETVAL}                                                  restart ()  {    stop    sleep 1     start}                                                 reload ()   {    [[ -z  ' Ps aux | grep sbin/haproxy | grep  -v grep '  ]] && echo  "the haproxy is not running."  && return 1    echo -n $ "Reloading HAProxy ..."                                                         if  [[ -f  $PIDFILE  ]]; then         $BINFILE  -f  $CFGFILE  -st  ' cat  $PIDFILE '     else          $BINFILE  -f  $CFGFILE  -st  ' ps aux | grep sbin/ haproxy | grep -v grep | awk  ' {print $2} '     fi                                                         RETVAL=$?    echo                                                         return  $RETVAL}                                                  case  "$"  instart)      start    ;;                                                     stop)      stop    ;;                                                     restart)      restart    ;;                                              &nBsp;      reload)     reload    ;;                                                     condrestart)      [[ -e  $LOCKFILE  ]] && restart | |  :    ;;                                                     check)       $BINFILE  -c -q -V -f  $CFGFILE     ;;                                                     *)     echo  "Usage: service haproxy  {start|stop|restart|reload|condrestart|check} "    RETVAL=1esac                                                  exit  $RETVAL



4. Edit the System log configuration


# vim/etc/rsyslog.conf

By default, the following settings will read the configuration files in the/etc/rsyslog.d/*.conf directory

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


5. Create a separate configuration file for Haproxy


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

$ModLoad IMUDP

$UDPServerRun 514

local3.*/var/log/haproxy.log

A message file is also written #如果不加下面的的配置则除了在/var/log/haproxy.log in the log



6. Configure the Rsyslog Master profile to open the remote log


# Vim/etc/sysconfig/rsyslog

Syslogd_options= "-C 2-r-M 0"

#-c 2 using compatibility mode, default is-C 5

#-r turning on remote logging

#-m 0 marks the timestamp. The unit is the minute, which is 0 o'clock, which means disabling the feature


7. Restart Haproxy and Rsyslog services



#/etc/init.d/rsyslog restart

#/etc/init.d/haproxy restart


8. View Haproxy Status

#/etc/init.d/haproxy status


Haproxy installation is complete.





This article is from the "Work Diary" blog, make sure to keep this source http://3920625.blog.51cto.com/3910625/1691924

CentOS 6.5 Installation Haproxy

Related Article

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.