直接yum安装

yum -y install haproxy

或者编译安装, 版本高些

wget http://www.haproxy.org/download/1.8/src/haproxy-1.8.12.tar.gz
tar zxvf haproxy-1.8.12.tar.gz
cd haproxy-1.8.12
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy

配置文件

 vim /etc/haproxy/haproxy.cfg
global
	  daemon
	  
defaults
    log global
    mode    tcp
    option  dontlognull
    timeout connect 1000
    timeout client 150000
    timeout server 150000
    maxconn     60000
    retries     3

listen smtp
    bind 127.0.0.1:465
    mode tcp
    log  global
    server s1 smtp.gmail.com:465

listen pop
    bind 127.0.0.1:995
    mode tcp
    log global
    server s2 pop.gmail.com:995

listen imap
    bind 127.0.0.1:993
    mode tcp
    log global
    server s3 imap.gmail.com:993

注册成服务

# haproxy文件
#! /bin/sh
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROGDIR=/root
PROGNAME=haproxy
DAEMON=/usr/sbin/haproxy
CONFIG=/etc/haproxy/haproxy.cfg
PIDFILE=/tmp/$PROGNAME.pid
DESC="HAProxy daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

start()
{
       echo -n "Starting $DESC: $PROGNAME"
       $DAEMON -f $CONFIG
       echo "."
}

stop()
{
       echo -n "Stopping $DESC: $PROGNAME"
       haproxy_pid=cat $PIDFILE
       kill $haproxy_pid
       echo "."
}

restart()
{
       echo -n "Restarting $DESC: $PROGNAME"
       $DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE)
       echo "."
}

case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 restart)
       restart
       ;;
 *)
       echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
       exit 1
       ;;
esac

exit 0

权限

chmod 775 /etc/init.d/haproxy

启动

service haproxy start