#!/bin/bash
cd /usr/local/src/
wget
tar zxf haproxy-1.4.8.tar.gz
cd haproxy-1.4.8
uname -a
make TARGET=linux26PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
cat >> /usr/local/haproxy/haproxy.cfg <
global
log 127.0.0.1 local0 ###全局日志
maxconn 4096 ###最大连接数
chroot /usr/local/haproxy
uid 501 ###用户ID
gid 501 ###组ID
daemon ###后台运行
nbproc 1 ###创建进程数
pidfile /usr/local/haproxy/haproxy.pid ###pid文件
defaults
log 127.0.0.1 local3
mode http ###支持的模式
option httplog ###日志格式
option httpclose ###请求完成后关闭http通道
option dontlognull
option forwardfor ###apache日志转发
option redispatch
retries 2 ###重连次数
maxconn 2000
balance roundrobin ###算法类型
stats uri /haproxy-stats ###状态统计页面
#stats auth admin:admin ###状态统计页面用户名密码,可选
contimeout 5000 ###连接超时
clitimeout 50000 ###客户端超时
srvtimeout 50000 ###服务器超时
listen proxy *:80 ###访问地址及端口
option httpchk HEAD /index.html HTTP/1.0 ###健康检查页面
server web2 10.10.18.10:88 cookie app1inst2 check inter 2000 rise 2 fall 5
server web2 10.10.18.11:88 cookie app1inst2 check inter 2000 rise 2 fall 5
server web2 10.10.18.12:88 cookie app1inst2 check inter 2000 rise 2 fall 5
server web2 10.10.18.13:88 cookie app1inst2 check inter 2000 rise 2 fall 5
server web2 10.10.18.14:88 cookie app1inst2 check inter 2000 rise 2 fall 5
server web2 10.10.18.15:88 cookie app1inst2 check inter 2000 rise 2 fall 5
EOF
cat >> /etc/init.d/haproxy <
#! /bin/sh
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
PROGDIR=/usr/local/haproxy
PROGNAME=haproxy
DAEMON=\$PROGDIR/sbin/\$PROGNAME
CONFIG=\$PROGDIR/\$PROGNAME.cfg
PIDFILE=\$PROGDIR/\$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 /usr/local/haproxy/haproxy.pid
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
EOF
chmod +x /etc/rc.d/init.d/haproxy
chkconfig --add haproxy
chmod 777 /usr/local/haproxy/haproxy.pid
sed -i '/SYSLOGD_OPTIONS/c\SYSLOGD_OPTIONS="-r -m 0"' /etc/sysconfig/syslog
echo "local3.* /var/log/haproxy.log" /etc/syslog.conf
echo "local0.* /var/log/haproxy.log" /etc/syslog.conf
service syslog restart
#启动haproxy
# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
#重启haproxy
# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg -st `cat /usr/local/haproxy/haproxy.pid`
#停止haproxy
# killall haproxy
# service haproxy start restart stop
echo "haproxy setup ok"
#######################
#/haproxy-stats
#admin:admin
#查看运行状态
#######################
阅读(758) | 评论(0) | 转发(0) |