[root@localhost ~]# yum install -y gcc autoconf automake Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Package gcc-4.8.5-36.el7.x86_64 already installed and latest version Package autoconf-2.69-11.el7.noarch already installed and latest version Package automake-1.13.4-3.el7.noarch already installed and latest version Nothing to do
server web1 192.168.1.10:80 weight 1 check inter 2000 rise 2 fall 3 #web1均衡(应添加内容) server web2 192.168.1.11:80 weight 1 check inter 2000 rise 2 fall 3 #web2均衡(应添加内容) backend kvm server kvm1 127.0.0.1:8000
角色名称 ip信息 haproxy server eth0:172.51.96.233/24 && eth1:192.168.0.233/24 static server eth1:192.168.0.247/24 php server eth1:192.168.0.235/24 tomcat server eth1:192.168.0.238/24
#--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global log 127.0.0.1 local3 maxconn 204800 chroot /usr/local/haproxy user haproxy group haproxy daemon nbproc 1 pidfile /var/run/haproxy.pid stats socket /usr/local/haproxy/stats description haproxy server #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults log global mode http maxconn 10000 option httplog option httpclose option dontlognull option forwardfor except 127.0.0.0/8 retries 3 option redispatch option abortonclose balance roundrobin timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s #--------------------------------------------------------------------- # use listen setting the haproxy status for site #--------------------------------------------------------------------- listen admin_status #设置haproxy监控状态 bind *:3030 mode http log 127.0.0.1 local3 err stats refresh 5s stats uri /status #监控状态页面访问url stats realm www.skeryp.com stats auth admin:admin stats hide-version stats admin if TRUE #--------------------------------------------------------------------- # main listen which proxys to the backends #--------------------------------------------------------------------- listen www bind *:80 maxconn 5000 mode http log global option httplog option httpclose option forwardfor log global default_backend default #设置默认访问页面 #定义当请求的内容是静态内容时,将请求转交给static server的acl规则 acl url_static path_beg -i /static /images /img /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js .html acl host_static hdr_beg(host) -i img. video. download. ftp. imags. videos. #定义当请求的内容是php内容时,将请求转交给php server的acl规则 acl url_php path_end -i .php #定义当请求的内容是.jsp或.do内容时,将请求转交给tomcat server的acl规则 acl url_jsp path_end -i .jsp .do #引用acl匹配规则 use_backend static_pool if url_static or host_static use_backend php_pool if url_php use_backend tomcat_pool if url_jsp #定义后端backend server backend static_pool option httpchk GET /index.html server static1 192.168.0.247:80 cookie id1 check inter 2000 rise 2 fall 3 backend php_pool option httpchk GET /info.php server php1 192.168.0.235:80 cookie id1 check inter 2000 rise 2 fall 3 backend tomcat_pool option httpchk GET /index.jsp server tomcat1 192.168.0.238:8086 cookie id2 check inter 2000 rise 2 fall 3
#<----------------------default site for listen and frontend------------------------------------> backend default mode http option httpchk GET /index.html server default 192.168.0.127:80 cookie id1 check inter 2000 rise 2 fall 3 maxconn 5000