Haproxy实现负载均衡和动静分离

Haproxy实现负载均衡和动静分离:

前提:后端服务器及部署:

static_servers:

StaSrv1_test    192.168.88.130:80      httpd

StaSrv2_web2   192.168.88.129:80     httpd

dynamic_servers:

DycSrv_www   192.168.88.131:80       httpd

default_servers:

DftSrv1_www   192.168.88.131:8080   nginx

DftSrv2_test    192.168.88.130:8080    nginx

 

1、haproxy配置

(1)、编辑haproxy配置文件,实现动静分离:

[root@www haproxy]# vi haproxy.cfg

#---------------------------------------------------------------------

# Example configuration for a possible webapplication.  See the

# full configuration options online.

#

#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

#

#---------------------------------------------------------------------

#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

    #to have these messages end up in /var/log/haproxy.log you will

    #need to:

    #

    #1) configure syslog to accept network log events.  This is done

   #    by adding the '-r' option tothe SYSLOGD_OPTIONS in

   #    /etc/sysconfig/syslog

    #

    #2) configure local2 events to go to the /var/log/haproxy.log

   #   file. A line like thefollowing can be added to

   #   /etc/sysconfig/syslog

    #

   #    local2.*                       /var/log/haproxy.log

    #

    log        127.0.0.1 local2

   chroot      /var/lib/haproxy

   pidfile     /var/run/haproxy.pid

   maxconn     40000

   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

# use if not designated in their block

#---------------------------------------------------------------------

defaults

   mode                    http

#   mode                    tcp

   log                     global

   option                  httplog

   option                 dontlognull

   option http-server-close

   option forwardfor       except127.0.0.0/8

   option                  redispatch

   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                 30000

#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

frontend   http-in

   bind    *:90

   bind    *:9090

   rspadd  Rsp-Via:\ www.field.com

   mode    http

#   log     global

   option  httpclose

   option  logasap

   option  dontlognull

   capture request  header Host len20

   capture request  header Refererlen 60

   acl url_static       path_beg       -i /static /images /javascript/stylesheets

   acl url_static       path_end       -i .jpg .png .css .js

   acl url_dynamic      path_beg       -i /music /video /dynamicpage

   acl url_dynamic      path_end       -i .mp4 .mkv .mp3 .wma .avi

   use_backend         static_servers   if  url_static

   use_backend         dynamic_servers  if  url_dynamic

default_backend      default_servers

 

listen statistics

   bind  *:8088

   stats enable

   stats hide-version

#   stats scope .

   stats uri  /haproxyadmin?stats

   stats realm   Haproxy\ Statistics

   stats auth admin:field

   stats auth fieldyang:field

   stats admin if TRUE

   errorfile 503 /etc/haproxy/errorpages/statserror/503sorry.http

   errorfile 403 /etc/haproxy/errorpages/statserror/403forbid.http

#--------------------------------------------------------------------

# static backend for serving up images,stylesheets and such

#---------------------------------------------------------------------

backend static_servers

   balance     roundrobin

   server StaSrv1_test 192.168.88.130:80 check maxconn 6000

   server StaSrv2_web2 192.168.88.129:80 check maxconn 6000

   errorfile 503 /etc/haproxy/errorpages/503sorry.http

   errorfile 403 /etc/haproxy/errorpages/403forbid.http

 

backend dynamic_servers

   balance     roundrobin

#基于cookie绑定,SERVERID指cookie名,指定为插入方式,不允许缓存,有可能会使用间接方式访问(可不写)

   server      DycSrv_www  192.168.88.131:80 maxconn 3000 check

   errorfile 503 /etc/haproxy/errorpages/503sorry.http

errorfile 403/etc/haproxy/errorpages/403forbid.http

 

#backend mysql_servers

#   balance leastconn

#   server dbsrv1 192.168.88.131:3306 check port 3306 inter 1000 rise 1 fall2 maxconn 300

#   server dbsrv2 192.168.88.130:3306 check port 3306 inter 1000 rise 1 fall2 maxconn 300

 

#---------------------------------------------------------------------

# round robin balancing between the variousbackends

#---------------------------------------------------------------------

backend default_servers

   balance     roundrobin

   cookie      SERVER   insert  nocache  indirect

