# tar jxvf squid-3.0.STABLE25.tar.bz2 -C /usr/local/src
# cd /usr/local/src/squid-3.0.STABLE25/
# ./configure --help //查看可以编译的选项
# ./configure --prefix=/usr/local/squid \
> --enable-arp-acl \
> --enable-linux-netfilter \
> --enable-pthreads \
> --enable-storeio=ufs,aufs,null \
> --enable-auth="basic" \
> --enable-basic-auth-helpers="NCSA"
# make
# make install
# cd /usr/local/squid/etc
# cp -p squid.conf squid.conf.bak
# vim squid.conf
875 http_port 192.168.9.8:3128
2981 cache_effective_user nobody
1744 cache_dir ufs /usr/local/squid/var/cache 200 16 256
1572 cache_mem 40 MB
1800 cache_swap_low 90
1801 cache_swap_high 95
1907 access_log /usr/local/squid/var/logs/access.log squid
1933 cache_store_log /usr/local/squid/var/logs/store.log
630 http_access allow all
# /usr/local/squid/sbin/squid -z
# cd /usr/local/squid
# chmod 777 var
# cd logs
# chmod 777 logs
# /usr/local/squid/sbin/squid -z
-----------------------------------
# vim /etc/rc.local //随系统启动启动服务
添加
/usr/local/squid/sbin/squid -D &
------------------
# vim /etc/profile //设置命令路径
在最后一行添加
export PATH=$PATH:/usr/local/squid/sbin/
# source /etc/profile
# squid
------------------
透明代理
# vim /usr/local/squid/etc/squid.conf
876 http_port 192.168.9.8:3128 transparent
使用iptables实现端口重定向:
# iptables -t nat -A PREROUTING -s 192.168.9.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
# squid -k reconfigure //重新读取配置文件
在客户端 网络连接-本地连接-属性-internet协议(tcp/ip)-属性-默认网关-192.68.9.8
打开ie浏览器
http://172.16.10.20 能访问到网页的内容 代理服务器跟172.16.10.20 能联通
------------------------
反向代理
# vim /usr/local/squid/etc/squid.conf
876 http_port 80 vhost vport //如果代理服务器上有网页服务器,先关掉
877 cache_peer 172.16.10.20 parent 80 0 no-query originserver name=www
//172.16.10.20 是目标服务器的ip地址
# iptables -t nat -F
[2]+ Done squid -D
# iptables -t nat -L
# service iptables save
Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
# service iptables stop
# squid -D &
在客户端
打开ie 浏览器
http://192.168.9.8 写的是代理服务器的ip地址 ,访问的到的内容是目标服务器的内容。
-------------------------------------------
访问控制
# cd /usr/local/squid/etc
# vim squid.conf
禁止响应ip地址为192.168.100.0/24 子网所有客户端在周一到周五的9:00到18:00的请求
acl clientnet1 src 192.168.100.0/24
acl worktime time MTWHF 9:00-18:00
http_access deny clientnet1 worktime
禁止ip地址为192.168.90.10的客户端下载 *.mp3 *.zip *.rar类型的文件
acl client1 src 192.168.90.10
acl badfile urlpath_regex -i \.mp3$ \.zip$ \.rar$
http_access deny client1 badfile
不允许ip地址为192.168.100.0/24 子网所有客户端访问www.google.com
acl clientnet1 src 192.168.100.0/24
acl baddomain1 dstdomain www.google.com
http_access deny clientnet1 baddomain1
禁止客户端通过squid访问域名含有 163.com的主机
acl badurl1 url_regex -i 163.com
http_access deny badurl1
----------------------------------------------
认证
# cd /usr/local/squid/etc
# vim squid.conf
89 auth_param basic program /usr/local/squid/libexec/ncsa_auth /usr/local/squid/etc/password
98 auth_param basic children 5
116 auth_param basic realm Squid proxy-caching web server
631 acl normal proxy_auth REQUIRED
634 http_access allow normal
# htpasswd -cm /usr/local/squid/etc/password su1
New password:
Re-type new password:
Adding password for user su1
# ps -e |grep squid //杀死squid进程
27223 ? 00:00:00 squid
27225 ? 00:00:01 squid
# kill -9 27223
# kill -9 27225
# squid -D & //启动squid服务
在客户端
在客户端 网络连接-本地连接-属性-internet协议(tcp/ip)-属性-默认网关-192.68.9.8
打开ie浏览器
http://172.16.10.20 能访问到网页的内容 代理服务器跟172.16.10.20 能联通
能弹出对话框 要求输入用户名和密码
-----------------------------
sarg
# tar zxvf sarg-2.3.1.tar.gz -C /usr/local/src
# cd /usr/local/src/sarg-2.3.1/
# ./configure --prefix=/usr/local/sarg
# make
# make install
# cd /usr/local/sarg/etc
# vim sarg.conf
7 access_log /usr/local/squid/var/logs/access.log
25 title "Squid User Access Reports"
120 output_dir /var/www/html/squid
# mkdir /var/www/html/squid
# /usr/local/sarg/bin/sarg -o /var/www/html/squid/daily -d $(date +%d/%m/%Y) //生成报告
perl-GD
squid-graph
# rpm -ivh perl-GD-2.41-2.el5.rf.i386.rpm
warning: perl-GD-2.41-2.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
error: Failed dependencies:
libgd.so.2 is needed by perl-GD-2.41-2.el5.rf.i386
# yum provides "*/libgd.so.2"
Loaded plugins: security
gd-2.0.33-9.4.el5_4.2.i386 : A graphics library for quick creation of PNG or
: JPEG p_w_picpaths
Repo : base
Matched from:
Filename : /usr/lib/libgd.so.2
gd-2.0.33-9.4.el5_4.2.i386 : A graphics library for quick creation of PNG or
: JPEG p_w_picpaths
Repo : installed
Matched from:
Filename : /usr/lib/libgd.so.2
# rpm -ivh perl-GD-2.41-2.el5.rf.i386.rpm
# tar zxvf squid-graph-3.2.tar.gz -C /usr/local/src
# cd /usr/local/src/squid-graph/
# mkdir /var/www/html/hit
# /usr/local/src/squid-graph/squid-graph --output-dir=/var/www/html/hit < /usr/local/squid/var/logs/access.log
打开ie 浏览器
http://192.168.9.8/squid/daily/