歡迎您光臨本站 註冊首頁

Squid2.7+iptables+透明代理+sarg 生產適用版,無故障運行15天,圖示魷魚工作原理

安裝不用多說
給出參數
順便說一下,2.7以前的透明代理參數根本不需要以下這四行,這是個誤區,我就被這個害過。
httpd_accel_host ProxyServer  
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
根本不需要這幾行的

./configure --prefix=/usr/local/squid
--enable-poll
--disable-internal-dns
--enable-storeio=aufs,coss,diskd,ufs
--enable-default-err-languages=Simplify_Chinese
--enable-linux-netfilter         //要想實現透明代理,必須選取這個參數,啟用linux netfilter支持
--enable-err-language=Simplify_Chinese
--enable-default-err-languages=Simplify_Chinese
--enable-arp-acl
--enable-snmp
--enable-async-io=180       //1G內存,並且是雙核的選180,否則選100以下
--enable-cahce-digests      
--enable-underscore          //允許請求的URL出現下劃線
--enable-gnuregex  
--enable-icmp
--enable-kill-parent-hack
#make
#make install

建立用戶和組squid
建立/var/squid目錄,將目錄的許可權設置為squid所有 chown -R squid /var/squid
將/usr/local/squid目錄的許可權設置為squid所有


清空/usr/loca/squid/etc/squid.conf
#Squid Ver 2.7 For xj_kt No.2 Primary School

http_port 192.168.1.1:3128 transparent     //就是這個要注意了,2.7以後的版本只需要加這個參數即可實現透明代理
http_port 192.168.2.1:3128 transparent     //監聽二塊網卡。因為一個是學生用,一個是老師使用
cache_mem 300 MB                           //使用最大300MB的內存,如果你是2G以上的可以適當增加,我原本是1G,發現1G根本不夠用,就買了一根。
maximum_object_size 9000 KB        //最大緩存對象大小為9MB,視你情況而定
maximum_object_size_in_memory 6128 KB   //內存緩存最大為6.1MB ,視你情況而定

dns_nameservers 192.168.1.1       //DNS伺服器,我在這台機器上安裝了bind緩存伺服器,就用自己的啦
cache_dir ufs /var/squid/cache 58000 16 256      //裝載緩存的目錄為/var/squid/cache,大小58G
error_directory /usr/local/squid/share/errors/Simplify_Chinese

acl nocache urlpath_regex cookie.*\.php *\.jsp *\.asp *\.pl *\.cgi
no_cache deny nocache      //不緩存php jsp asp pl cgi 因為這些都是動態網頁

acl audio urlpath_regex -i .torrent$ .avi$ .mp3$ .mp4$
http_access deny audio      //禁止下載torrent avi mp3 mp4

acl name url_regex -i  關鍵詞
http_access deny name


cache_access_log none     //不記錄日誌了,由於學校電腦太多,一天的日誌大於2MB,要記錄日誌,寫出全路徑,並使squid組有寫許可權
cache_log none
cache_store_log none

acl localhost src 192.168.2.0/24 192.168.1.0/24
http_access allow localhost        //允許我的這二塊網卡都可以使用squid上網


acl all src 0.0.0.0/0.0.0.0
http_access deny all                //其它所有地址禁止

acl safe port 80 21 443 3128
http_access allow safe            //允許這些埠通過

cache_effective_user squid    //運行squid用戶和組
cache_effective_group squid
cache_mgr wubifans_huaxing@yahoo.com.cn   //當現在錯誤提示時,會顯示你的郵箱
acl conncount maxconn 5         //最大連接為5

visible_hostname LinuxProxyServer    //代理伺服器所顯示的名字
icon_directory /usr/local/squid/share/icons


#ipcache_size 2024    //緩存IP所解析的正反解信息大小。由於我已經有了bind,就註釋掉
#ipcache_low 90
#ipcache_high 95
#fqdncache_size 2024

到現在, squid是不可能代理的,因為防火牆不允許squid幹活

下面說說防火牆配置
網路環境:
eth0:218.84.9.1    eth1:192.168.1.1  eth2:192.168.2.1
vi fw
chmod a+x fw
在/etc/rc.d/rc.local里添加fw角本所在的全路徑
fw角本內容
#!/bin/bash
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t filter -F
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP


#實現192.168.2 與192.168.1源地址轉換
/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 218.84.9.1
/sbin/iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j SNAT --to-source 218.84.9.1

#將eth1與eth2去往80埠的數據包重定向去本機的3128埠,也就是SQUID處理
/sbin/iptables -t nat -A PREROUTING -i eth1 -s 192.168.1.0/24 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
/sbin/iptables -t nat -A PREROUTING -i eth2 -s 192.168.2.0/24 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

#SQUID允許的客戶
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 3128 -j ACCEPT
/sbin/iptables -A OUTPUT -d 192.168.1.0/24 -p tcp --s port 3128 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.2.0/24 -p tcp --dport 3128 -j ACCEPT
/sbin/iptables -A OUTPUT -d 192.168.2.0/24 -p tcp --s port 3128 -j ACCEPT

#允許本機向外解析,分析一下數據流,先是output,再是input
/sbin/iptables -A OUTPUT -d 0/0 -p ALL --dport 53 -j ACCEPT
/sbin/iptables -A INPUT -s 0/0 -p ALL --sport 53 -j ACCEPT

#允許80
/sbin/iptables -A OUTPUT -d 0/0 -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -s 0/0 -p tcp --sport 80 -j ACCEPT

#允許內網使用本機的dns,懶得再寫一條,就將源地址改寫為16位的子網編碼
/sbin/iptables -A INPUT -s 192.168.0.0/16 -p udp --dport 53 -j ACCEPT
/sbin/iptables -A INPUT -d 192.168.0.0/16 -p udp --sport 53 -j ACCEPT


#現在過濾不是做在output與input里,因為數據是從一個網卡流動到另一個網卡,得在forward里
/sbin/iptables -A FORWARD -s 192.168.1.0/24 -d 0/0 -p tcp --dport 80  -j ACCEPT
/sbin/iptables -A FORWARD -s 0/0 -d 192.168.1.0/24 -p tcp  -j ACCEPT
/sbin/iptables -A FORWARD -s 192.168.2.0/24 -d 0/0 -p tcp --dport 80  -j ACCEPT
/sbin/iptables -A FORWARD -s 0/0 -d 192.168.2.0/24 -p tcp  -j ACCEPT

#允許使用ssh,一定要不允許root登陸,將permitrootlogin no加上  允許root登陸 不
/sbin/iptables -A INPUT -p tcp -s any/0 --sport 1024:65535 --dport 22 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --sport 22 -d any/0 --dport 1024:65535 -j ACCEPT


運行防火牆/etc/rc.d/fw,必須root用戶.
/usr/local/squid/sbin/squid -z
至此一個包過濾的防火牆加透明代理已經完成.
將你的日誌開啟。看看access.log
1224701847.121 RELEASE -1 FFFFFFFF 99440A26AEF26787E7368B90458A3D54  403 1224701847        -1        -1 text/html 1156/1156 GET http://www.chinaunix.net/favicon.ico


用戶應該OK了,設置這個透明代理,我將這個精華區的所有帖全看得差不多了。感謝前輩們的貢獻。星期一上課時,我將我的squid.conf與防火牆配置帖出來。哪些文件已經被驗證可用,已經運行了15天了。生產適用,呵呵,歡迎CU的兄弟批評指正.還是不行,加我QQ3645636我幫你
還是建議你將squid權威指南看完,哪樣就不會問題多多了,不過新的版本參數與2.7以前有所不同,得注意


Sarg的安裝請看這裡
http://bbs.chinaunix.net/thread-1339666-1-1.html

[ 本帖最後由 3645636 於 2008-12-24 00:59 編輯 ]
《解決方案》

有多少用戶? 用戶少基本沒什麼問題
《解決方案》

不錯,好文。。
《解決方案》

以圖為證,當前一共有36個用戶,安裝了sarg
看帖里新添加的附件

現在學生的微機課都停了,所以不高,如果高上學生一塊上的話。超碼得有180個用戶了

[ 本帖最後由 3645636 於 2008-12-24 00:56 編輯 ]
《解決方案》

acl conncount maxconn 5

似乎沒有看到你有應用這個acl?
《解決方案》

記錄一下。
《解決方案》

回復 #5 zenglingping 的帖子

有的,這個配置文件是我記錄在郵箱里的,實際運行的,有的
最大連接數為5

[ 本帖最後由 3645636 於 2008-12-24 12:46 編輯 ]
《解決方案》

每ip 5個連接數,樓主做網管可真有點扣啊。:shock:
《解決方案》

兄弟,我想問問,如果想在sarg中顯示用戶訪問的全url路徑而不只是domainName,如何設置?
《解決方案》

再加個http 殺毒吧.

[火星人 ] Squid2.7+iptables+透明代理+sarg 生產適用版,無故障運行15天,圖示魷魚工作原理已經有747次圍觀

http://coctec.com/docs/service/show-post-13621.html