#基于cookie绑定,SERVERID指cookie名,指定为插入方式,不允许缓存,有可能会使用间接方式访问(可不写)

   server      DftSrv1_www  192.168.88.131:8080 maxconn 5000 check weight1

   server      DftSrv2_test192.168.88.130:8080 maxconn 5000 check weight 2

#   server      dynamicsev_www  192.168.88.131:8080 maxconn 1000 check weight1 cookie websev1

#   server      dynamicsev_test192.168.88.130:8080 maxconn 1000 check weight 2 cookie websev2

   errorfile 503 /etc/haproxy/errorpages/503sorry.http

   errorfile 403 /etc/haproxy/errorpages/403forbid.http

 

注意:改变端口,必须重启服务

[root@www haproxy]# service haproxy restart

停止 haproxy:[确定]

正在启动 haproxy:[确定]

[root@www haproxy]# service haproxy status

haproxy (pid  44281) 正在运行...

 

(2)、编写后端服务器测试页面

[root@test html]# mkdir static

[root@test html]# mkdir javascript

[root@test html]# mkdir stylesheets

[root@test html]# echo "<h1> Welcome to test.field.comstatic page !! </h1>" >static/index.html

[root@test html]# echo "<h1> Welcome to test.field.comjavascript page !! </h1>" >javascript/index.html

[root@test html]# echo "<h1> Welcome to test.field.comstylesheets page !! </h1>" >stylesheets/index.html

[root@test html]# ll

总用量 1080

-rwxr--r-- 1 root root 197222 4月  28 00:42 1.png

-rwxr--r-- 1 root root 153467 4月  28 00:42 2.png

-rwxr--r-- 1 root root 228588 4月  28 00:42 3.png

-rwxr--r-- 1 root root 202941 4月  28 00:42 4.png

-rwxr--r-- 1 root root 219479 4月  28 00:42 5.jpg

drwxr-xr-x. 2 root root   4096 4月  18 21:19 bbs

drwxr-xr-x 2 root root   4096 4月  18 22:22 field

drwxr-xr-x. 2 root root   4096 4月  28 23:35 images

-rw-r--r-- 1 root root     47 4月  26 18:45 index.html

-rw-r--r-- 1 root root    110 4月  26 18:44 index.html.backup

drwxr-xr-x 2 root root   4096 4月  28 00:41 javascript

drwxr-xr-x 2 root root   4096 4月  28 00:40 static

drwxr-xr-x 2 root root   4096 4月  28 00:42 stylesheets

-rw-r--r-- 1 root root     50 4月  27 15:40 test10.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test1.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test2.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test3.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test4.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test5.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test6.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test7.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test8.html

-rw-r--r-- 1 root root     49 4月  27 15:40 test9.html

[root@test html]# cd images

[root@test images]# ll

总用量 1008

-rwxrw-rw-. 1 root root 197222 11月 18 19:131.png

-rwxrw-rw-. 1 root root 153467 11月 18 19:122.png

-rwxrw-rw-. 1 root root 228588 11月 18 19:143.png

-rwxrw-rw-. 1 root root 202941 11月 18 19:144.png

-rwxrw-rw-. 1 root root 219479 11月 18 19:155.jpg

[root@test static]# cat /usr/share/nginx/html/index.html

<h1> welcome to Nginx on test.field.com ! </h1>

[root@web2 html]# mkdir static

[root@web2 html]# mkdir javascript

[root@web2 html]# mkdir stylesheets

[root@web2 html]# echo "<h1> Welcome to web2.field.comstatic page !! </h1>" >static/index.html

[root@web2 html]# echo "<h1> Welcome to web2.field.comjavascript page !! </h1>" >javascript/index.html

[root@web2 html]# echo "<h1> Welcome to web2.field.comstylesheets page !! </h1>" >stylesheets/index.html

[root@www html]# cat /usr/share/nginx/html/index.html

<h1> welcome to Nginx on www.field.com ! </h1>

[root@www ~]# cd /var/www/html/dynamicpage/

[root@www dynamicpage]# ll

总用量 239516

-rwxr--r--. 1 root root 39931918 4月  28 16:45 1.wmv

