1. Server
192.168.9.34 Haproxy--->haproxy
192.168.9.35 Service1--->nginx
192.168.9.36 Service2--->nginx+tomcat
2. Haproxy load Balancing on the Web
#---------------------------------------------------------------------# Example configuration for a possible web Application. See the# full configuration options online.## http://haproxy.1wt.eu/download/1.4/doc/configuration.txt##------------ ---------------------------------------------------------#----------------------------------------------------- ----------------# Global settings#---------------------------------------------------------------------Global # to Has these messages end up In/var/log/haproxy.log you'll # need to: # # 1) Configure Syslog to accept Network Log events. This is do # by adding the '-r ' option to the syslogd_options in #/etc/sysconfig/syslog # 2) config Ure local2 events to go to The/var/log/haproxy.log # file. A line like the following can is added to #/etc/sysconfig/syslog # # local2.*/var/lo G/haproxy.log # log 127.0.0.1 local2 Chroot/var/lib/haproxy Pidfile/var/run/haproxy.pid maxconn 4000 User haproxy Group Haproxy daemon # turn On stats UNIX socket stats socket/var/lib/haproxy/stats#----------------------------------------------------------- ----------# Common defaults that all the ' listen ' and ' backend ' sections will# with if not designated in their block#------ ---------------------------------------------------------------Defaults mode HTTP log Global option httplog option dontlognull option Http-server-close o ption forwardfor except 127.0.0.0/8 option Redispatch retries 3 Timeout HT Tp-request 10s Timeout Queue 1m timeout Connect 10s timeout client 1m timeout SE RVer 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000#----------- ----------------------------------------------------------# Listen page#------------------------------------------------------------------ ---Listen stats mode http bind 0.0.0.0:1080 stats enable stats hide-version stats Uri/listen-page s Tats Realm Welcome login\ listen-page Stats Auth admin:000000 stats admin if true#----------------------------- ----------------------------------------# main frontend which proxys to the backends#-------------------------------- -------------------------------------frontend main *:80 #haproxy的监听端口 ACL url_static path_b Eg-i/static/images/javascript/stylesheets ACL url_static path_end-i. jpg. gif. png. css. js Use_backend static if url_static default_backend app#--------------------------------------------- ------------------------# Static backend for serving up images, stylesheets and such#---------------------------------- -----------------------------------Backend Static balance roundrobin option Httpchk get/index.html server Static1 192.168.9.35:80 Check Port I Nter 5s rise 2 fall 3#---------------------------------------------------------------------# round robin balancing Between the various backends#---------------------------------------------------------------------backend app Balance Roundrobin server App1 192.168.9.35 Check Port Inter 5s rise 2 Fall 3 server APP2 192.168.9 . Check port Inter 5s rise 2 Fall 3
3. Back-end health checks and load balancing for other applications
3.1 Excerpts
3.2 Excerpts
3.3 Excerpts
Haproxy Service with high availability