使用Haproxy搭建web叢集

來源:互聯網
上載者:User

標籤:伺服器   server   local   

環境:

代理haproxy:192.168.100.155

後台nginx:192.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

 


使用Haproxy搭建web叢集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.