-rwxr--r--. 1 root root 50196542 4月  28 16:45 2.wmv

-rwxr--r--. 1 root root  1772348 4月  28 16:44 3.gif

-rwxr--r--. 1 root root 46929988 4月  28 16:45 4.avi

-rwxr--r--. 1 root root 10103245 4月  28 16:44 beyond.mp3

-rwxr--r--. 1 root root  9223502 4月  28 16:45 Boy'z、Twins - 死性不改.mp3

-rw-r--r--. 1 root root      1444月  28 16:44 index.html.bak

drwxr-xr-x. 2 root root     4096 4月  28 16:50 music

-rwxr--r--. 1 root root 46929988 4月  28 16:44 test.avi

drwxr-xr-x. 2 root root     4096 4月  28 16:50 video

-rwxr--r--. 1 root root 10840287 4月  28 16:45 戴佩妮 - 怎样.mp3

-rwxr--r--. 1 root root  9169253 4月  28 16:45 朴树 - 白桦林.mp3

-rwxr--r--. 1 root root  9112840 4月  28 16:45 谭咏麟 - 半梦半醒.mp3

-rwxr--r--. 1 root root 10714537 4月  28 16:45 王菲 - 给自己的情书.mp3

 

3、测试动静分离实现

(1)、测试默认访问:访问http://192.168.88.131:9090/

刷新页面,页面会在【welcome to Nginxon www.field.com ! 】和【welcome to Nginx ontest.field.com ! 】之间以1:2比例跳转

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 20:52:11 localhost haproxy[54270]:192.168.88.1:54691 [28/Apr/2018:20:52:11.343] http-indefault_servers/DftSrv2_test 18/0/1/1/+20 200 +367 - - --NI 1/1/1/0/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

Apr 28 20:52:16 localhost haproxy[54270]:192.168.88.1:54694 [28/Apr/2018:20:52:16.944] http-indefault_servers/DftSrv2_test 0/0/1/2/+3 304 +286 - - --NI 1/1/1/0/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

Apr 28 20:52:23 localhost haproxy[54270]:192.168.88.1:54697 [28/Apr/2018:20:52:23.277] http-indefault_servers/DftSrv1_www 0/0/0/2/+2 200 +367 - - --NI 1/1/1/0/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

Apr 28 20:52:29 localhost haproxy[54270]:192.168.88.1:54701 [28/Apr/2018:20:52:29.646] http-indefault_servers/DftSrv2_test 0/0/1/1/+2 200 +367 - - --NI 1/1/1/1/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

Apr 28 20:52:30 localhost haproxy[54270]:192.168.88.1:54702 [28/Apr/2018:20:52:30.047] http-indefault_servers/DftSrv2_test 21/0/1/2/+24 304 +286 - - --NI 1/1/1/0/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

Apr 28 20:52:30 localhost haproxy[54270]:192.168.88.1:54703 [28/Apr/2018:20:52:30.744] http-indefault_servers/DftSrv1_www 18/0/0/1/+19 200 +367 - - --NI 1/1/1/0/0 0/0{192.168.88.131:9090|} "GET / HTTP/1.1"

 

(2)、测试动态访问:访问http://192.168.88.131:90/music/

可以看到如下页面:

Index of /music

[ICO]         Name       Lastmodified   Size  Description

[DIR]         Parent Directory             -        

[SND]        beyond.mp3     28-Apr-2018 16:43          9.6M        

Apache/2.2.15 (CentOS)Server at 192.168.88.131 Port 90

点击beyond.mp3,可以正常播放

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 23:20:20 localhost haproxy[393]:192.168.88.1:63733 [28/Apr/2018:23:20:20.817] http-indynamic_servers/DycSrv_www 26/0/0/9/+35 200 +189 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /music/ HTTP/1.1"

