一、環境:
操做系統:CentOS 6.4
haproxy: 1.3.15.10 [下載:http://download.chinaunix.net/download.php?id=25784&ResourceID=12508]
服務器IP: 10.5.24.51php
修改HOST,添加以下配置
10.5.24.51 w1.rhythmk.com
10.5.24.51 w2.rhythmk.com linux
二、安裝web
tar -zxvf haproxy-1.3.15.10.tar.gz mv haproxy-1.3.15.10 haproxy cd haproxy make TARGET=linux26 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy
默認安裝後,/usr/local/haproxy/conf 路徑是沒有haproxy.cfg配置 ,添加配置文件以下:redis
global maxconn 51200 chroot /usr/local/haproxy uid 99 gid 99 daemon #quiet nbproc 1 pidfile /usr/local/haproxy/logs/haproxy.pid defaults mode http #retries 2 option redispatch option abortonclose timeout connect 5000ms timeout client 30000ms timeout server 30000ms #timeout check 2000 log 127.0.0.1 local0 err #[err warning info debug] balance roundrobin # option httplog # option httpclose # option dontlognull # option forwardfor listen admin_stats bind 0.0.0.0:8888 option httplog stats refresh 30s stats uri /stats stats realm Haproxy Manager stats auth admin:admin frontend rhythmk.com bind 0.0.0.0:80 option httpclose ## hdr_reg 採用正則匹配對應請求域名 ,進行映射 ## hdr_dom 全相等匹配域名 進行映射 acl w1.rhythmk hdr_dom(host) -i w1.rhythmk.com use_backend w1.rhythmk.com if w1.rhythmk acl w2.rhythmk hdr_reg(host) -i w2.rhythmk.com use_backend w2.rhythmk.com if w2.rhythmk ######## web1 ############## backend w1.rhythmk.com mode http balance roundrobin appsession 9ai9 len 64 timeout 5h request-learn balance roundrobin #cookie LOGONCOOKIE insert nocache #option httpchk GET /index.php # 端口 92xx 爲主幹,93xx 爲分支1(dev),94xx 爲分支2(branch2) server w1.rhythmk 127.0.0.1:6055 check inter 10000 rise 3 fall 3 weight 100 ######## web2 ############## backend w2.rhythmk.com mode http balance roundrobin appsession 9ai9 len 64 timeout 5h request-learn balance roundrobin #cookie LOGONCOOKIE insert nocache #option httpchk GET /index.php server w2.rhythmk 127.0.0.1:6056 check inter 10000 rise 3 fall 3 weight 100
添加啓動腳本 restart.sh:bash
#!/bin/bash pkill -9 haproxy dirpath=/usr/local/haproxy $dirpath/sbin/haproxy -f $dirpath/conf/haproxy.cfg
爲 restart.sh 添加執行權限。啓動haproxy服務器
三、驗證:cookie
已經配置好的站點 :session
w1站點:app
w2站點:frontend
瀏覽地址:
http://10.5.24.51:8888/stats