Chinaunix首页 | 论坛 | 博客
  • 博客访问: 541240
  • 博文数量: 81
  • 博客积分: 5015
  • 博客等级: 大校
  • 技术积分: 866
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-25 09:08
个人简介

www.cloud86.cn

文章分类

全部博文(81)

文章存档

2017年(2)

2014年(1)

2011年(1)

2007年(5)

2006年(31)

2005年(41)

我的朋友

分类: 系统运维

2007-05-07 09:22:51

Squid+iptables+marg配置总结

 

 

从可以从squid主站下载:

 

 

 

#./configure --prefix=/usr/local/rickycai/squid

--enable-gnuregex

--enable-async-io=80 --enable-icmp --enable-kill-parent-hack

--enable-snmp --disable-ident-lookups --enable-cahce-digests

--enable-arp-acl --enable-err-language="Simplify_Chinese"

--enable-default-err-languages="Simplify_Chinese"  --enable-poll

--enable-linux-netfilter --enable-underscore                            

 

注:

--enable-gnuregex   加入模式匹配

--enable-async-io=80   该选项导致编译过程链接到你系统中的P 线程库。aufs 存储模块是squid 中唯一需要使用线程的部分

 

 

如果有上述选项等同于:--with-aufs-threads=N_THREADS

                      --with-pthreads

                      --enable-storeio=ufs,aufs

                      --with-pthreads

--enable-icmp  :加入icmp支持

--enable-kill-parent-hack :关掉suqid的时候,连同父进程一起关掉

--enable-snmp   此选项可以让MRTG使用SNMP协议对服务器的流量状态进行监测,因此必须选择此项,使Squid支持SNMP接口

--disable-ident-lookups  :防止系统使用RFC931规定的身份识别方法。

--enable-cahce-digests  :加快请求时,检索缓存内容的速度

--enable-arp-acl  :可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗。

--enable-poll  :应启用Poll()函数而不是select()函数,通常而言poll(轮询)select要好

--enable-linux-netfilter :可以支持透明代理

--enable-underscore  :允许解析的URL中出现下划先,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址。

 

 

 

[root@mail squid-2.6.STABLE9]# cd /usr/local/rickycai/squid/etc

[root@mail etc]# vi squid.conf

 

//注意:这个版本透明代理是如下

 

 http_port 10.10.100.25:3128  transparent  #代理端口

   icp_port 3130   #此端口为Squid从邻居缓存服务器发送和接收ICP查询,禁止该选项为0

 

#禁止缓存

 

   hierarchy_stoplist cgi-bin ?

   hierarchy_stoplist -i ^https:\\ ?

   acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi

   acl denyssl urlpath_regex -i ^https:\\

   no_cache deny QUERY   

   #no_cache 访问列表来指示squid,它不必存储某些响应(在磁盘或内存里)。

   #该列表典型的与dst,dstdomain,url_regex ACL 结合使用

   no_cache deny denyssl

   #上面几个就是说遇到URL中有包含cgi-bin和以https:\\开头的都不要缓存,

   #还有aspcgiphp等动态脚本也不要缓存,

   #因为这些脚本通常都是动态更新的,这样数据不同步。

   #还有https://开通的不缓存是因为一般我们进行电子商务交易,

   #例如银行付款等都是采用这个的,如果把信用卡号什么缓存那不是很危险。

 

#定义cache大小的选项

cache_mem 512 MB   #额外使用内存量,可根据你的系统内存在设定,一般为实际内存的1/3

cache_swap_low 90    #最低缓存百分比

cache_swap_high 95     ##最高缓存百分比,就是上面那个额外内存的使用百分比,如果超过那个就清楚前面的

maximum_object_size 4096 KB  #单个文件最大缓存大小,超过这个大小将不缓存在磁盘里面

maximum_object_size_in_memory 8 KB  #在内存中单个文件最大缓存大小,超过这个大小将不缓存到内存中

 

 

 

#IP存在缓存区的大小,这样可以加快解析DNS速度

ipcache_size 1024

ipcache_low 90

ipcache_high 95

fqdncache_size 1024

 

#; ; <目录所在>; 大小>; ; ;

#7000M