Apr 28 23:20:20 localhost haproxy[393]:192.168.88.1:63734 [28/Apr/2018:23:20:20.942] http-indefault_servers/DftSrv2_test 0/0/2/2/+4 404 +239 - - --NI 1/1/1/0/0 0/0{192.168.88.131:90|http://192.168.88.131:90/music/} "GET /icons/blank.gifHTTP/1.1"

Apr 28 23:20:21 localhost haproxy[393]:192.168.88.1:63736 [28/Apr/2018:23:20:21.098] http-indefault_servers/DftSrv1_www 0/0/0/1/+1 404 +239 - - --NI 2/2/2/0/0 0/0{192.168.88.131:90|} "GET /favicon.ico HTTP/1.1"

Apr 28 23:20:21 localhost haproxy[393]:192.168.88.1:63737 [28/Apr/2018:23:20:21.098] http-indefault_servers/DftSrv2_test 0/0/0/3/+3 404 +239 - - --NI 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /favicon.ico HTTP/1.1"

Apr 28 23:20:27 localhost haproxy[393]:192.168.88.1:63750 [28/Apr/2018:23:20:27.532] http-indynamic_servers/DycSrv_www 0/0/0/1/+1 206 +345 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/music/} "GET /music/beyond.mp3HTTP/1.1"

 

访问http://192.168.88.131:90/dynamicpage/

可以看到如下页面:

Index of /dynamicpage

[ICO]         Name       Lastmodified   Size  Description

[DIR]         Parent Directory             -        

[SND]        戴佩妮 - 怎样.mp3        28-Apr-2018 16:45          10M

[SND]        朴树 - 白桦林.mp3        28-Apr-2018 16:45          8.7M        

[SND]        王菲 - 给自己的情书.mp3   28-Apr-2018 16:45          10M

[VID]         22.avi       28-Apr-201816:45          45M

[SND]        谭咏麟 - 半梦半醒.mp3        28-Apr-2018 16:45          8.7M        

[VID]         1.wmv      28-Apr-201816:45          38M

[VID]         2.wmv      28-Apr-201816:45          48M

[IMG]        3.gif 28-Apr-201816:44          1.7M        

[SND]        Boy'z、Twins - 死性不改.mp3       28-Apr-2018 16:45          8.8M        

[SND]        beyond.mp3     28-Apr-2018 16:44          9.6M        

[TXT]         index.html.bak         28-Apr-2018 16:44          144          

[DIR]         music/      28-Apr-201816:50          -        

[VID]         test.avi    28-Apr-2018 16:44          45M

[DIR]         video/       28-Apr-201816:50          -        

Apache/2.2.15 (CentOS)Server at 192.168.88.131 Port 90

点击戴佩妮 - 怎样.mp3     可以播放音乐

点击2.wmv    可以播放视屏

点击文件夹 music/,可以进入并播放音乐

点击文件夹 video/,可以进入并播放视屏 test.avi

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 21:05:14 localhost haproxy[57091]:192.168.88.1:55167 [28/Apr/2018:21:05:14.599] http-in dynamic_servers/DycSrv_www113/0/0/4/+117 200 +190 - - ---- 1/1/1/1/0 0/0 {192.168.88.131:90|} "GET/dynamicpage/ HTTP/1.1"

Apr 28 21:05:23 localhost haproxy[57091]:192.168.88.1:55171 [28/Apr/2018:21:05:22.554] http-indynamic_servers/DycSrv_www 0/0/0/484/+484 200 +284 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/} "GET/dynamicpage/%e6%9c%b4%e6%a0%91%20-%20%e7%99%bd%e6%a1%a6%e6%9e%97.mp3HTTP/1.1"

Apr 28 21:05:37 localhost haproxy[57091]:192.168.88.1:55179 [28/Apr/2018:21:05:37.484] http-in dynamic_servers/DycSrv_www0/0/0/3/+3 200 +190 - - ---- 1/1/1/1/0 0/0 {192.168.88.131:90|} "GET/dynamicpage/ HTTP/1.1"

Apr 28 21:05:46 localhost haproxy[57091]:192.168.88.1:55189 [28/Apr/2018:21:05:46.192] http-indynamic_servers/DycSrv_www 0/0/0/218/+218 200 +290 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/} "GET/dynamicpage/2.wmv HTTP/1.1"

Apr 28 21:06:11 localhost haproxy[57091]:192.168.88.1:55225 [28/Apr/2018:21:06:11.501] http-indynamic_servers/DycSrv_www 0/0/0/4/+4 200 +190 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/} "GET/dynamicpage/music/ HTTP/1.1"

