Squid Web Cache Wiki

Squid Web Cache 文档

🔗 Linux 路由器 TPROXY Squid 集群

作者:Eliezer Croitoru

🔗 Linux 路由器和 WCCP

WCCP 代表 Web Cache Communication Protocol(Web 缓存通信协议)

WCCP 的优点是什么?WCCP 允许 Web 缓存集群,内置故障转移机制和半自动配置管理。

这让网络管理员可以安心,因为如果缓存集群中出现任何问题,客户端也不会受到影响。

WCCP 可以用于 http 和其他协议。许多网络管理员会将 Web 缓存基础设施部署在网络边缘,以获得带宽优势,

一些缓存架构是为了与边缘路由系统配合而构建的:Peerapp exinda F5-sol1880

如果您使用 Cisco,可以使用 WCCP,但在其他情况下,例如您使用 Linux 路由器作为边缘路由器服务器\BGP\路由反射器,情况就不同了。即使是领先的开源路由平台 Vyatta 也不支持 WCCP。

要在边缘部署 Web 缓存,需要一些路由和 iptables 规则。

🔗 目录

我将提供一个简单的场景以及一些基本的规则和基线。

在 Linux 路由中,我们有“main”和“local”两个路由表来处理所有流量。“Local”表用于物理连接的设备,“main”表用于所有其他目的地。

Linux 路由系统有一个非常好的功能,允许自定义路由表。其思想是,基于“ip rules”,我们可以通过“src”(源)“dst”(目标)“dev”(设备)和“fwmark”(防火墙标记)来定义特定数据包,以便按我们的意愿进行路由。

这可以是特定的上行链路/端口,或者在我们的例子中是缓存代理/集群。

与 Cisco 或 Juniper 的命令行界面相比,这可能会被一些人视为恼人或玩笑,但 Linux 在每秒数据包数 (pps) 方面限制非常低,因此非常强大。

我们将配置 Linux 路由器来标记所有 Web(80 端口)流量(出站和回程)。基于此标记,我们将使用路由规则将所有流量转发到一个特定的“cache”表。该 cache 表包含所有可用缓存代理的列表。表中的路由将使用轮询算法进行负载均衡。(稍后我可能会做一些更复杂的事情)

🔗 拓扑

网络中

🔗 对您的基本假设

您知道 TPROXY 和 Squid 的拦截模式之间的区别。

您了解基础/高级网络知识。

您有使用 iptables iproute2(ip) 的经验,并且对路由守护进程 (Quagga, Openbgpd, Bird) 有所了解。

🔗 Linux 边缘配置

由于我们将使用 iptables,您必须理解我们*绝不*会使用连接跟踪!!我们唯一使用的层是 IP/第 3 层过滤。路由器上执行此任务所需的唯一 iptables 模块是

ip_tables
iptable_mangle
iptable_filter
x_tables
xt_mark

您必须手动加载它们,以避免自动加载其他模块。

Ubuntu 上的要求:基本的 Ubuntu 服务器预装了 iptunnel iproute2 以及完成此任务所需的所有 iptables 模块。

#!/usr/bin/bash

echo "Loading modules.."
modprobe -a nf_tproxy_core xt_TPROXY xt_socket xt_mark ip_gre gre


LOCALIP="10.80.2.2"
CISCODIRIP="10.80.2.1"
CISCOIPID="192.168.10.127"

echo "changing routing and reverse path stuff.."
echo 0 > /proc/sys/net/ipv4/conf/lo/rp_filter
echo 1 > /proc/sys/net/ipv4/ip_forward

echo "creating tunnel..."
iptunnel add wccp0 mode gre remote $CISCOIPID local $LOCALIP dev eth1
ifconfig wccp0 127.0.1.1/32 up

echo "creating routing table for tproxy..."
ip rule add fwmark 1 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100

echo "creating iptables tproxy rules..."
iptables -A INPUT  -i lo -j ACCEPT
iptables -A INPUT  -p icmp -m icmp --icmp-type any -j ACCEPT
iptables -A FORWARD -i lo -j ACCEPT
iptables -A INPUT  -s $CISCODIRIP -p udp -m udp --dport 2048 -j ACCEPT
iptables -A INPUT -i wccp0 -j ACCEPT
iptables -A INPUT -p gre -j ACCEPT

iptables -t mangle -F
iptables -t mangle -A PREROUTING -d $LOCALIP -j ACCEPT
iptables -t mangle -N DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 1
iptables -t mangle -A DIVERT -j ACCEPT
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 3129

在 squid.conf 中添加以下行

#add change the src subnet to the list of clients subnets allowed.
acl clients src 10.80.0.0/16

http_access allow clients

http_port 127.0.0.1:3128
http_port 3129 tproxy

# replace 10.80.2.1 with your cisco router directly connected interface
wccp2_router 10.80.2.1
wccp_version 2
wccp2_rebuild_wait on
wccp2_forwarding_method 1
wccp2_return_method 1
wccp2_service standard 0
wccp2_service dynamic 80
wccp2_service dynamic 90
wccp2_service_info 80 protocol=tcp flags=src_ip_hash priority=240 ports=80
wccp2_service_info 90 protocol=tcp flags=dst_ip_hash,ports_source priority=240 ports=80

🔗 Cisco 设置

conf t

ip access-list extended wccp
 permit ip 10.80.3.0 0.0.0.255 any
ip access-list extended wccp_to_inside
 permit ip any 10.80.3.0 0.0.0.255
exit
ip wccp version 2
ip wccp web-cache
ip wccp 80 redirect-list wccp
ip wccp 90 redirect-list wccp_to_inside

interface FastEthernet0/0
 ip wccp 80 redirect out
 ip wccp 90 redirect in

interface FastEthernet0/1
 ip wccp redirect exclude in

🔗 构建 Squid

Squid 必须使用以下选项进行 ./configure 编译:

--enable-linux-netfilter --enable-wccpv2

⚠️ Disclaimer: Any example presented here is provided "as-is" with no support
or guarantee of suitability. If you have any further questions about
these examples please email the squid-users mailing list.

类别: ConfigExample

导航:网站搜索网站页面分类🔼 向上