cache_dir ufs /usr/local/rickycai/squid/var/cache 7000 16 256

 

#日志文件

access_log /usr/local/rickycai/squid/var/logs/access.log squid

cache_log /usr/local/rickycai/squid/var/logs/cache.log 

 

cache_store_log /usr/local/rickycai/squid/var/logs/store.log

 

pid_filename /usr/local/rickycai/squid/var/logs/squid.pid

 

#用代理登陆匿名ftp服务选项

#  TAG: ftp_user

ftp_user Squid@    #用户名

ftp_passive on     #被动模式

 

#  TAG: refresh_pattern    Cache更新时间设置

#; ; <最小时间>; <百分比>; <最大时间>;

refresh_pattern ^ftp:           1440    20%     10080

refresh_pattern ^gopher:        1440    0%      1440

refresh_pattern .               0       20%     4320

 

 

# TIMEOUTS (超时)

# -----------------------------------------------------------------------------

#连接到其他机器的最大尝试时间

connect_timeout 1 minute

 

#连接到上层代理的超时时间

#peer_connect_timeout 30 seconds

 

#返回超时

request_timeout 2 minutes

 

#持续连接时间

persistent_request_timeout 1 minute

 

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

acl CONNECT method CONNECT

 

acl inside src 10.10.100.0/24

acl inside src 10.10.101.0/24

acl inside src 10.10.102.0/24

 

 

http_access allow manager localhost

http_access deny manager

 

# Deny requests to unknown ports

http_access deny !Safe_ports

# Deny CONNECT to other than SSL ports

http_access deny CONNECT !SSL_ports

http_access allow inside

 

 

另外如果想通过MAC进行控制

#acl localmac arp "/usr/local/squid/localmac"  #mac地址文件

#http_access allow localmac  #允许localmac里面有登记的mac地址通过

 

# ADMINISTRATIVE PARAMETERS(管理参数)

# -----------------------------------------------------------------------------

cache_mgr

cache_effective_user squid

cache_effective_group  squid

 

visible_hostname MesicProxyServer  #代理服务器名称

 

 

# MISCELLANEOUS(杂项)

# -----------------------------------------------------------------------------

 

#  TAG: logfile_rotate

#squid会定期的将日志文件更名并打包。

#比如正在使用的日志文件为access.log,squid会将其更名并打包为 access.log.1.gz

#过了一定时间后,squid又会将access.log.1.gz更名为access.log.2.gz

#并将当前的日志文件更名并打包为access.log.1.gz,以此循环。

#logfile_rotate指定的数字即为打包并备份的文件的数量,当达到这一数目时,

#squid将删除最老的备份文件。默认值为1 0。如果想手动来进行这些操作,

#可以用logfile_rotate 0来取消自动操作。

logfile_rotate 4

 

#  TAG: forwarded_for        on|off

#关闭此项将在访问某些论坛时显示的IPunknown

#如果打开则显示的是你client的内网IP

 

forwarded_for off

 

/***********************************************************************

 

#图标文件目录

# icon_directory /usr/local/squid/share/icons

 

 

#错误提示文件目录

# error_directory /usr/local/squid/share/errors/Simplify_Chinese

 

 

 

#  TAG: snmp_port

#        Squid can now serve statistics and status information via SNMP.

#        By default it listens to port 3401 on the machine. If you don't

#        wish to use SNMP, set this to "0".

#

#Default:

# snmp_port 3401

 

#  TAG: snmp_access

#        Allowing or denying access to the SNMP port.

#

#        All access to the agent is denied by default.

#        usage:

#

#        snmp_access allow|deny [!]aclname ...

#

#Example:

# snmp_access allow snmppublic localhost

# snmp_access deny all

#

#Default:

# snmp_access deny all

 

*****************************************************************************/

 

 

 

 

# DELAY POOL PARAMETERS (all require DELAY_POOLS compilation option)(延时池参数)

# -----------------------------------------------------------------------------

 

 

#  TAG: coredump_dir

#squid突然挂掉的时候,或者突然出现什么故障的时候,将squid在内存中的资料写到硬盘中

coredump_dir /usr/local/rickycai/squid/var/cache

 

 

 

 