Apr 28 21:06:18 localhost haproxy[57091]:192.168.88.1:55250 [28/Apr/2018:21:06:18.420] http-indynamic_servers/DycSrv_www 0/0/0/265/+265 200 +285 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/music/} "GET/dynamicpage/music/%e6%88%b4%e4%bd%a9%e5%a6%ae%20-%20%e6%80%8e%e6%a0%b7.mp3HTTP/1.1"

Apr 28 21:06:42 localhost haproxy[57091]:192.168.88.1:55281 [28/Apr/2018:21:06:42.593] http-indynamic_servers/DycSrv_www 0/0/0/2/+2 200 +190 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /dynamicpage/ HTTP/1.1"

Apr 28 21:06:50 localhost haproxy[57091]:192.168.88.1:55287 [28/Apr/2018:21:06:50.354] http-in dynamic_servers/DycSrv_www0/0/0/1/+1 200 +190 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/} "GET/dynamicpage/video/ HTTP/1.1"

Apr 28 21:07:00 localhost haproxy[57091]:192.168.88.1:55295 [28/Apr/2018:21:07:00.192] http-in dynamic_servers/DycSrv_www0/0/0/150/+150 200 +291 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/dynamicpage/video/} "GET/dynamicpage/video/test.avi HTTP/1.1"

Apr 28 21:07:14 localhost haproxy[57091]:192.168.88.1:55383 [28/Apr/2018:21:07:14.124] http-indynamic_servers/DycSrv_www 0/0/0/1/+1 200 +190 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /dynamicpage/ HTTP/1.1"

 

(3)、测试静态页面访问:访问http://192.168.88.131:90/static/

会以轮询的方式从服务器StaSrv1_test和StaSrv2_web2依次打开如下页面

Welcome to test.field.comstatic page 】、【Welcome toweb2.field.com static page

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 21:52:13 localhost haproxy[393]:192.168.88.1:57836 [28/Apr/2018:21:52:13.507] http-instatic_servers/StaSrv2_web2 113/0/1/1/+115 200 +286 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

Apr 28 21:52:16 localhost haproxy[393]:192.168.88.1:57839 [28/Apr/2018:21:52:16.335] http-instatic_servers/StaSrv1_test 0/0/0/2/+2 200 +289 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

Apr 28 21:52:16 localhost haproxy[393]:192.168.88.1:57840 [28/Apr/2018:21:52:16.820] http-instatic_servers/StaSrv2_web2 17/0/0/1/+18 200 +286 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

Apr 28 21:52:17 localhost haproxy[393]:192.168.88.1:57841 [28/Apr/2018:21:52:17.457] http-instatic_servers/StaSrv1_test 17/0/0/2/+19 200 +289 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

Apr 28 21:52:18 localhost haproxy[393]:192.168.88.1:57843 [28/Apr/2018:21:52:18.977] http-instatic_servers/StaSrv2_web2 19/0/0/1/+20 200 +286 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

访问http://192.168.88.131:90/javascript/

会以轮询的方式从服务器StaSrv1_test和StaSrv2_web2依次打开如下页面

Welcome to test.field.comjavascript page】、【Welcome toweb2.field.com javascript page

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 23:25:32 localhost haproxy[393]:192.168.88.1:64132 [28/Apr/2018:23:25:32.705] http-instatic_servers/StaSrv1_test 165/0/0/2/+167 301 +258 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /javascript HTTP/1.1"

Apr 28 23:25:33 localhost haproxy[393]:192.168.88.1:64134 [28/Apr/2018:23:25:32.893] http-instatic_servers/StaSrv2_web2 12/0/1/131/+144 200 +286 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /javascript/ HTTP/1.1"

Apr 28 23:25:34 localhost haproxy[393]:192.168.88.1:64135 [28/Apr/2018:23:25:34.568] http-instatic_servers/StaSrv1_test 19/0/0/97/+116 200 +289 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /javascript/ HTTP/1.1"

Apr 28 23:25:35 localhost haproxy[393]:192.168.88.1:64136 [28/Apr/2018:23:25:35.399] http-instatic_servers/StaSrv2_web2 16/0/1/1/+18 200 +286 - - ---- 1/1/1/0/0 0/0{192.168.88.131:90|} "GET /javascript/ HTTP/1.1"

