Squid代理服务器

缓存代理概述:做为应用层的代理服务软件,squid主要提供缓存加速,应用层过滤控制的功能。

1.代理的工作机制

当客户机通过代理来请求web页面时,指定的代理服务器会先检查自己的缓存,如果缓存中已经有客户机需要的页面,则直接将缓存中的页面内容反馈给客户机,如果缓存中没有客户机要访问的页面,则由代理服务器向Internet发送访问请求,当获得返回的web页面以后,将网页数据保存到缓存中并发送给客户机!如图

HTTP代理缓存加速对象主要是文字,图像等静态web元素。使用缓存机制后,当客户机在不同的时候访问同一web元素,或者不同的客户机访问不同的web元素时,可以直接从代理服务器的 缓存中获得结果。这样就大大减少了想Internet提交重复的web请求的过程,提高了客户机的web访问响应速度。

由于客户机的web访问请求实际上是由代理服务器来替代完成的,从而可以隐藏用户的真实ip地址,起到一定的保护作用。另一方面,代理服务器担任着类似“经纪人”的角色,所以有机会针对要访问的目标,客户机的地址,访问的时间段等进行过滤控制。

2.代理的基本性质类型。

根据实现方式不同,代理服务器可分为传统代理和透明代理两种常见的代理服务。

1)传统代理:也就是普通的代理服务,首先必须在客户机的浏览器,qq聊天工具,下载软件等程序中手动设置代理服务器的地址和端口,然后才能使用代理来访问网络。对于网页浏览器,访问网站时的域名解析请求也会发给指定的代理服务器。

2)透明代理:提供与传统代理相同的功能和服务,其区别在于客户机不需要指定代理服务器的地址和端口,而是通过默认路由,防火墙策略将web访问重定向,实际仍然交给代理服务器处理。重定向的过程对客户机来说是透明的,用户甚至并不知道自己在使用代理服务,所有称为“透明代理”,使用透明代理时,网页浏览器访问网站时的域名解析请求将优先先发给dns服务器。

安装及运行控制

软件:squid3.4.6

系统:centos 6.5

1)编译安装squid

[[email protected] ~]# tar zxf squid-3.4.6.tar.gz -C /usr/src/   //解压
[[email protected] ~]# cd /usr/src/squid-3.4.6/
[[email protected] squid-3.4.6]# ./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-arp-acl --enable-linux-netfilter --enable-linux-tproxy --enable-async-io=100 --enable-err-language="Simplify_Chinese" --enable-underscore --enable-poll --enable-gnuregex     //配置
[[email protected] squid-3.4.6]# make && make install     //编译安装
  • --prefix=/usr/local/squid          //安装目录
  • --sysconfdir=/etc                   //单独将配置文件修改到其他目录
  • --enable-arp-acl                    //可以在规则中设置直接通过客户端MAC进行管理,防止客户端使用ip欺骗
  • --enable-linux-netfilter           //使用内核过滤
  • --enable-linux-tproxy            //支持透明模式
  • --enable-async-io                 //异步i/o,提升存储性能,相当于--enable-pthreads     --enable-storeio=ufs,aufs --with//-pthreads  --with-aufs-thread=值
  • --enable-err-language="Simplify_Chinses"    //错误信息的显示语音
  • --enable-underscore                                  //允许URL中有下划线
  • --enable-poll                                            //使用poll()模式,提高性能
  • --enable-gnuregex                                  //使用GNU正则表达式

创建链接文件、创建用户和组更改目录属主属组

[[email protected] squid-3.4.6]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/
[[email protected] squid-3.4.6]# useradd -M -s /sbin/nologin squid
[[email protected] squid-3.4.6]# chown -R squid.squid /usr/local/squid/var/
[[email protected] squid-3.4.6]# vim /etc/squid.conf     //修改配置文件
49 # Example rule allowing access from your local networks.
 50 # Adapt localnet in the ACL section to list your (internal) IP networks
 51 # from where browsing should be allowed
 52 http_access allow localnet
 53 http_access allow localhost
 54
 55 # And finally deny all other access to this proxy
 56 http_access deny all
 57
 58 # Squid normally listens to port 3128
 59 http_port 3128
 60 cache_effective_user squid   //这一项指定squid的程序用户,用来设置初始化允许缓存的账号,负责启动不成功!
 61 cache_effective_group squid   //默认为cache_effective_user指定账号的基本组
 62 # Uncomment and adjust the following to add a disk cache directory.
 63 #cache_dir ufs /usr/local/squid/var/cache/squid 100 16 256
 64
 65 # Leave coredumps in the first cache dir
 66 coredump_dir /usr/local/squid/var/cache/squid
 67
