squid常规代理实现内网的共享上网

来源:互联网 发布:淘宝毛衣外套 编辑:程序博客网 时间:2024/04/30 18:17

一、Squid的简单介绍


通过squid代理服务器实现内网用户共享上网,配置squid的缓存和基本的访问控制加速和限制web服务的访问。

对于Web用户来说,Squid是一个高性能的代理缓存服务器,可以加快内部网浏览Internet的速度,提高客户机的访问命中率。Squid不仅支持HTTP协议,还支持ftp、gopher、SSL和WAIS等协议。和一般的代理缓存软件不同,Squid用一个单独的、非模块化的、I/O驱动的进程来处理所有的客户端请求。
Squid将数据元缓存在内存中,同时也缓存DNS查寻的结果,除此之外,它还支持非模块化的DNS查询,对失败的请求进行消极缓存。Squid支持SSL,支持访问控制 。由于使用了ICP,Squid能够实现重叠的代理阵列,从而最大限度的节约带宽。
Squid由一个主要的服务程序Squid,一个DNS查询程序dnsserver,几个重写请求和执行认证的程序,以及几个管理工具组成。当Squid启动以后,它可以派生出指定数目的dnsserver进程,而每一个dnsserver进程都可以执行单独的DNS查询,这样一来就大大减少了服务器等待DNS查询的时间。
Squid的另一个优越性在于它使用访问控制清单(ACL)和访问权限清单(ARL)。访问控制清单和访问权限清单通过阻止特定的网络连接来减少潜在的Internet非法连接,可以使用这些清单来确保内部网的主机无法访问有威胁的或不适宜的站点。
Squid对硬件的要求是内存一定要大,不应小于128M,硬盘转速越快越好,最好使用服务器专用SCSI硬盘,处理器要求不高,400MH以上既可。

二、squid代理的实现原理

1、 客户端向代理服务器squid提出访问internet的请求

2、代理服务器接受请求后,首先与访问控制列表中的访问规则相对照,如果满足规则,那就在缓存中查找是否存在需要的信息,若缓存中有所需要的信息,则直接返还给客户端,如果不存在,代理服务器就会代替客户端向互联网发出访问请求。

3、互联网上的主机会将代理服务器请求的信息回馈给代理服务器,同时,代理服务器会将获得的数据存在自己的缓存中,然后再将互联网回应的信息传给客户端。

4、其他客户端向代理服务器squid提出访问internet的相同请求时,代理服务器首先与访问控制列表中的访问规则相对照,如果满足规则,则将缓存中的数据传给客户端


简单的用个逻辑图介绍一下



(1)如果缓存中有客户端请求的数据则走1234路线;

(2)如果缓存中没有请求的数据则走125634路线。


三、Squid的编译安装

[root@server softs]# tar xf squid-3.1.14.tar.gz -C /usr/src/

[root@server softs]# cd /usr/src/squid-3.1.14/






squid相关目录和文件