访问http://192.168.88.131:90/images/

会以轮询的方式从服务器StaSrv1_test和StaSrv2_web2打开如下页面

Index of /images

[ICO]         Name       Lastmodified   Size  Description

[DIR]         Parent Directory             -        

[IMG]        1.png        18-Nov-201719:13          193K        

[IMG]        2.png        18-Nov-201719:12          150K        

[IMG]        3.png        18-Nov-201719:14          223K        

[IMG]        4.png        18-Nov-201719:14          198K        

[IMG]        5.png        18-Nov-201719:15          214K        

Apache/2.2.15 (CentOS)Server at 192.168.88.131 Port 90

点击图片,会以轮询的方式从服务器StaSrv1_test和StaSrv2_web2获取图片

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 23:27:46 localhost haproxy[393]:192.168.88.1:64241 [28/Apr/2018:23:27:46.720] http-instatic_servers/StaSrv2_web2 193/0/2/1/+196 200 +190 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /images/ HTTP/1.1"

Apr 28 23:27:47 localhost haproxy[393]:192.168.88.1:64242 [28/Apr/2018:23:27:46.720] http-indefault_servers/DftSrv2_test 417/0/0/1/+418 404 +239 - - --NI 1/1/1/0/0 0/0{192.168.88.131:90|http://192.168.88.131:90/images/} "GET /favicon.icoHTTP/1.1"

Apr 28 23:27:49 localhost haproxy[393]:192.168.88.1:64244 [28/Apr/2018:23:27:49.250] http-instatic_servers/StaSrv1_test 20/0/1/1/+22 200 +190 - - ---- 3/3/1/1/0 0/0{192.168.88.131:90|} "GET /images/ HTTP/1.1"

Apr 28 23:27:50 localhost haproxy[393]:192.168.88.1:64245 [28/Apr/2018:23:27:49.250] http-instatic_servers/StaSrv2_web2 1072/0/1/2/+1075 200 +190 - - ---- 3/3/1/0/0 0/0{192.168.88.131:90|} "GET /images/ HTTP/1.1"

Apr 28 23:27:53 localhost haproxy[393]:192.168.88.1:64246 [28/Apr/2018:23:27:49.250] http-instatic_servers/StaSrv1_test 4370/0/0/4/+4374 200 +281 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/images/} "GET /images/3.pngHTTP/1.1"

Apr 28 23:27:54 localhost haproxy[393]:192.168.88.1:64247 [28/Apr/2018:23:27:50.306] http-instatic_servers/StaSrv2_web2 4660/0/1/2/+4663 200 +281 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/images/} "GET /images/3.pngHTTP/1.1"