echo "1" >; /proc/sys/net/ipv4/ip_forward   #设置转发

 

[root@mail squid]# mkdir sh

[root@mail squid]# cd sh

[root@mail sh]# cat firewall.sh

 

#!/bin/sh

modprobe ip_tables

modprobe ip_nat_ftp

modprobe ip_conntrack

modprobe ip_conntrack_ftp

iptables -F -t nat

iptables -t nat -A POSTROUTING -j MASQUERADE

iptables -t nat -A PREROUTING -i eth1 -p tcp -s 10.10.100.0/24 --dport 80 -j REDIRECT --to-ports 3128

iptables -t nat -A PREROUTING -i eth1 -p tcp -s 10.10.101.0/24 --dport 80 -j REDIRECT --to-ports 3128

iptables -t nat -A PREROUTING -i eth1 -p tcp -s 10.10.102.0/24 --dport 80 -j REDIRECT --to-ports 3128

 

 

[root@mail sh]# ./firewall.sh

[root@mail sh]# cd /usr/local/rickycai/squid/var

[root@mail var]# mkdir cache

[root@mail var]# cd logs

[root@mail logs]# touch access.log cache.log store.log

[root@mail logs]#chmod 755 access.log cache.log store.log

[root@mail logs]#cd ..

[root@mail var]# chown -R squid:squid ./

 

#初始化cache

[root@mail var]# /usr/local/rickycai/squid/sbin/squid -z

 

#启动squid

[root@mail var]# /usr/local/rickycai/squid/bin/RunCache &

[root@mail var]# su squid -c "/usr/local/rickycai/squid/bin/RunCache &"

 

#关闭squid

 

[root@mail var]# /usr/local/rickycai/squid/sbin/squid -k sthudown

 

#重新读取配置文件

[root@mail var]# /usr/local/rickycai/squid/sbin/squid -k reconfigure

 

安装日志分析文件:

 

 

[root@mail workspace]# tar zxvf ./software/sarg-2.2.2.tar.gz

[root@mail workspace]# cd sarg-2.2.2

[root@mail sarg-2.2.2]# ./configure --prefix=/usr/local/rickycai/sarg

 

注意:这个版本因为prefix指定无效,所以需要./configure之后在Makefile文件里面更改几个目录

SYSCONFDIR      = /usr/local/rickycai/sarg

ISYSCONFDIR     = -DSYSCONFDIR=\"/usr/local/rickycai/sarg\"

 

[root@mail sarg-2.2.2]# ./configure --enable-bindir=/usr/local/rickycai/sarg/bin --enable-sysconfdir=/usr/local/rickycai/sarg/etc --enable-htmldir=/usr/

local/rickycai/sarg/www --enable-mandir=/usr/local/rickycai/man/man1

 

 

 

 

[root@mail sarg-2.2.2]#make

[root@mail sarg-2.2.2]#make install

[root@mail sarg-2.2.2]cd [root@mail sarg]# cd /usr/local/rickycai/sarg/etc/

[root@mail etc]#vi sarg.conf

修改:

language English   //暂时还没中文版提供

access_log /usr/local/rickycai/squid/var/logs/access.log   #squid日志文件存放位置

title "Squid User Access Reports"

temporary_dir /tmp   #临时目录

output_dir /usr/local/rickycai/apache/htdocs/squidreport/  #生成后的html存放到那里,设置到你的网站目录下,以便浏览

overwrite_report no  #是否覆盖报告,当那个日期的报告已经存在时是否覆盖掉

mail_utility mail

topsites_num 100

exclude_codes /usr/local/rickycai/sarg/etc/exclude_codes

max_elapsed 28800000

charset GB2312  #字符集

[root@mail etc]# cd /usr/local/rickycai/apache/htdocs/

[root@mail htdocs]# mkdir squidreport

[root@mail htdocs]# chmod 755 squidreport

[root@mail htdocs]# chown -R vmail:vmail ./squidreport

[root@mail htdocs]# cd /usr/local/rickycai/sarg/bin/sarg/    

[root@mail sarg]# ./sarg

报告生成数据

所以访问就可以看到报告内容。如果需要限制访问用户,可以做目录限制认证

阅读(1986) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~