haproxy 安装和配置
<pre name="code" class="sql"><pre name="code" class="sql">yum -y installgcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses* libmcrypt*# tar zcvf haproxy-1.3.20.tar.gz
# cd haproxy-1.3.20
# make TARGET=linux26 PREFIX=/usr/local/haproxy #将haproxy安装到/usr/local/haproxy
# make install PREFIX=/usr/local/haproxy
jrhppt01:/root# ps -ef | grep haproxy
root 11889 118710 10:33 pts/0 00:00:00 grep haproxy
haproxy31872 10 Apr16 ? 02:09:08 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid
启动程序:
haproxy:/usr/local/haproxy/sbin# ls
haproxyhaproxy-systemd-wrapper
配置文件路径:
/etc/haproxy
配置内容:
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1local3
maxconn 65535
chroot /usr/local/haproxy
uid 401
gid 401
daemon
defaults
logglobal
modehttp
optionhttplog
optiondontlognull
retries3
optionredispatch
optionabortonclose
optionhttpclose
optionforwardfor
maxconn 65535
timeout connect 5000
timeout client50000
timeout server 50000
timeout check 5s
stats refresh 30s
stats uri /stats
stats realm baison-test-Haproxy
stats auth admin:zjadmin818
stats hide-version
frontendwww
bind *:80
bind *:443 ssl crt /etc/haproxy/cert.pem
redirect scheme https if !{ ssl_fc }
acl host_zjcap.cnhdr_beg(host)-i zjcap.cn
redirect prefix http://www.zjcap.cn if host_zjcap.cn
####flow
acl web_req path_beg -i /web
use_backend appserver_8081 if web_req
####flow
acl business_req path_beg -i /business
use_backend appserver_8081 if business_req
acl validcode_req path_beg -i /validcode
use_backend appserver_8081 if validcode_req
####api
acl api_req path_beg -i /api
use_backend appserver_8082 if api_req
###web nginx
acl mgr_req path_beg -i /backoffice
use_backend mgrserver_8001 if mgr_req
###pay
acl pay_req path_beg -i /pay
use_backend appserver_8083 if pay_req
acl llmock_req path_beg -i /llmock
use_backend appserver_8083 if llmock_req
###web
acl url_static path_end .html .gif .png .jpg .css .js
use_backend webserver_8001 if url_static
default_backend webserver_8001
###frond end
backendwebserver_8001
mode http
balanceroundrobin
serverwebhost01_800110.252.105.157:8001 check inter 2000 fall 3
serverwebhost02_800110.168.29.17:8001 check inter 2000 fall 3
####backoffice
backendmgrserver_8001
mode http
servermgrhost_800110.168.34.94:8001 check inter 2000 fall 3
######flow
backend appserver_8081
mode http
balance roundrobin
serverapphost01_8081 10.168.32.82:8081check inter 2000 fall 3
serverapphost02_8081 10.168.33.193:8081check inter 2000 fall 3
######api
backend appserver_8082
mode http
balance roundrobin
serverapphost11_8082 10.171.243.55:8082check inter 2000 fall 3
serverapphost12_8082 10.252.148.164:8082check inter 2000 fall 3
#######pay
backend appserver_8083
mode http
balance roundrobin
serverapphost21_8083 10.171.240.139:8083check inter 2000 fall 3
serverapphost22_8083 10.252.163.244:8083check inter 2000 fall 3
listen stats 0.0.0.0:8899
mode http
option httpclose
balance roundrobin
stats uri /admin-status
stats realm Haproxy\ Statistics
stats auth admin:admin-check
简单测试:
acl api_req path_beg -i /api
use_backend appserver_8082 if api_req
acl url_static path_end .html .gif .png .jpg .css .js
use_backend webserver_8001 if url_static
default_backend webserver_8001
backend appserver_8082
mode http
balance roundrobin
serverapphost11_8082 10.171.243.55:8082check inter 2000 fall 3
serverapphost12_8082 10.252.148.164:8082check inter 2000 fall 3
backendwebserver_8001
mode http
balanceroundrobin
serverwebhost01_800110.252.105.157:8001 check inter 2000 fall 3
serverwebhost02_800110.168.29.17:8001 check inter 2000 fall 3
haproxy:
192.168.32.173 http://192.168.32.173/api --可以访问
http://192.168.32.173/ --跳到静态页
页:
[1]