自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

haproxy 7層負(fù)載均衡代理轉(zhuǎn)發(fā)實(shí)戰(zhàn)講解

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

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

[root@ha2 ~]#for name in php nginx pic ;do mkdir -p /var/$name;echo $name >/var/$name/index.html;done
●1.2 檢查結(jié)果
[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服務(wù)
[root@ha2 ~]# yum install httpd -y

●1.4 配置http服務(wù)

先做配置文件備份
[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服務(wù)。

●1.5 http服務(wù)器本地增加host內(nèi)容如下
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內(nèi)容

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
嚴(yán)重提示:
1.這里解析的IP 為http server的IP
2.這里的host相當(dāng)于模擬DNS的解析

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


█ 2 配置haproxy L7負(fù)載均衡
●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內(nèi)容

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
嚴(yán)重提示:這里解析的IP 為haproxy server的IP

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

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

重起haproxy服務(wù)后,進(jìn)行訪問查看。

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

注意以上 已經(jīng)應(yīng)用到正式環(huán)境N久 大家可放心使用。

●2.4 更多7層的技術(shù)

比如 根據(jù)后綴進(jìn)行過濾轉(zhuǎn)發(fā)
acl url_static  path_end         .gif .png .jpg .css .js

在比如根據(jù)目錄進(jìn)行過濾轉(zhuǎn)發(fā)
acl oldboy_java path_beg /java/
acl static_ryan path_beg /images/
acl static_ryan path_beg /css/

配置haproxy L7負(fù)載均衡-之根據(jù)URL地址目錄轉(zhuǎn)發(fā)

準(zhǔn)備RS SERVER測試環(huán)境

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

配置http服務(wù)
刪除上面做的任何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
基于目錄轉(zhuǎn)發(fā)的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/...,提供靜態(tài)內(nèi)容訪問(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是虛構(gòu)的,只是告訴大家可以這樣加server.有沒有都不會影響訪問。以下同。

#http://www.etiantian.org/php/... 提供動態(tài)內(nèi)容訪問(以*.php結(jié)尾)
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
        #
列出更詳細(xì)的參數(shù),供大家參考使用。
#http://www.etiantian.org/pic/...
提供圖片內(nèi)容訪問(以*.jpg,*.png,*.gif等結(jié)尾)
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后面的名稱是自己定義的,名稱不要重復(fù)就好。

當(dāng)多臺服務(wù)器時,每個池子可配置成如下形式:
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的解析,實(shí)際配置時,在DNS里解析即可


●3.4
在用戶端進(jìn)行訪問測試
  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地址 看是否符合預(yù)期要求
分別訪問:
http://www.etiantian.org/nginx/
http://www.etiantian.org/php/
http://www.etiantian.org/pic/
如果能返回對應(yīng)自己目錄的內(nèi)容,那恭喜你,搞定了。

 

責(zé)任編輯:龐桂玉 來源: 51cto.com
相關(guān)推薦

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反向代理負(fù)載均衡

2012-05-07 10:17:48

2013-04-22 11:29:14

Nginx

2019-06-19 15:34:39

Nginx反向代理負(fù)載均衡

2018-10-17 09:51:04

負(fù)載均衡服務(wù)器性能

2010-04-20 18:13:44

網(wǎng)絡(luò)負(fù)載均衡設(shè)置

2010-04-20 10:27:57

什么是負(fù)載均衡

2010-04-26 13:34:43

DNS負(fù)載均衡

2012-02-14 00:01:22

2014-07-31 10:55:08

域名NAT七層

2013-08-22 16:32:24

2010-05-10 18:11:24

負(fù)載均衡機(jī)

2019-09-27 08:18:13

負(fù)載均衡核心Key

2017-12-18 12:04:02

Nginx代理均衡

2019-11-04 15:35:53

Nginx反向代理負(fù)載均衡

2019-09-18 10:39:08

負(fù)載均衡反向代理TCP

2018-01-17 09:57:41

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號