Apr 28 23:27:57 localhost haproxy[393]:192.168.88.1:64251 [28/Apr/2018:23:27:57.660] http-instatic_servers/StaSrv1_test 18/0/1/1/+20 200 +281 - - ---- 1/1/1/1/0 0/0 {192.168.88.131:90|http://192.168.88.131:90/images/}"GET /images/3.png HTTP/1.1"

Apr 28 23:27:58 localhost haproxy[393]:192.168.88.1:64252 [28/Apr/2018:23:27:58.125] http-instatic_servers/StaSrv2_web2 22/0/1/1/+24 200 +281 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|http://192.168.88.131:90/images/} "GET /images/3.pngHTTP/1.1"

访问http://192.168.88.131:90/1.png和http://192.168.88.131:90/5.jpg

会以轮询的方式从服务器StaSrv1_testStaSrv2_web2获取图片

[root@www ~]# tail -f /var/log/haproxy.log

Apr 28 23:30:47 localhost haproxy[393]:192.168.88.1:64354 [28/Apr/2018:23:30:47.500] http-instatic_servers/StaSrv1_test 107/0/1/210/+318 200 +281 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /1.png HTTP/1.1"

Apr 28 23:30:47 localhost haproxy[393]:192.168.88.1:64355 [28/Apr/2018:23:30:47.500] http-indefault_servers/DftSrv1_www 402/0/1/1/+404 404 +239 - - --NI 1/1/1/0/0 0/0{192.168.88.131:90|http://192.168.88.131:90/1.png} "GET /favicon.icoHTTP/1.1"

Apr 28 23:31:00 localhost haproxy[393]:192.168.88.1:64358 [28/Apr/2018:23:30:59.997] http-instatic_servers/StaSrv2_web2 14/0/1/1/+16 200 +281 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /1.png HTTP/1.1"

Apr 28 23:31:11 localhost haproxy[393]:192.168.88.1:64362 [28/Apr/2018:23:31:11.202] http-instatic_servers/StaSrv1_test 18/0/1/2/+21 200 +281 - - ---- 1/1/1/1/0 0/0{192.168.88.131:90|} "GET /1.png HTTP/1.1"

Apr 28 23:38:28 localhost haproxy[393]:192.168.88.1:64479 [28/Apr/2018:23:38:28.451] http-in static_servers/StaSrv2_web212/0/1/1/+14 200 +282 - - ---- 2/2/1/1/0 0/0 {192.168.88.131:90|} "GET/5.jpg HTTP/1.1"

Apr 28 23:38:31 localhost haproxy[393]:192.168.88.1:64480 [28/Apr/2018:23:38:28.451] http-instatic_servers/StaSrv1_test 2473/0/1/339/+2813 200 +282 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /5.jpg HTTP/1.1"

Apr 28 23:38:32 localhost haproxy[393]:192.168.88.1:64482 [28/Apr/2018:23:38:30.907] http-instatic_servers/StaSrv2_web2 1174/0/1/1/+1176 200 +282 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /5.jpg HTTP/1.1"

Apr 28 23:38:32 localhost haproxy[393]:192.168.88.1:64483 [28/Apr/2018:23:38:32.065] http-instatic_servers/StaSrv1_test 601/0/1/2/+604 200 +282 - - ---- 2/2/1/1/0 0/0{192.168.88.131:90|} "GET /5.jpg HTTP/1.1"

 

(4)、关闭静态服务器,测试报错页面:

[root@test html]# service httpd stop

停止 httpd:[确定]

[root@web2 html]# service httpd stop

停止 httpd:[确定]

访问:http://192.168.88.131:90/images/和http://192.168.88.131:90/static/

可以看到【Sorry! Server isbeing maintained. Please wait.Thanks!】页面

[root@www ~]# tail -f /var/log/haproxy.log

Apr 29 00:19:52 localhost haproxy[393]:192.168.88.1:65169 [29/Apr/2018:00:19:51.987] http-instatic_servers/<NOSRV> 19/-1/-1/-1/+19 503 +55 - - SC-- 0/0/0/0/0 0/0{192.168.88.131:90|} "GET /images/ HTTP/1.1"

Apr 29 00:19:52 localhost haproxy[393]:192.168.88.1:65170 [29/Apr/2018:00:19:52.178] http-instatic_servers/<NOSRV> 42/-1/-1/-1/+42 503 +55 - - SC-- 0/0/0/0/0 0/0{192.168.88.131:90|} "GET /images/ HTTP/1.1"

Apr 29 00:19:56 localhost haproxy[393]:192.168.88.1:65171 [29/Apr/2018:00:19:56.924] http-instatic_servers/<NOSRV> 0/-1/-1/-1/+0 503 +55 - - SC-- 1/1/0/0/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

Apr 29 00:20:56 localhost haproxy[393]:192.168.88.1:65188 [29/Apr/2018:00:20:56.939] http-instatic_servers/<NOSRV> 0/-1/-1/-1/+0 503 +55 - - SC-- 1/1/0/0/0 0/0{192.168.88.131:90|} "GET /static/ HTTP/1.1"

 

(5)、测试“Haproxy Statistics”服务器统计网页

访问http://192.168.88.131:8088/haproxyadmin?stats,输入账户密码:

可以进入haproxy统计页面,多次点击动静态页面,并让http下线,测试“Haproxy Statistics”统计,可以看到进入下图页面:

[root@test html]# service httpd stop

停止 httpd:[确定]

[root@test html]# service httpd start

正在启动 httpd:[确定]

[root@test html]# service httpd stop

停止 httpd:[确定]

[root@test html]# service httpd start

正在启动 httpd:[确定]

[root@test html]# service httpd stop

停止 httpd:[确定]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值