环境:

代理haproxy192.168.100.155

后台nginx192.168.100.153-154

 

1.安装nginx服务器:(192.168.100.153

yum -y install pcre-devel zlib-devel

wgetftp://ftp.linuxfan.cn/tools/nginx-1.6.0.tar.gz

tar zxvf nginx-1.6.0.tar.gz -C /usr/src/

cd /usr/src/nginx-1.6.0

useradd -M -s /sbin/nologin nginx

./configure --prefix=/usr/local/nginx--user=nginx --group=nginx &&make &&make install

cd /usr/local/nginx/html/

echo "server 192.168.100.153"  > test.html

/usr/local/nginx/sbin/nginx   ##启动服务

 

2.安装nginx服务器:(192.168.100.154

yum -y install pcre-devel zlib-devel

wgetftp://ftp.linuxfan.cn/tools/nginx-1.6.0.tar.gz

tar zxvf nginx-1.6.0.tar.gz -C /usr/src/

useradd -M -s /sbin/nologin nginx

cd /usr/src/nginx-1.6.0

./configure --prefix=/usr/local/nginx --user=nginx--group=nginx &&make &&make install

cd /usr/local/nginx/html/

echo "server 192.168.100.154"  > test.html

/usr/local/nginx/sbin/nginx   ##启动服务

 

3.安装及配置haproxy

yum -y install pcre-devel bzip2-devel

wget ftp://ftp.linuxfan.cn/tools/haproxy-1.4.24.tar.gz

tar zxvf haproxy-1.4.24.tar.gz -C /usr/src/

cd /usr/src/haproxy-1.4.24/

make TARGET=linux26

make install

mkdir /etc/haproxy

cd examples/

cp haproxy.cfg /etc/haproxy/

vi /etc/haproxy/haproxy.cfg  ##修改配置文件如下

global

         log127.0.0.1   local0 info

         log127.0.0.1   local1 notice

         maxconn4096

         uid99

         gid99

         daemon

defaults

         log    global

         mode        http

         option       httplog

         option       dontlognull

         retries      3

         maxconn  2000

         contimeout      5000

         clitimeout         50000

         srvtimeout       50000

listen        webcluster0.0.0.0:80

         option       httpchk GET /index.html

         balance    roundrobin

         server       inst1 192.168.100.153:80 check inter 2000fall 3

         server       inst2 192.168.100.154:80 check inter 2000fall 3

:wq

cp/usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy

chmod +x /etc/init.d/haproxy

ln -s /usr/local/sbin/haproxy /usr/sbin/

/etc/init.d/haproxy restart

4.日志管理:

vi /etc/rsyslog.conf

去掉注释

$ModLoad imudp
$UDPServerRun 514

添加

local0.*    /var/log/haproxy/ha-info.log

local1.*    /var/log/haproxy/ha-notice.log

:wq

 

vi /etc/sysconfig/rsyslog

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

:wq

/etc/init.d/rsyslog  restart

/etc/init.d/haproxy  restart

访问测试。

tail -f /var/log/haproxy/ha-info.log