[[email protected] ~]# squid -k parse    //检查配置文件语法是否正确
2015/09/23 06:38:26| Startup: Initializing Authentication Schemes ...
2015/09/23 06:38:26| Startup: Initialized Authentication Scheme ‘basic‘
2015/09/23 06:38:26| Startup: Initialized Authentication Scheme ‘digest‘
2015/09/23 06:38:26| Startup: Initialized Authentication Scheme ‘negotiate‘
2015/09/23 06:38:26| Startup: Initialized Authentication Scheme ‘ntlm‘
2015/09/23 06:38:26| Startup: Initialized Authentication.
2015/09/23 06:38:26| Processing Configuration File: /etc/squid.conf (depth 0)
2015/09/23 06:38:26| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2015/09/23 06:38:26| Processing: acl localnet src 172.16.0.0/12    # RFC1918 possible internal network
2015/09/23 06:38:26| Processing: acl localnet src 192.168.0.0/16    # RFC1918 possible internal network
2015/09/23 06:38:26| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2015/09/23 06:38:26| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2015/09/23 06:38:26| Processing: acl SSL_ports port 443
2015/09/23 06:38:26| Processing: acl Safe_ports port 80        # http
2015/09/23 06:38:26| Processing: acl Safe_ports port 21        # ftp
2015/09/23 06:38:26| Processing: acl Safe_ports port 443        # https
2015/09/23 06:38:26| Processing: acl Safe_ports port 70        # gopher
2015/09/23 06:38:26| Processing: acl Safe_ports port 210        # wais
2015/09/23 06:38:26| Processing: acl Safe_ports port 1025-65535    # unregistered ports
2015/09/23 06:38:26| Processing: acl Safe_ports port 280        # http-mgmt
2015/09/23 06:38:26| Processing: acl Safe_ports port 488        # gss-http
2015/09/23 06:38:26| Processing: acl Safe_ports port 591        # filemaker
2015/09/23 06:38:26| Processing: acl Safe_ports port 777        # multiling http
2015/09/23 06:38:26| Processing: acl CONNECT method CONNECT
2015/09/23 06:38:26| Processing: http_access deny !Safe_ports
2015/09/23 06:38:26| Processing: http_access deny CONNECT !SSL_ports
2015/09/23 06:38:26| Processing: http_access allow localhost manager
2015/09/23 06:38:26| Processing: http_access deny manager
2015/09/23 06:38:26| Processing: http_access allow localnet
2015/09/23 06:38:26| Processing: http_access allow localhost
2015/09/23 06:38:26| Processing: http_access deny all
2015/09/23 06:38:26| Processing: http_port 3128
2015/09/23 06:38:26| Processing: cache_effective_user squid
2015/09/23 06:38:26| Processing: cache_effective_group squid
2015/09/23 06:38:26| Processing: coredump_dir /usr/local/squid/var/cache/squid
2015/09/23 06:38:26| Processing: refresh_pattern ^ftp:        1440    20%    10080
2015/09/23 06:38:26| Processing: refresh_pattern ^gopher:    1440    0%    1440
2015/09/23 06:38:26| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
2015/09/23 06:38:26| Processing: refresh_pattern .        0    20%    4320
[[email protected] ~]# 

[[email protected] ~]# squid -z       //启动前必须初始化缓存目录

[[email protected] ~]# squid          //启动squid

服务启动脚本:如下

#!/bin/bash
#chkconfig: 2345 90 25
#config: /etc/squid.conf
#pidfile: /usr/local/squid/var/run/squid.pid
#description: squid - internet object cache.
PID="usr/local/squid/var/run/squid.pid"
CONF="/etc/squid.conf"
CMD="/usr/local/squid/sbin/squid"
case "$1" in
start)
    netstat -anpt | grep squid  &>/dev/null
    if [ $? -eq 0 ]
     then
      echo "squid is running"
        else
      echo "正在启动squid…….."
      $CMD
    fi
;;
stop)
   $CMD -k kill &> /dev/null
   rm -rf $PID &> /dev/null
;;
status)
   [ -f $PID ] &> /dev/null
       if [$? -eq 0 ]
           then
       netstat -anpt | grep squid
         else
            echo "squid is not running"
         fi
;;
restart)
$0 stop &> /dev/null
      echo "正在关闭squid……"
        $0 start &> /dev/null
      echo "正在启动squid……"
;;
reload)
    $CMD -k reconfigure
;;
check)
    $CMD -k parse
;;
*)
   echo "用法:$0 {start | stop |restart | reload | check | status}"
;;
esac
[[email protected] ~]# chmod 775 /etc/init.d/squid     //授权脚本权限
[[email protected] ~]# /etc/init.d/squid restart           //重启squid服务
[[email protected] ~]# chkconfig squid on                //开机自启动
[[email protected] ~]# chkconfig --add squid           //添加系统服务
时间: 2024-07-31 16:10:17

