免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4537 | 回复: 1
打印 上一主题 下一主题

[proxy] squid+mysql_auth+sarg代理初探 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-09 12:04 |只看该作者 |倒序浏览
实现功能:
1。提供Squid基本代理服务
2。通过mysql提供用户名密码的认证模式,用户管理通过php/web实现
3。实现代理日志分析统计功能,基于user和site的top排名

基本环境和所需软件:
1。redhat AS4、apache2.2、php5、mysql5
2。squid-2.6.STABLE9
3。mysql_auth-0.8 squid的mysql认证模块
4。sarg-2.2.3  squid分析软件

网络资源参考:
1。squid网站
http://www.squid-cache.org/
2。mysql_auth网站
http://people.arxnet.hu/airween/mysql_auth/
3。sarg网站
http://sarg.sourceforge.net/sarg.php
4。其他:
http://cha.homeip.net/blog/archives/2005/06/linux_nat_squid.html
http://www.chinaunix.net/jh/4/303886.html
http://www.squid-cache.org/Scripts/

步骤一、安装squid和mysql_auth

squid的安装比较简单
# tar zxvf squid-2.6.STABLE9.tar.gz
# cd squid-2.6.STABLE9
# ./configure --prefix=/data/app/squid
# make all
# make install

添加squid用户
# useradd squid

mysql_auth的安装也比较简单,要注意的就是关于目录和数据库的设定
# tar zxvf mysql_auth-0.8.tar.gz
# cd mysql_auth-0.8
可以通过修改Makefile和src/define.h来设定相关的安装文件路径、以及数据库登陆信息
# make
# make install
# mysql -u root -p < scripts/create_script
这里mysql_auth会自动给你新建一个squid/squid的本地数据库用户和相关的数据库和表;
安装完成之后的文件主要是mysql_auth和mysql_auth.conf,前者用于squid用户验证;


步骤二、squid.conf的配置

squid.conf的基本设置和说明如下,不再另表。

# 指定代理端口和绑定的IP
http_port xxx.xxx.xxx.xxx:3128

hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY

acl apache rep_header Server ^Apache
broken_vary_encoding allow apache

cache_mem 20 MB

# 设定cache目录及大小、结构纵深
cache_dir ufs /data/app/squid/var/cache 100 16 256

# 设定squid的日志,access访问日志、cache运行日志、cache_store命中日志
access_log /data/app/squid/var/logs/access.log squid
cache_log /data/app/squid/var/logs/cache.log
cache_store_log /data/app/squid/var/logs/store.log

# 指定HTTP验证方式和程序
auth_param basic program /data/app/squid/libexec/mysql_auth
# 指定squid使用多少个程序进程,默认5个,用户多可以适当扩充
auth_param basic children 5
# 指定验证域的提示字符串
auth_param basic realm welcome to edu-telecom Proxy Server
# 指定squid内在的缓存验证结果的时间数量
auth_param basic credentialsttl 1 hour

refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320

# 设定DNS server
dns_nameservers 202.103.24.68

# 默认设定一些控制列表对象
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8

# 默认定义Safe_ports的port对象
acl Safe_ports port 80         # http
acl Safe_ports port 21         # ftp
acl Safe_ports port 443                # https
acl Safe_ports port 70         # gopher
acl Safe_ports port 210                # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280                # http-mgmt
acl Safe_ports port 488                # gss-http
acl Safe_ports port 591                # filemaker
acl Safe_ports port 777                # multiling http

# 限制一个用户最多只来自2个IP
acl xz1 max_user_ip 2
# 重点:定义normal控制对象,设定匹配用户名认证模式,其中REQUIRED表示作为特殊值匹配任意用户名,如不能查明用户名此ACL不匹配
acl normal proxy_auth REQUIRED

http_access allow manager localhost
http_access deny manager

# 阻止定义的Safe_ports外的其他端口的访问
http_access deny !Safe_ports

# 允许符合normal控制对象的用户访问,及通过用户认证
http_access allow normal
# 拒绝其他的访问
http_access deny all

http_reply_access allow all
icp_access allow all

# 设定squid的运行用户和组
cache_effective_user squid
cache_effective_group squid

# 设定squid的主机名
visible_hostname localhost

coredump_dir /data/app/squid/var/cache

squid.conf配置完成之后启动squid
# /data/app/squid/bin/squid
有什么情况可以通过/var/log/message或者cache.log来分析

步骤三、配置sarg日志分析

sarg非常短小精悍,安装和使用也比较简单。
# tar zxvf sarg-2.2.3.1.tar.gz
# cd sarg-2.2.3.1
# ./configure --enable-htmldir=/data/webapp
# make
# make install

sarg默认被安装到/usr/bin/sarg,其系统目录在/usr/local/sarg;
sarg是作为一个定期的squid日志分析软件,可以用sarg -d来定义分析时间范围,更多选项可以查看sarg -h或者查看sarg.conf的说明,一般来讲结合手工的日志轮询脚本对squid提供每日的分析报表是非常合适的;
sarg会生成html的分析报告,我们通过web访问查看即可。

至此,基本完成,结合squid的更多丰富控制功能可以提供更为强大的服务。

论坛徽章:
0
2 [报告]
发表于 2007-07-19 08:15 |只看该作者
用户管理通过php/web实现,这个功能具体怎么实现?用户可以自己去web上修改自己的密码吗?还有可不可以暂时的禁止某个用户,在需要的时候再开放这个用户?

[ 本帖最后由 zhangshoug 于 2007-7-19 08:17 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP