📄 1520.html
字号:
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>用Squid实现代理上网及计费</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>一、 获取Squid及相关的软件 <br>
<br>
---- 从http://squid-cache.org/上获取Squid软件,从http://web.onda.com.br/orso/上获取htpasswd_plus和SQMGRLOG,并将它们保存在/tmp目录下。 <br>
<br>
二、在Linux下编译并安装Squid <br>
<br>
---- 我们假设软件环境为Redhat Linux 7.x,编译和安装Squid的操作步骤如下。 <br>
<br>
---- 1.下载最新版本的源文件Squid-2.3.STABLE4.src.tar.gz,并将它放置在/tmp目录下。 <br>
<br>
---- 2.以root身份创建用户squidadmin#adduser squidadmin <br>
<br>
---- 在缺省的情况下,同名组squidadmin已经被建立。Squid因为考虑到安全问题,不能以root身份运行,所以从一开始就使用新建的用户进行安装管理。 <br>
<br>
---- 3.以squidadmin登录,对Squid源文件解包和安装。 <br>
<br>
$cd /tmp <br>
$tar -zxvf squid* <br>
$cd squid* <br>
$./configure --prefix=/usr/local/squid <br>
进入Squid目录进行编译,考虑的选项是安装路径 <br>
--prefix=/usr/local/squid。 <br>
$make <br>
$make install <br>
<br>
-- -- 4.进入/usr/local/squid/bin目录,执行$./squid -z,创建cache交换目录。至此,Squid已经安装在用户的系统上了。然而,要让Squid正常运转,用户还需要做一些基本设置。Squid的运转只与 /usr/local/squid/etc/squid.conf有关,所有设置均在此文件中完成。 <br>
<br>
三、Squid基本设置 <br>
<br>
#Defaults: <br>
acl all src 0.0.0.0/0.0.0.0 <br>
设置的规则在此处加入。 <br>
http_access deny all <br>
<br>
---- 在缺省的情况下,有以上2条规则。当有请求未能匹配任何一条用户定义的规则时,http_access deny all规则将被应用,这样,http请求将被拒绝。 <br>
<br>
---- 那么如何在Linux中设置Squid的用户认证存取控制呢?Squid用access control list(缩写为acl)来管理规则。例如: <br>
<br>
acl aclname acltype string1 ... <br>
acl aclname acltype "file" <br>
<br>
---- aclname为用户定义规则的名字,acltype是可被Squid识别的类别(主要有src、dst、proxy_auth、port和time...),string为用户的设置,可以用"file"从外部文件调入设置。 <br>
<br>
---- 1.如果用户喜欢弹出输入用户名及密码的方式,首先需要安装认证程序。Squid的源文件包自带了几种认证程序,都在/tmp/squid-2.3.STABLE4/auth_modules目录下。 <br>
<br>
(1)$ cd /tmp/squid-2.3.STABLE4/auth_modules/NCSA <br>
$ make ncsa_auth <br>
(2)将生成的执行文件ncsa_auth拷贝到squid执行文件目录中。 <br>
$ cp ncsa_auth /usr/local/squid/bin <br>
(3)用htpasswd_plus生成供Squid利用的用户名和密码认证数据文件。 <br>
$htpasswd_plus -c /usr/local/squid/etc/passwd <br>
passwd的格式如下。 <br>
username1:SilykvIBT46C.:977867617:* <br>
username2:tV.8XcR8tgIqw:*:192.168.1.0 <br>
username3:密码:失效时间:可以登录的IP <br>
若为*,则说明任何项都能与其匹配。另外还可以增加其他更多的用户。 <br>
$ htpasswd_plus /usr/local/squid/etc/passwd newusername <br>
(4)修改squid.conf设置 <br>
authenticate program /usr/local/squid/bin/ncsa_auth <br>
/usr/local/squid/etc/passwd指定认证身份的内部程序。添加规则如下。 <br>
acl alloweduer proxy_auth username1 username2或者 <br>
acl alloweduser proxy_auth REQUIRED http access allow alloweduser <br>
<br>
---- 关键字REQUIRED意味着任何合法的用户都可以认证身份,在其他的acltype中也起同样的作用。 <br>
<br>
---- 2.用IP限制Squid proxy的使用,设置内容如下。 <br>
<br>
acl manager proto HTTP FTP … <br>
acl safeports port 80 21 443 563 70 210 1025-65535 … <br>
acl connect method CONNECT <br>
acl allowedIP src 202.120.x.x/255.255.255.224 <br>
acl denyIP src 202.96.x.x/255.255.255.224 <br>
acl allowedusers proxy_auth REQUIRED <br>
http_access deny !safeports <br>
#禁止来自!safeports的HTTP请求。 <br>
http_access deny denyIP <br>
http_access allow allowedIP <br>
http_access allow allowedusers <br>
<br>
---- 这样,除了拒绝及允许的IP,其他的请求都将通过输入用户名及密码来认证。如果用户不希望内部计算机访问某些网站(比如暴力或色情网站),可以通过如下设置屏蔽这些站点。 <br>
<br>
---- acl badip dst "/usr/local/squid/etc/somebadip" <br>
<br>
---- http_access deny badip <br>
<br>
---- 此处被拒绝的不是来源src的IP地址,而是目的dst的IP地址。在文件somebadip中存储如下格式的一批IP地址: <br>
<br>
---- 24.244.192.0/255.255.240.0 <br>
<br>
---- 61.128.0.0/255.252.0.0 <br>
<br>
---- 请大家特别注意http语句的顺序,正是通过不同的次序,使得我们可以进行灵活的配置,得到相应的服务。 <br>
<br>
---- 3.其他的一些设置如下所示,其中的大多数可以不做修改,只使用缺省值即可。 <br>
<br>
http port 3128 <br>
#HTTP协议的默认代理端口。 <br>
cache mem 42MB <br>
#用一块内存作为缓冲。 <br>
cache dir ufs /home/squid/cache 1024 16 256 <br>
<br>
---- #硬盘缓冲区的大小,大小为1GB,一级目录16个,二级目录256个。 <br>
<br>
---- cache access log /var/log/squid/access.log <br>
<br>
---- #该log文件是用来描述每次客户请求HTTP内容时高速缓存命中或未命中的项目,同时还描述提出请求的主机身份及它们所需要的内容,它是用SQMGRLOG等软件分析记费的基础。 <br>
<br>
---- cache log /var/log/squid/cache.log <br>
<br>
---- #用于描述当Squid守护进程启动时可以看到的内存容量、交换空间的大小、高速缓存目录的位置、所接受的连接类型以及接受连接的端口。 <br>
<br>
---- cache_store_log /var/log/squid/store.log <br>
<br>
---- #用于描述页面从高速缓存中被调入调出的情况。 <br>
<br>
pid filename /var/run/squid.pid <br>
#Squid进程的进程号。 <br>
dns nameservers 192.x.x.1 <br>
#定义域名解析服务器的地址。 <br>
cache_mgr squidadmin@your.domain <br>
#cache管理员的邮件箱地址。 <br>
reference age 1 week <br>
#设置缓冲区的更新周期。 <br>
maximum object size 4096 KB <br>
#设置允许被缓存的一次性最大请求。 <br>
cache_effective_user squidadmin squidadmin <br>
#以用户squidadmin的身份运行。 <br>
<br>
四、用SQMGRLOG实现计费 <br>
<br>
$cd /tmp <br>
$tar -zxvf sqmlog* <br>
$cd sqm* <br>
$./configure --enable-config=/usr/local/squid/ <br>
的选项主要有以下2项。 <br>
<br>
---- 1. 语言 <br>
<br>
---- 该语言不包含中文。事实上,它的语言部分是由English.h控制的,可以汉化后对其进行编译和安装。 <br>
<br>
---- --enable-language=English, Bulgarian_windows1251, Czech, Dutch, French, German, Hungarian, Indonesian, talian, apanese, Portuguese, Russian_Koi8, Russian_windows1251, Serbian, Spanish, Turkish default: English <br>
<br>
---- 2.安装目录 <br>
<br>
---- --enable-config=/usr/local/squid/etc <br>
<br>
---- #笔者将SQMGRLOG的配置文件sqmgrlog.conf 放在与Squid的配置文件相同的目录下。 <br>
<br>
--enable-prefix=/usr/local/squid/bin <br>
#最终编译生成的运行文件sqmgrlog的放置目录。 <br>
$make <br>
$make install <br>
最后,我们还要配置sqmgrlog.conf。 <br>
access log /usr/local/squid/logs/access.log <br>
#设置Squid的使用记录文件access.log的所在地。 <br>
output dir /home/squidadmin/public_html/squid-reports <br>
#生成report的输出目录。 <br>
password /usr/local/squid/etc/passwd <br>
#只生成此passwd文件中指明的用户report。 <br>
$./sqmgrlog <br>
<br>
---- 生成的report如图1和图2所示(只保留了前5个用户的数据),可以用浏览器进行浏览。
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -