标签:haproxy配置
注:mode一般写在backend段,也可以写在defaults,forntend段
注:maxconn写在defaluts或forntend段表示前端的最大连接,写在backend表示后端server的最大连接
global
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option http-server-close
option http-pretend-keepalive
option forwardfor except 127.0.0.0/8
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 655350
listen stats
bind *:1080
stats enable
stats hide-version
stats realm haproxy\ stats
stats auth test:test
stats admin if TRUE
stats uri /jiankong
frontend mysql
bind 192.168.10.80:3306
default_backend mysql_server
#自定义日志格式
capture request header Host len 64
capture request header User-Agent len 128
capture request header X-Forwarded-For len 100
capture request header Referer len 200
capture response header Server len 40
capture response header Server-ID len 40
log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %r\ %b\ %f\ %bi\ %hrl\ %hsl\
frontend tupian
bind 192.168.10.85:80
default_backend tupian
frontend web
bind 192.168.10.86:80
use_backend tomcat_web
log 127.0.0.1 local2
#自定义日志格式
capture request header Host len 64
capture request header User-Agent len 128
capture request header X-Forwarded-For len 100
capture request header Referer len 200
capture response header Server len 40
capture response header Server-ID len 40
log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %r\ %b\ %f\ %bi\ %hrl\ %hsl\
frontend erp
bind 192.168.10.87:80
use_backend tomcat_erp
log 127.0.0.1 local3
frontend interface
bind 192.168.10.88:80
use_backend tomcat_interface
log 127.0.0.1 local4
frontend wap
bind 192.168.10.89:80
use_backend tomcat_wap
log 127.0.0.1 local5
backend tupian
mode http
balance static-rr
server tp01 192.168.10.2:80 check
server tp01 192.168.10.3:80 check
...
backend mysql_server
mode tcp
fullconn 500
balance leastconn
server mysql01 192.168.10.4:3306 check
server mysql02 192.168.10.5:3306 check
server mysql03 192.168.10.6:3306 check
...
backend tomcat_web
mode http
fullconn 3000
balance source
server web1 192.168.10.7:8080 check
server web2 192.168.10.8:8080 check
server web3 192.168.10.9:8080 check
server web4 192.168.10.10:8080 check
...
backend tomcat_erp
mode http
fullconn 3000
balance source
servererp1 192.168.10.11:8080 check
servererp2 192.168.10.12:8080 check
...
backend tomcat_interface
mode http
fullconn 3000
balance source
serverinterface1 192.168.10.13:8080 check
serverinterface2 192.168.10.14:8080 check
serverinterface3 192.168.10.15:8080 check
serverinterface4 192.168.10.16:8080 check
...
backend tomcat_mobile
mode http
fullconn 3000
balancesource
servermobile1 192.168.10.17:8080 check
servermobile2 192.168.10.18:8080 check
servermobile3 192.168.10.19:8080 check
servermobile4 192.168.10.20:8080 check
...
注:forentend有两种写法
第一种写法:定义多个frontend,基于虚拟IP进行绑定frontend,即访问不同的IP分发到不同的backend,此种写法的缺点是当需要做acl,自定义日志格式时,需要在每个frontend中都写一遍;优点是每个forntend的日志可以写到单独的文件中
第二种写法:定义1个frontend,基于acl定义规则,根据请求的域名来分发到不同的backend,此种写法的优点是当需要定义acl或者自定义日志格式时,只需要在frontend中写一遍即可;缺点是访问所有backend的日志都只能写到一个文件中,在分析日志时会给造成麻烦
以上两种写法,可以根据需求进行选择!!!
本文出自 “激情燃烧的岁月” 博客,请务必保留此出处http://liuzhengwei521.blog.51cto.com/4855442/1927999
标签:haproxy配置
原文地址:http://liuzhengwei521.blog.51cto.com/4855442/1927999