天天看點

squid

# 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

-----------------------------------

# 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 能聯通

------------------------

反向代理

 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位址 ,通路的到的内容是目标伺服器的内容。

-------------------------------------------

通路控制

禁止響應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 baddomain1 dstdomain www.google.com

http_access deny clientnet1 baddomain1

禁止用戶端通過squid通路域名含有 163.com的主機

acl badurl1 url_regex -i 163.com

http_access deny badurl1

----------------------------------------------

認證

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服務

能彈出對話框 要求輸入使用者名和密碼

-----------------------------

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

# 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

repo        : installed

# 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/

繼續閱讀