Chinaunix首页 | 论坛 | 博客
  • 博客访问: 241665
  • 博文数量: 62
  • 博客积分: 2540
  • 博客等级: 少校
  • 技术积分: 607
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-05 10:47
文章分类

全部博文(62)

文章存档

2015年(3)

2013年(9)

2010年(10)

2009年(7)

2008年(7)

2007年(22)

2006年(3)

2005年(1)

我的朋友

分类: LINUX

2007-02-21 21:58:05

酷!學園 精華區 - [原創]實作 Cisco + squid WCCP v2 Transparent Proxy server

adersun
- 星期五 一月 30, 2004 5:11 pm
文章主題: [原創]實作 Cisco + squid WCCP v2 Transparent Proxy server
實作 Cisco + squid WCCP v2 Transparent Proxy server

作者 : Adersun
版權宣言 : 可任意轉載, 轉載時請務必著明作者及出處

前言:

WCCP這種協定主要的功能是提供路由器(Router)與快取伺服器(Cache Server)之間的溝通, 這種溝通的結果是希望能達成一種機制, 將user所要求的需求經過路由器時, 路由器將此需求及時的重導(Redirect) 到快取伺服器上, 如果快取伺服器儲存了符合user所要求的資料, 則快取伺服器便直接將該份符合的資料回應給user.
如需了解 WCCP, 請參閱 :


我現在的環境是在 Asia 各個分公司都設立 transparent proxy 節省頻寬, 但我們又不是每個分公司都有 IT 人員, 所以每次出問題就要到處飛來飛去, 所以我想採用 squid + WCCP v2 來作, 這樣就算 proxy server 當掉, 網路都還是可以直接透過 router 進出而不至於整個 site 停擺等 IT 來處理.

這次寫一下實作 Cisco + squid WCCP v2 Transparent Proxy server, 因為要用 WCCP ver 2, 而 WCCP 是利用 GRE 通道來建立 , 所以需要 Cisco IOS 12.x 以上, 及 squid ver 2.5 以上, Linux kernel 需要在 2.4.x.

以下為我的環境 :

Cisco 3640 router --> IOS: 12.2
RedHat 8 + kernel 2.4.18
squid 2.5.PRE7

開始實作 :

下載 Linux kernel 2.4.18 及 kernel patch 重新編譯使其支援 GRE 及 WCCP ver2
# cd /usr/src
# wget
# wget http://squid.visolve.com/developments/ip_wccp-2_4_18.patch
# tar zxvf linux-2.4.18.tar.gz
# mv linux linux-2.4.18
# ln -s linux-2.4.18 linux
# cd linux-2.4.18
# patch -p1 < ../ip_wccp-2_4_18.patch
# make menuconfig

重新編譯時請將 :
CONFIG_NET_IPGRE=y
CONFIG_NET_IPGRE_BROADCAST=y
CONFIG_NET_SCH_GRED=y
CONFIG_NET_SCH_INGRESS=y
CONFIG_NET_IPWCCP=y
其他選項起配合你的實際需要去編.

# make dep
# make clean
# make bzImage
# make modules
# make modules_install
# cp /usr/src/linux-2.4.18/System-map /boot/System-map-2.4.18
# rm -f /boot/System-map
# ln -s /boot/System-map-2.4.18 /boot/System-map
# cp /usr/src/linux-2.4.18/arch/i386/boot/bzImage /boot/vmlinuz-2.4.18
# mkinitrd /boot/initrd-2.4.18.img 2.4.18

編輯 /etc/grub.conf
title Linux recompiled (2.4.18 For Squid WCCP v2)
root (hd0,0) <-- 請按照你的實際狀況來寫
kernel /boot/vmlinuz-2.4.18 ro root=/dev/hda1<-- 請按照你的實際狀況來寫
initrd /boot/initrd-2.4.18.img <-- 請按照你的實際狀況來寫

reboot 你的 Linux 然後以你剛剛編譯完的 kernel 開機.

下載及安裝 squid-2.5.PRE7 及 WCCP v2 patch for squid :
# cd /usr/src
# wget
# wget http://squid.visolve.com/developments/wccpv2.patch
# tar -xvzf squid-2.5.PRE7
# cd squid-2.5.PRE7
# patch -p1 < ../wccpv2.patch
# ./configure --enable-wccpv2
# make
# make install

到這裡你的系統已經有能力支援 squid 跑 WCCP v2 了, 現在要修改 squid.conf 使 squid 成為 WCCP v2 transparent proxy server :

# vi /usr/local/squid/etc/squid.conf

httpd_accel_with_proxy on
httpd_accel_port 80
httpd_accel_host virtual
httpd_accel_uses_host_header on
http_port 3128
no_cache deny QUERY
no_cache deny spc_nocache
emulate_httpd_log on
http_access allow all
http_access allow localhost
icp_access allow all
wccp2_version 2
wccp2_routr 123.123.123.1 <-- 此為你 cisco router
其他關於 squid 的設定請參閱其他 squid 的文章, 在此不做闡述.
# squid -z <-- 製造 squid 要用的快取目錄

接下來我們要告訴 Linux kernel 在開機時建立 GRE 以及啟動 squid :
# vi /etc/rc.d/rc.local
加入以下幾行 :

#Start packege forwarding....
echo 1 > /proc/sys/net/ipv4/ip_forward
#Start create gre tunnel....
modprobe ip_gre
iptunnel add gre1 mode gre remote 123.123.123.1 local 123.123.123.123 dev eth0
# 123.123.123.1 為你 Cisco router 接至 proxy server 的 ethernet interface, 123.123.123.123 為你 eth0 的 IP
ifconfig gre1 192.168.123.1 up
# 要給 GRE tunnel 一個 IP, 根據我的情況使用虛擬 IP 一樣可以使用
#Start squid proxy cache....
/usr/sbin/squid &

設定 Cisco router 開啟 WCCP v2 :

conf t
ip wccp enable
ip wccp version 2
ip wccp web-cache
Int (你想要 cache 的output interface)
ip wccp web-cache redirect out

大功告成, 測試是否成功 :

1. 看看 /var/log/squid/access.log 是否開始紀錄web requests passing through
2. 或是在 Cisco 上用 debug ip wccp event 指令, 是否有 'I see you/here I am'

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

huzi19862010-03-25 16:35:24

你的WCCP +SQUID 正常运行一年多了?我现在碰到问题 想请教你。我的QQ是178645003 谢谢了