Squid代理服务器的相关文章

Squid代理服务器--实战篇

一.传统代理 使用传统代理的特点在于,客户机的相关程序(如IE浏览器.QQ聊天工具)必须指定代理服务器的地址.端口等信息.下面通过一个简单的应用案例来学习传统代理的配置和使用 基于Internet网络环境,案例的主要需求描述如下: 在Linux主机B上,构建Squid为客户机访问各种网站提供代理服务,但禁止通过代理下载超过10MB大小的文件 在客户机C上,指定主机B作为Web访问代理,以隐藏自己的真实IP地址 针对上述实验环境,主机B作为代理服务器必须正确构建Squid服务,并允许客户机使用代理

CentOS 6.4下Squid代理服务器的安装与配置

一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可以向Squid 发出一个申请,要Squid 代替其进行下载,然后Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid 把保存的备份立即传给用户,使用户觉得速度相当快.Squid 可以代理HTTP.FTP.GOPH

Linux与云计算——第二阶段 第一十一章:代理Proxy服务器架设—Squid代理服务器正向代理和客户端配置

Linux与云计算--第二阶段Linux服务器架设 第一十一章:代理Proxy服务器架设-Squid代理服务器正向代理和客户端配置 安装Squid 安装Squid来配置代理服务器. [1] 这是一个通用的转发代理配置 [[email protected] ~]# yum -y install squid [[email protected] ~]# vi /etc/squid/squid.conf # line 26: 添加一条新的ACL acl lan src 192.168.96.0/24

[转]CentOS 6.4下Squid代理服务器的安装与配置

一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可以向Squid 发出一个申请,要Squid 代替其进行下载,然后Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid 把保存的备份立即传给用户,使用户觉得速度相当快.Squid 可以代理HTTP.FTP.GOPH

构建squid代理服务器

实验拓扑图: 需求:配置iptables策略,利用SNAT共享internet 配置squid代理服务器.实现http访问的缓存加速 先用yum -y install squid.1* 安装squid代理服务器. 两块网卡:eth0 192.168.5.6/24 桥接到vm1 eth1 202.10.10.5/24 桥接到vm8 gw 202.10.10.1 web服务器是2003 server 搭建一个简单的网站做测试. ip:172.168.10.10/24 gw :172.168.10.1

Linux之安装部署squid代理服务器

Linux之安装部署squid代理服务器 1.案例拓扑图 系统centos6.5   软件sarg-2.3.7.tar.gz  squid-3.4.6.tar.gz 2.案例要求 (1)如上图要求配置网络,内部linux需要配置默认网关,外部linux不需要配置默认网关,squid服务器上开启路由转发. (2)在squid服务器上安装squid,并做相关的配置,启动squid服务,查看端口. (3)搭建传统代理服务器,要求在内部linux服务器能够使用传统代理访问外部的web服务器.内部客户端最

2-12-配置squid代理服务器加快网站访问速度

本节所讲内容: squid服务器常见概念 squid服务器安装及相关配置文件 实战:配置squid正向代理服务器 实战:配置透明squid代理提升访问速度 实战:配置squid反向代理加速度内网web服务器访问速度 squid服务概述: 全称: squid cache,是一个流行的自由软件(GNU通用公共许可证). 主要有连个功能:  代理服务器 和 为web服务器提供缓存 应用广泛: 1. 共享网络资源,缓存万维网; 2.为web服务器前置缓存提高web服务器的访问速度; 3. 域名和其他网络

squid代理服务器(捎带的SNAT)

1.传统代理 传统代理可以隐藏IP地址 多用于Internet 在Linux中 默认没有安装squid 所以要安装 在red hat中 还要安装perl 语言包的支持 squid代理服务器需要两块网卡  首先保证你的流量是从linux服务器上过的 所以先保证做完SNAT可以互相通信 1)配置网络参数 在试验中一块网卡桥到VM2 一块VM3             这里内网eth0 对应 VM2  外网eth1 对应VM3 配置主机名:因为做代理代理服务器的时候 或者干其他事 配置主机名很重要 w

搭建squid代理服务器

准备环境: 客户机:192.168.118.4 squid代理服务器:192.168.118.3(内网IP)1.1.1.1(外网IP) web服务器:1.1.1.2 实现目标:客户机通过squid代理服务器访问web服务器 一.普通代理 1.首先将各个主机的防火墙关闭,然后实现squid服务器分别与另外两台机器互通 2.给web服务器搭建HTTP服务 [[email protected] ~]# yum -y install httpd [[email protected] ~]# servic

squid代理服务器的安装和配置

CentOS 6.4下Squid代理服务器的安装与配置 一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可以向Squid 发出一个申请,要Squid 代替其进行下载,然后Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid 把保存的备份立即传给用户,使用户觉得速