2、安装sarg
安装httpd服务yum install httpd(我这里采用了yum安装,也可以源码编译看个人爱好了)
- wget http://fossies.org/unix/privat/sarg-2.3.2.tar.gz
- tar xvf sarg-2.3.2.tar.gz
- cd sarg-2.3.2
- chmod +x configure
- ./configure --perfix=/usr/local/sarg
- make && install
注意:此时可能提示错误 修改方法为 编辑 util.c 186 行 LLONG改为 LONG
配置文件
- #######################sarg.conf################################
- access_log /data/squid/logs/cache_access.log
- graphs yes
- title "Squid User Access Reports"
- font_face Tahoma,Verdana,Arial
- header_color darkblue
- header_bgcolor blanchedalmond
- font_size 10px
- header_font_size 11px
- title_font_size 13px
- background_color white
- text_color #000000
- text_bgcolor lavender
- title_color green
- logo_image none
- logo_text ""
- logo_text_color #000000
- image_size 80 45
- background_image none
- password none
- temporary_dir /tmp
- output_dir /var/www/html
- anonymous_output_files no
- charset UTF-8
- #######################sarg.conf_END#################################
每天生成一次报表(时间根据自己需求定)
- echo "* 1 * * * root /usr/local/sarg/bin/sarg" >>/etc/crontab
3、透明代理 iptables 设置
- #!/bin/bash
- /sbin/iptables -F
- /sbin/iptables -Z
- /sbin/iptables -X
- /sbin/iptables -t nat -F
- /sbin/iptables -t nat -Z
- /sbin/iptables -t nat -X
- /sbin/iptables -t filter -F
- /sbin/iptables -t mangle -X
- /sbin/iptables -P INPUT DROP
- /sbin/iptables -P OUTPUT ACCEPT
- /sbin/iptables -P FORWARD ACCEPT
- /sbin/iptables -t nat -P PREROUTING ACCEPT
- /sbin/iptables -t nat -P POSTROUTING ACCEPT
- /sbin/iptables -t nat -P OUTPUT ACCEPT
- #启动转发功能
- echo "1" > /proc/sys/net/ipv4/ip_forward
- #打开本机回路
- /sbin/iptables -A INPUT -i lo -j ACCEPT
- /sbin/iptables -A OUTPUT -o lo -j ACCEPT
- #打开内网连接
- /sbin/iptables -A INPUT -i eth1 -j ACCEPT
- #允许已建立的连接
- /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- #允许ping
- /sbin/iptables -A INPUT -p icmp -j ACCEPT
- #允许22,80端口
- /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- #192.168.1源地址转换
- /sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to-source 192.168.1.22
- #将eth1去往80端口的数据包重定向去本机的3128端口,也就是SQUID处理
- /sbin/iptables -t nat -A PREROUTING -i eth1 -s 192.168.0.0/24 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
- #SQUID允许的客户
- #/sbin/iptables -A INPUT -s 192.168.0.0/24 -p tcp --dport 3128 -j ACCEPT
- #/sbin/iptables -A OUTPUT -d 192.168.0.0/24 -p tcp --sport 3128 -j ACCEPT
- #现在过滤不是做在output与input里,因为数据是从一个网卡流动到另一个网卡,得在forward里
- /sbin/iptables -A FORWARD -s 192.168.0.0/24 -d 0/0 -p tcp -j ACCEPT
- /sbin/iptables -A FORWARD -s 0/0 -d 192.168.0.0/24 -p tcp -j ACCEPT
- 备注:
- squidclient使用简介:
- 查看帮助:./squidclient -h 192.168.0.1 -p 3128 mgr:
- /usr/local/squid/squidclient
- squidclient -h 192.168.0.1 -p 3128 mgr:client_list //查看客户端列表
- squidclient -h 192.168.0.1 -p 3128 mgr:objects //取得已缓存的列表
- squidclient -h 192.168.0.1 -p 3128 mgr:info //取得运行状态
