服務(wù)項目:網(wǎng)站建設(shè)、仿站、程序開發(fā)、APP開發(fā)設(shè)計、移動網(wǎng)站開發(fā)設(shè)計、企業(yè)網(wǎng)站設(shè)計、電子商務(wù)網(wǎng)站開發(fā)、網(wǎng)站維護(hù)、網(wǎng)站推廣、UX/UI 、HTML5、CSS3、JS / Jquery ...
四川???萍加邢薰?></a></div>
                    <div   id=四川???萍加邢薰? title=
四川???萍加邢薰?(開發(fā)設(shè)計官網(wǎng))TEL : 15308000360 / QQ : 38585404

您的位置:首頁 > 技術(shù)經(jīng)驗 > 服務(wù)器 > 正文

squid tcp_outgoing_address 出口IP隨機調(diào)用
技術(shù)支持服務(wù)電話:15308000360 【7x24提供運維服務(wù),解決各類系統(tǒng)/軟硬件疑難技術(shù)問題】

squid 代理服務(wù)器,使用用戶名和密碼訪問代理,對于出口ip的不同方式的調(diào)用或者以隨機的方式調(diào)用,因為服務(wù)器使用的是squid 2.7版本的,根據(jù)官方手冊 3.2版本的有 acl xxx random 1/24 可以隨機(未測試)

若此篇文章還不能解決您的問題,請聯(lián)系QQ:38585404  獲取有償技術(shù)服務(wù)...

配置如下

http_port 142.4.106.1:3128
http_port 142.4.106.xx:3128
http_port 142.4.106.xx:3128
auth_param basic program /user/lib/squid/libexec/ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 12 hours
auth_param basic casesensitive off
#使用用戶或者用戶組來確定出口的IP
#acl wltony proxy_auth wltony
#acl wltony1 proxy_auth wltony1
#tcp_outgoing_address 142.4.106.xxx wltony
#根據(jù)被訪問服務(wù)器 IP 來確定出口IP
#acl no1 myip 142.4.106.xxx
#tcp_outgoing_address 142.4.106.xxx no1
acl src_73 src 142.4.106.xxx
acl src_74 src 142.4.106.xxx
tcp_outgoing_address 142.4.106.xxx src_73
tcp_outgoing_address 142.4.106.xxx src_74
#first_req 為主訪問IP
acl first_req src 142.4.106.1
acl second_req src 142.4.106.xxx
acl second_req src 142.4.106.xxx
cache_peer 142.4.106.xxx parent 3128 0 round-robin no-query login=wltony:xxx
cache_peer 142.4.106.xxx parent 3128 0 round-robin no-query login=wltony:xxx
cache_peer_access 142.4.106.xxx allow first_req
cache_peer_access 142.4.106.xxx allow first_req
cache_peer_access 142.4.106.xxx deny second_req
cache_peer_access 142.4.106.xxx deny second_req
never_direct allow first_req
never_direct deny second_req
#close cache www.haipai.wang
acl NCACHE method GET
no_cache deny NCACHE
acl ncsa_users proxy_auth REQUIRED
acl all src all
header_access Via deny all
header_access X-Forwarded-For deny all
http_access allow ncsa_users
#http_access allow wltony
#http_access allow wltony1
http_access deny all


正向代理: 機器通過該機器訪問外部網(wǎng)絡(luò).
本例: 使用爬蟲去抓取網(wǎng)絡(luò)數(shù)據(jù).但抓取過多時會被封IP.于是, 在一個機器上綁定若干個 IP. 抓取時使用代理.
當(dāng)然, 可以使用其它代理機器.但這里我們是使用的代理到本機.
 
在本機上綁定了 4 個 IP. 同時運行四個抓取實例. 每一個都使用代理, 代理到本機不同的端口.

本機上的 IP 分別是:
22.55.153.1
22.55.153.2
22.55.153.3
22.55.153.4
 
分別使用端口:
22881
22882
22883
22884
 
squid 配置: /etc/squid/squid.conf:
 
# 在代理的時候去掉請求頭部.再另行添加代理后的頭部
forwarded_for delete
via Deny all
 
# 允許本機訪問.如果不加,可能不成功
http_access allow localhost
 
 
# 定義本機上的各個端口
acl p1 myport 22881
acl p2 myport 22882
acl p3 myport 22883
acl p4 myport 22884
 
# 讓 squid 監(jiān)聽本機的各個端口
http_port 22881
http_port 22882
http_port 22883
http_port 22884
 
# 定義從 squid 代理往外的數(shù)據(jù), 每個 ip 分別使用哪個端口
tcp_outgoing_address 22.55.153.1   p1
tcp_outgoing_address 22.55.153.2   p2
tcp_outgoing_address 22.55.153.3   p3
tcp_outgoing_address 22.55.153.4   p4
 
 
把上面的配置加到當(dāng)前的配置文件上部即可.
 
配置完后重啟 squid 服務(wù).
 
然后再配置爬蟲軟件使用代理,使用相應(yīng)的 IP 和端口.
當(dāng)使用 22881 端口時, 出口使用的 IP 是 ip1.
按上面的 tcp_outgoing_address  配置的規(guī)則.
依此類推, 這樣, 同時運行四個任務(wù),實際上出去的 IP 就是四個. 就不會被封了. 



上一篇:nginx+php-fpm性能參數(shù)優(yōu)化(配置文件)
下一篇:CentOS下一張網(wǎng)卡設(shè)置多個IP

相關(guān)熱詞搜索:squid 隨機IP