[root@server squid-3.1.14]# cp /usr/local/squid/etc/squid.conf.d
ocumented /usr/local/squid/etc/squid.conf
cp: overwrite `/usr/local/squid/etc/squid.conf'? y

[root@server squid-3.1.14]# ln -s /usr/local/squid/sbin/squid /sbin/squid
[root@server squid-3.1.14]# ln -s /usr/local/squid/etc/squid.conf /etc/squid.conf

[root@server etc]# chmod -R o+w /usr/local/squid/var/logs/
[root@server etc]# chmod -R o+w /usr/local/squid/var/cache/

[root@server etc]# squid  -z
2014/02/10 16:11:01| Creating Swap Directories
2014/02/10 16:11:01| /usr/local/squid/var/cache exists
2014/02/10 16:11:01| Making directories in /usr/local/squid/var/cache/00
2014/02/10 16:11:01| Making directories in /usr/local/squid/var/cache/01
2014/02/10 16:11:01| Making directories in /usr/local/squid/var/cache/02
2014/02/10 16:11:01| Making directories in /usr/local/squid/var/cache/03
2014/02/10 16:11:01| Making directories in /usr/local/squid/var/cache/04
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/05
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/06
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/07
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/08
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/09
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0A
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0B
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0C
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0D
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0E
2014/02/10 16:11:02| Making directories in /usr/local/squid/var/cache/0F
[root@server etc]# 

[root@server etc]# squid -k parse
2014/02/10 16:12:05| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)
2014/02/10 16:12:05| Processing: acl mynet  src  192.168.0.0/24
2014/02/10 16:12:05| Processing: http_access allow mynet
2014/02/10 16:12:05| Processing: http_port 3128
2014/02/10 16:12:05| Processing: cache_mem 256 MB
2014/02/10 16:12:05| Processing: acl manager proto cache_object
2014/02/10 16:12:05| Processing: acl localhost src 127.0.0.1/32 ::1
2014/02/10 16:12:05| Processing: acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
2014/02/10 16:12:05| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2014/02/10 16:12:05| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
2014/02/10 16:12:05| Processing: acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
2014/02/10 16:12:05| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2014/02/10 16:12:05| aclIpParseIpData: IPv6 has not been enabled.
2014/02/10 16:12:05| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2014/02/10 16:12:05| aclIpParseIpData: IPv6 has not been enabled.
2014/02/10 16:12:05| Processing: acl SSL_ports port 443
2014/02/10 16:12:05| Processing: acl Safe_ports port 80         # http
2014/02/10 16:12:05| Processing: acl Safe_ports port 21         # ftp
2014/02/10 16:12:05| Processing: acl Safe_ports port 443                # https
2014/02/10 16:12:05| Processing: acl Safe_ports port 70         # gopher
2014/02/10 16:12:05| Processing: acl Safe_ports port 210                # wais
2014/02/10 16:12:05| Processing: acl Safe_ports port 1025-65535 # unregistered ports
2014/02/10 16:12:05| Processing: acl Safe_ports port 280                # http-mgmt
2014/02/10 16:12:05| Processing: acl Safe_ports port 488                # gss-http
2014/02/10 16:12:05| Processing: acl Safe_ports port 591                # filemaker
2014/02/10 16:12:05| Processing: acl Safe_ports port 777                # multiling http
2014/02/10 16:12:05| Processing: acl CONNECT method CONNECT
2014/02/10 16:12:05| Processing: http_access allow manager localhost
2014/02/10 16:12:05| Processing: http_access deny manager
2014/02/10 16:12:05| Processing: http_access deny !Safe_ports
2014/02/10 16:12:05| Processing: http_access deny CONNECT !SSL_ports
2014/02/10 16:12:05| Processing: http_access allow localnet
2014/02/10 16:12:05| Processing: http_access allow localhost
2014/02/10 16:12:05| Processing: http_access deny all
2014/02/10 16:12:05| Processing: http_port 3128
2014/02/10 16:12:05| Processing: hierarchy_stoplist cgi-bin ?
2014/02/10 16:12:05| Processing: cache_dir ufs /usr/local/squid/var/cache 512 16 256
2014/02/10 16:12:05| Processing:  minimum_object_size 0 KB
2014/02/10 16:12:05| Processing: maximum_object_size 4096 KB
2014/02/10 16:12:05| Processing: coredump_dir /usr/local/squid/var/cache
2014/02/10 16:12:05| Processing: refresh_pattern ^ftp:          1440    20% 10080
2014/02/10 16:12:05| Processing: refresh_pattern ^gopher:       1440    0%  1440
2014/02/10 16:12:05| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%  0
2014/02/10 16:12:05| Processing: refresh_pattern .              0       20% 4320
2014/02/10 16:12:05| Initializing https proxy context
[root@server etc]# 

[root@server etc]# squid -s
[root@server etc]# netstat -ntlp | grep squid
tcp        0      0 0.0.0.0:3128                0.0.0.0:*                   LISTEN      17584/(squid)

[root@server etc]# squid -k shutdown
[root@server etc]# squid -k reconfigure
[root@server etc]# squid -s
[root@server etc]# netstat -tnlp | grep squid
tcp        0      0 192.168.1.110:3128          0.0.0.0:*                   LISTEN      17584/(squid)  


客户端的设置

客户端需要配置内网的地址

客户端不需要配置dns和网关

可断浏览器需要配置代理服务器的网关和端口



浏览器访问baidu


查看一下日志





1 0
原创粉丝点击