成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

haproxy 7層負載均衡代理轉發實戰講解

系統 Linux
haproxy7層模式下,HAProxy會分析協議,并且能通過允許、拒絕、交換、增加、修改或者刪除請求(request)或者回應(response)里指定內容來控制協議,做L7的整體表現和F5/netscaler等硬件負載均衡比,毫不遜色。
█ 1、rs web server機測試環境準備:

●1.1 在/var下分別建立php、nginx、pic三個站點目錄,并增加index.htms文件及增加內容
假定 php nginx pic分別代表解析不同的服務。

[root@ha2 ~]#for name in php nginx pic ;do mkdir -p /var/$name;echo $name >/var/$name/index.html;done
●1.2 檢查結果
[root@ha2 ~]# for name in php nginx pic ;do echo -n "/var/$name/index.html → :";cat /var/$name/index.html; done
/var/php/index.html → :php
/var/nginx/index.html → :nginx
/var/pic/index.html → :pic

●1.3 安裝http服務
[root@ha2 ~]# yum install httpd -y

●1.4 配置http服務

先做配置文件備份
[root@ha2 conf]# cd /etc/httpd/conf
[root@ha2 conf]# cp httpd.conf httpd.conf.oldboy.110625
[root@ha2 conf]# ls -l
total 88
-rw-r--r-- 1 root root 34399 Jun 26 16:40 httpd.conf
-rw-r--r-- 1 root root 34399 Jun 26 16:49 httpd.conf.oldboy.110625
-rw-r--r-- 1 root root 13139 May  4 18:54 magic

編輯httpd.conf 最下面加
<Directory "/var">
    Options FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin
49000448@qq.com
        ServerName nginx.etiantian.org
        ServerAlias etiantian.org
        DocumentRoot "/var/nginx"
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin
49000448@qq.com
        ServerName php.etiantian.org
        DocumentRoot "/var/php"
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin
49000448@qq.com

        ServerName pic.etiantian.org
        DocumentRoot "/var/pic"
</VirtualHost>

提示:配置完成記得重起http服務。

●1.5 http服務器本地增加host內容如下
echo '10.0.0.162 nginx.etiantian.org' >>/etc/hosts
echo '10.0.0.162 php.etiantian.org' >>/etc/hosts
echo '10.0.0.162 pic.etiantian.org' >>/etc/hosts
echo '10.0.0.162 etiantian.org' >>/etc/hosts

●1.6 在我們的筆記本電腦上
C:\WINDOWS\system32\drivers\etc\hosts增加如下hosts內容

10.0.0.162 nginx.etiantian.org
10.0.0.162 php.etiantian.org
10.0.0.162 pic.etiantian.org
10.0.0.162 etiantian.org
嚴重提示:
1.這里解析的IP 為http server的IP
2.這里的host相當于模擬DNS的解析

●1.7測試增加http虛擬主機的配置
訪問:http://nginx.etiantian.org 結果應該為nginx,其它類推。
訪問:
http://php.etiantian.org 結果應該為php,其它類推。
訪問:
http://pic.etiantian.org
結果應該為pic,其它類推。


█ 2 配置haproxy L7負載均衡
●2.1 haproxy.conf配置
#______________________________________________________________________

 

defaults
        log     global
        mode    http
        retries 3
        option redispatch
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000
        stats enable
        stats hide-version
        stats uri /admin?stats
        stats auth proxy:123456
        option httpclose
 

●2.2 更改hosts
在我們的筆記本電腦上
C:\WINDOWS\system32\drivers\etc\hosts增加如下hosts內容

10.0.0.162 nginx.etiantian.org
10.0.0.162 php.etiantian.org
10.0.0.162 pic.etiantian.org
10.0.0.162 etiantian.org
嚴重提示:這里解析的IP 為haproxy server的IP

