标签:配置文件 server linux local 下载安装
web_proxy server 192.168.20.112
web1 server 192.168.20.137
web2 server 192.168.20.140
echo "192.168.20.137 > /usr/local/nginx/html/index.html
echo "192.168.20.140 > /usr/local/nginx/html/index.html
下载安装haproxy
tar -zxvf haproxy-1.4.24.tar.gz
cd haproxy-1.4.24
uname -r #查看下linux内核
make TARGET=linux2632 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
2.创建chroot所需目录
mkdir /var/haproxy
3.创建haproxy主配置文件
global
log 127.0.0.1 local3
chroot /var/haproxy
pidfile /var/haproxy/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
nbproc 1
stats socket /var/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
stats uri /admin?stats
#stats hide-version(隐藏版本号)
timeout check 10s
#balance source
maxconn 3000
listen web_proxy 192.168.20.112:8000
server web1 192.168.20.137:8000 cookie app1inst1 check inter 2000 rise 2 fall 5
server web2 192.168.20.140:8000 cookie app1inst2 check inter 2000 rise 2 fall 5
listen admin_status
bind *:8000
mode http
stats enable
stats uri /admin?status
stats auth yzg:yzg1314520
stats refresh 5
stats hide-version
因为haproxy本来就有主配置文件在/etc/haproxy/haproxy.cfg,所以我们要把自己弄的主配置文件替换掉原本haproxy自己本身的主配置文件,
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
cp /etc/haproxy.cfg /etc/haproxy/haproxy.cfg
然后重启haproxy服务
service haproxy restart
4.创建haproxy用户和组
useradd -s /sbin/nologin haproxy
5.修改日志配置文件
vim /etc/rsyslog.conf # 最下面添加这三行
$ModLoad imudp
$UDPServerRun 514
local3.* /var/log/haproxy.log
6.重启rsyslog
service rsyslog restart
7.启动haproxy服务
haproxy -f /etc/haproxy.cfg
echo”/usr/local/sbin/haproxy -f /etc/haproxy.cfg start " >> etc/rc.d/rc.local
8.在浏览器输入http://192.168.20.137 和http://192.168.20.140 来确认网址是否能正确访问
9.浏览器输入web_proxy server端的ip看是否轮询 web1 2.
10.用web_proxy 192.168.20.112:8000/admin?stats 去访问浏览器看是否打开图形界面
本文出自 “回不去的时光” 博客,请务必保留此出处http://yzg784534398.blog.51cto.com/9719002/1672029
标签:配置文件 server linux local 下载安装
原文地址:http://yzg784534398.blog.51cto.com/9719002/1672029