●2.3 測試haproxy的轉發應用
確認host文件配置正常后,可以瀏覽 etiantian.org
看是否能跳轉到nginx.etiantian.org 檢查點:url和內容顯示
提示:個別瀏覽器,有可能看不到URL跳轉,只要是內容顯示正確就對了。

可以修改配置在測試下:
        acl short_dom hdr(Host) -i etiantian.org
        redirect prefix
http://php.etiantian.org code 301 if short_dom
目的:使訪問
http://etiantian.org 跳轉到http://php.etiantian.org

重起haproxy服務后,進行訪問查看。

#########################################################

注意以上 已經應用到正式環境N久 大家可放心使用。

●2.4 更多7層的技術

比如 根據后綴進行過濾轉發
acl url_static  path_end         .gif .png .jpg .css .js

在比如根據目錄進行過濾轉發
acl oldboy_java path_beg /java/
acl static_ryan path_beg /images/
acl static_ryan path_beg /css/

配置haproxy L7負載均衡-之根據URL地址目錄轉發

準備RS SERVER測試環境

建立測試目錄:
for name in php nginx pic ;do mkdir -p /var/$name/$name;echo $name >/var/$name/$name/index.html;done

配置http服務
刪除上面做的任何apache配置(或者還原httpd.conf
[root@ha2 conf]# cd /etc/httpd/conf
[root@ha2 conf]# /bin/cp httpd.conf.oldboy.110625  httpd.conf

然后編輯httpd.conf 最下面加
<Directory "/var">
    Options FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
</Directory>

Listen 8080
Listen 8090

NameVirtualHost *:80
NameVirtualHost *:8080
NameVirtualHost *:8090
<VirtualHost *:80>
        ServerAdmin 49000448@qq.com
        ServerName www.etiantian.org
        ServerAlias etiantian.org
        DocumentRoot "/var/nginx"
</VirtualHost>
<VirtualHost *:8080>
        ServerAdmin 49000448@qq.com
        ServerName www.etiantian.org
        DocumentRoot "/var/php"
</VirtualHost>
<VirtualHost *:8090>
        ServerAdmin 49000448@qq.com
        ServerName www.etiantian.org
        DocumentRoot "/var/pic"
</VirtualHost>


● 3.2
基于目錄轉發的haproxy配置
frontend oldboy_test
        bind *:80
        acl short_domain hdr(Host) -i etiantian.org
        redirect prefix http://www.etiantian.org code 301 if short_domain

        #acl lang_domain hdr(Host) -i www.etiantian.org
        #use_backend staticpools if lang_domain

        default_backend staticpools

#http://www.etiantian.org/nginx/...,提供靜態內容訪問(htm,html,css,js
backend staticpools
        balance roundrobin
        server oldboy-1 10.0.0.151:80 check port 80 inter 3000 fall 3
        server oldboy-2 10.0.0.151:81 check port 81 inter 3000 fall 3
        server oldboy-3 10.0.0.151:82 check port 82 inter 3000 fall 3

#提示:后面兩個rs是虛構的,只是告訴大家可以這樣加server.有沒有都不會影響訪問。以下同。

#http://www.etiantian.org/php/... 提供動態內容訪問(以*.php結尾)
backend dynamicpools
        balance roundrobin
 cookie SERVERID insert indirect
        server oldboy-4 10.0.0.151:8080 maxconn 2048 weight 50  cookie A check port 8080 inter 3000 fall 3
        server oldboy-5 10.0.0.151:8180 maxconn 2048 weight 100 cookie B check port 8180 inter 3000 fall 3
        server oldboy-6 10.0.0.151:8280 maxconn 2048 weight 100 cookie C check port 8280 inter 3000 fall 3
        #
列出更詳細的參數,供大家參考使用。
#http://www.etiantian.org/pic/...
提供圖片內容訪問(以*.jpg,*.png,*.gif等結尾)
backend picpools
        balance roundrobin
        server oldboy-7 10.0.0.151:8090 check port 8090 inter 3000 fall 3
        server oldboy-8 10.0.0.151:8190 check port 8190 inter 3000 fall 3
        server oldboy-9 10.0.0.151:8290 check port 8290 inter 3000 fall 3
#
提示:server后面的名稱是自己定義的,名稱不要重復就好。

當多臺服務器時,每個池子可配置成如下形式:
cookie SERVERID insert indirect
server oldboy-1 10.0.0.163:8080 cookie ett-1-1 check port 8080 inter 3000 fall 3

配置基于URL的健康檢查
option httpchk HEAD /checkstatus.jsp HTTP/1.0

配置用戶端hosts
10.0.0.162 www.etiantian.org
提示:10.0.0.162 haproxyIP,這里是模擬DNS的解析,實際配置時,在DNS里解析即可


●3.4
在用戶端進行訪問測試
  3.4.1
查看hosts解析是否正確
C:\Documents and Settings\hyran>ping www.etiantian.org

Pinging www.etiantian.org [10.0.0.162] with 32 bytes of data:

Reply from 10.0.0.162: bytes=32 time=5ms TTL=64
Reply from 10.0.0.162: bytes=32 time<1ms TTL=64
Reply from 10.0.0.162: bytes=32 time<1ms TTL=64
   3.4.2
測試URL地址 看是否符合預期要求
分別訪問:
http://www.etiantian.org/nginx/
http://www.etiantian.org/php/
http://www.etiantian.org/pic/
如果能返回對應自己目錄的內容,那恭喜你,搞定了。

 

責任編輯:龐桂玉 來源: 51cto.com
相關推薦

2010-05-05 22:58:46

2024-01-31 09:11:16

HaproxyHttpTCP

2012-02-15 00:15:48

2019-07-09 15:10:02

Nginx反向代理負載均衡

2013-04-22 11:29:14

Nginx

2012-05-07 10:17:48

2019-06-19 15:34:39

Nginx反向代理負載均衡

2010-04-20 18:13:44

網絡負載均衡設置

2010-04-26 13:34:43

DNS負載均衡

2010-04-20 10:27:57

什么是負載均衡

2018-10-17 09:51:04

負載均衡服務器性能

2013-08-22 16:32:24

2012-02-14 00:01:22

2010-05-10 18:11:24

負載均衡機

2014-07-31 10:55:08

域名NAT七層

2010-04-21 10:30:12

負載均衡

2010-05-04 13:23:55

Tomcat負載均衡

2010-05-06 16:58:10

Dns負載均衡

2010-04-20 16:34:31

2019-09-27 08:18:13

負載均衡核心Key
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久精品国产99国产 | 国产精品成人一区二区三区 | 91亚洲精 | 亚洲美女网站 | 精品国产一区二区三区成人影院 | 亚洲福利精品 | 欧美在线| 亚洲精品一区二区在线观看 | 亚洲成人免费视频 | 国产精品我不卡 | 精品乱码一区二区 | 91精品久久久久久久 | 免费在线观看一区二区 | 国产亚洲二区 | 国产资源在线观看 | 欧美激情精品久久久久久免费 | 日韩在线免费视频 | 日韩中文一区二区三区 | 亚洲精品一区国产精品 | 日日夜夜精品免费视频 | 91色在线 | 国产精品毛片无码 | 在线视频日韩精品 | 农村黄性色生活片 | 中文字幕日韩三级 | 国产毛片久久久久久久久春天 | h视频在线看 | 一级黄色片日本 | av中文字幕在线 | 看特级黄色片 | 日韩欧美网 | 国产在线精品一区二区三区 | 亚洲国产第一页 | 一区二区免费看 | 欧美性大战xxxxx久久久 | 欧美精品一区二区在线观看 | 日韩欧美在线观看视频 | 久久久91精品国产一区二区三区 | 高清av一区 | 美女精品一区 | 日韩成人在线播放 |