Linux_SquidProxyServer代理服务器

Squid proxy server

Squid是基于Unix的代理服务器(proxy server),支持缓存多种不同的网络对象,包括那些通过HTTP和FTP访问的对象。缓存频繁访问的网页、媒体文件等,实现加速应答时间并减少带宽堵塞。Squid通过追踪网络中的对象来实现作用。Squid最初担当中介,仅仅是把客户请求传递到服务器并存储请求对象的副本。如果同一个用户或同一批用户再次请求还缓存(cache)在Squid中的相同对象时,Squid能够立即服务,加速下载并保存带宽。Squid代理服务器提供更快的下载速度、缩短延迟时间,尤其是在提供丰富媒体和流式视频方面。网站经营者将频繁地把Squid代理服务器作为内容加速器、频繁查看内容的缓存和网络服务器的容位负载。内容发布网络和媒体公司会采用Squid代理服务器,并在整个网络中部署它们来改善浏览者的访问体验,特别是对流式内容的负载平衡(load balancing)和处理访问高峰等方面的优化有显著效果。 
Squid can proxy http ftp ssl protocol. 
Effect:Proxy server helps client users to gets and cache the data from targeted host. Realize more fast and more secure what access web protal.

Web proxy server operating principle

Cache web element object(static text,picture),reduce multiple request. 
1. Forward Proxy(SNAT) 
2. Reverse Proxy(DNAT) 
Achieve firewall function via domain name limit(application layer). 
Forward proxy: 
1. Typical proxy: need setup proxy’s ip and port by manual in the browser. 
2. Transparent proxy: host gateway IP assign to proxy server

Squid features

Software:squid-3.1.10-1.e16_2.4.X86_64 
Service:squid 
Configure file:/etc/squid/squid.conf 
Squid control module store dirextory: /usr/lib64/squid/ 
Config option:

http_port     squidServerIP:3128
cache_mem     64 MB     #one half as cache(64MB) when the mem > 2G
cache_dir    nfs        /var/spool/squid    100        16        256
        #100 -->  Total disk space < 100M
        #16  -->  Total directory < 16
        #256 --> Total level2 directory in the level1 directory
visible_hostname    proxy.fan.com   #if have not hostname and this option, the proxy server can not start.
dns_testnames    www.baidu.com
reply_body_max_size    10 MB     #forbid download the file when the file size greater than 10MB
minimum_object_size    0kb         #don't cache data when the data count less than Xkb, 0 the meaning is no limit.
maximum_object_size 4096kb     #don't cache date when the data greater than Xkb
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

ACL list control mode. 
1. Format:

acl    listName listType listContent
http_access  allow/deny  listName
http_access  allow/deny  "url"   #import url of ACLlist file,Create file for store ACLList when the ACLList have too much.
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

Example:Deny cache web paper

acl deny php,...
cache_deny:deny php
  • 1
  • 2
  • 1
  • 2

Acl list type:

src:source address     #Can define network segment example:IP or continuous IP. 192.168.1.10-192.168.1.20/24
dst:destination address
port:destination port
srcdomain:source domain
dstdomain:destination domain
time:access time,general the parameter is range, example:09:30-17:30
maxconn:max concurrency connect
url_regex:destination url address, example : ^rtsp://     #Beginning with this type
urlpath_regex:complete destination url path, example: -i Sex adult
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Setup squid server

step1. General squid

yum install -y squid
  • 1
  • 1

step2. Edit configuration file 
vim /etc/squid/squid.conf

http_port 10.20.0.210(proxyServerIP):3182
reply_body_max_size 10MB
cache_dir    nfs        /var/spool/squid    100        16        256
visible_hostname  proxy.fan.com
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Attention:Frist make DNS analysis as IP in the client then send the data package to squid server, but squid do not proxy DNS server, so should be setup SDNA and use it to connect DNS in the squid server.

Setup transparent proxy

Transparent proxy can’t support 443 port 
step1.Edit config file 
vim /etc/squid/squid.conf

http_port ServerIP:3128        transparent
  • 1
  • 1

step2. Set the iptables rules

iptables -t nat -A PREROUTING -i eth1 -s 192.168.4.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
  • 1
  • 1

Attention:

iptables -t nat -A PREROUTING -i eth1 -s 192.168.4.0/24 -p tcp --dport 443 -j REDIRECT --to-port 3128
#Will 80 port access session assign to squid server's 3128 port, resolve way is use the SNAT.
  • 1
  • 2
  • 1
  • 2

step3. Set the ACL rules

acl worktime time D 9:00-17:30
acl burl urlpath_regex -i game \.mp3$
http_deny burl
http_access allow localnet worktime
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Squit authentication

Transparent proxy don’t use authentication ,but the classical proxy can. 
step1. Add authentition module.

/usr/lib64/squid/ncsa_auth --> authentication mudule
  • 1
  • 1

step2. Set authentication parameter in the main config file. 
step3. Set authentication ACL

acl auth_user proxy_auth REQUIRED
http_access allow auth_user
  • 1
  • 2
  • 1
  • 2

step4. Create authentication account 
vim squid.conf

acc auth_user proxy_auth REQUIRED
http_access auth_user
auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/auth_user.txt   #Frist line in the config file. Specify user list file for ncsa_auth authentication module
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
htpasswd -c /etc/squid/auth_user.txt jmilk    #create user list file, you have to install httpd service to use command htpasswd
cat /etc/squid/auth_user.txt
  • 1
  • 2
  • 1
  • 2

vim /etc/squid/squid.conf

auth_param basic children 5 --> deal with 5 concurrent authentication
auth_param basic realm Squid proxy-caching web  --> welcome page
auth_param basic credentialstt2 2 hours  --> timeout
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step5. Set the speed limit for every IP.

delay_pools 1   #relay pool number
delay_class 1 3
            #1 --> relay pool number
            #3 --> specify network type to B;1: one IP;2:type C;3:type B;4: type A
delay_access 1 allow localnet      #usr acl:localnet
delay_parameters 1 -1/-1 20000/20000(byte)
            #-1/-1  --> all network segment
            #20000/20000 --> no limit download speed before 200M/speed limit beyond 200M
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Setup the Reverse Proxy Server

Web 服务器容易出现负载瓶颈,有下面解决办法 
1. Web服务器集群 
2. 使用反向代理服务器 
反向代理服务器:类似DNS以缓存的方式,减轻web server的压力 
Listen 80 
no set ACL, allow all 
step1
vim squid.conf

http_port ProxyServerIP:80 vhost
cache_peer WebServerIP parent 80 0 originserer
http_access allow
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

Case: set the transparent proxy

vim squid.conf

http_port squidServerIP:3128 transparent
visible_hostname transparent.fan.com
cache_dir ufs /var/spool/squid 100 16 256
cache_mem 1024 MB
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

对超过3MB大小的文件不做缓存,禁止下载超过100M的文件

maximum_object__size 3 MB
reply_body_max_size 100 MB
  • 1
  • 2
  • 1
  • 2

启用网址过滤,禁止访问带有”Sex”,”adult”字样的链接

acl burl urlpath_regex -i Sex adult
        #-i --> key word
http_access deny burl
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

配置Squid使用基本的身份认证,并且创建用户jmilk,只有通过身份认证后才可以使用squid上网。(透明代理不支持,只有传统代理支持) 
vim squid.conf

acl auth_user proxy_auth REQUIREP|-i userName     #支持所设定的用户|支持用户列表
http_access allow auth_user
htpasswd -c /etc/squid/auth_user.txt jmilk
cat /etc/squid/auth_user.txt
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

vim squid.conf

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/auth_user.txt    #put it in frist line
auth_param basic children 5              #一次可以处理5个并发认证
auth_param basic realm Hellow!           #设定欢迎页面
auth_param basic credentialsttl 2 hours  #一次用户认证的有效时间
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

设置客户端192.168.1.52在上班时间的最高下载速度为150k/s

acl worktime time D 9:00-24:00  #D (周一到周五)  DSA全周
acl lan src 192.168.1.52/32
delay_pools 1                   #限速池1,为每个限速对象定序号
delay_class 1 2                 #声明1号池的IP类型为C类IP地址
delay_access 1 allow worktime lan
delay_parameters 1 -1/-1 150000/2000000

转载:http://blog.csdn.net/jmilk/article/details/50286253

时间: 2024-08-07 15:57:04

Linux_SquidProxyServer代理服务器的相关文章

在Linux代理服务器上设置防火墙

一般而言,实现Linux的防火墙功能有两种策略.一种是首先全面禁止所有的输入.输出和转发数据包,然后根据用户的具体需要逐步打开各项服务功能.这种方式的特点是安全性很高,但必须全面考虑用户所需的各项服务功能,不能有任何遗漏,要求系统管理员清楚地知道实现某种服务和功能需要打开哪些服务和端口.第二种方式是首先默认打开所有的输入.输出数据包,然后禁止某些危险包.IP欺骗包.广播包.ICMP服务类型攻击等:对于应用层的服务,像 http.sendmail.pop3.ftp等,可以有选择地启动或安装.这种方

利用GoAgent让PHP空间成为你的代理服务器

前一段时间,一直使用的GAE,可是今天突然发现无法使用了.找了找,不知道问题出在什么地方.后来想了想,很有可能是因为我前几篇文章分享了,gae不需要设置直接使用的那个文件了.导致google把我的那个账号给封掉了. 既然不能使用了,那网还是要上,facebook还是要玩,youtube还是要看滴.我们就使用PHP的空间作为代理服务器吧. 下文基于PHP空间的GoAgent代理方式: 1,首先当然是一个支持php的空间啦!前提是国外的空间,而且没有被和谐).不管免费还是收费(空间必须支持curl或

socket-JAVA代理服务器,用浏览器打开的时候显示的网页信息总是不全,有时候显示不出来,求大神帮我看看

问题描述 JAVA代理服务器,用浏览器打开的时候显示的网页信息总是不全,有时候显示不出来,求大神帮我看看 package work; import java.io.*; import java.net.*; public class MMProxy extends Thread { static public int CONNECT_RETRIES = 5; //尝试与目标主机连接次数 static public int CONNECT_PAUSE = 5; //每次建立连接的间隔时间 stat

Win8如何设置LAN代理服务器

  Win8设置LAN代理服务器的方法如下: 1.点击屏幕左下角IE图标,打开浏览器,在IE右上角位置打开小齿轮图标,点击选择"Internet 选项". 2.在Internet选项中点击"连接"标签.先择"局域网设置". 3.在"局域网(LAN)设置"中,在"为LAN使用代理服务器(这些设置不用于拨号或是VPN)"前复选打对号.输入正确的地址和端口,然后确定. 4.在"Internet选项&qu

代理服务器的路由分析

对于小型用户群体或家庭用户接入Internet,采用拨号上网不失为一种廉价实用的方式.在局域网上通过代理服务器软件便可以解决多用户共享访问Internet问题,代理服务器实质上是一个介于用户群体和Internet之间的桥梁,用以实现其网络用户对Internet的访问. 利用局域网 目前局域网的组网产品很多,以太网交换机或集线器(HUB)价格低廉,非常容易实现局域网客户的互联.本文以现有园区网为例,阐述如何利用PROXY代理服务器实现Internet连接,并进行代理服务器的内部路由分析.本局域网的

搜狗高速浏览器如何设置多个代理服务器

设置多个代理服务器的方法:点击菜单栏工具选项,找到网络连接.当选择"添加新代理",可以添加代理服务器地址,如图所示.   当选择"网络连接设置",可以对已有的代理服务器进行编辑和设置,如图所示. 当选择"代理测速",可以对已有的代理服务器进行速度测试,如图所示.

用XMLHTTP通过代理服务器从服务提取数据的一些问题

xml|服务器|数据|问题 用XMLHTTP通过代理服务器从服务提取数据,比如说从WEBSERVICE.ASP.ASPX提取数据,我在用的时候曾经出现过一些不明问题,往往通不过代理认证.经过多次摸索,终于弄明白其中的原因,现分拿出来分享. 在VB中调用方法是这样的:     Dim objHTTP As New XMLHTTP               objHTTP.open "post", http://192.168.1.2/web.asmx, False    objHTTP

用RedHat打造安全高效的代理服务器

Linux具有安全.高效.廉价的优点,但大家对它一直有难以使用的印象.其实,随着Linux的不断发展,它的易用性已大有改观.采用Linux操作系统,可使一台配置赛扬400MHz CPU.256MB内存的机器,用ADSL带动两三百台电脑上网成为轻而易举的事.下面就以RedHat 8.0和Squid为例,教你打造一个安全.高效的服务器. 配置服务器上网 首先要使服务器能上网.为了提高服务器的效率,一般要用双网卡,一块连接内部局域网,一块用来连接互联网.下面让我们来看看连接ADSL类宽带的方法. 1.

搭建Linux安全的Squid代理服务器

代理服务器的功能是代理网络用户取得网络信息,它 是网络信息的中转站.随着代理服务器的广泛使用,随之而来的是一系列的安全问题.由于没有对代理服务器的访问控制策略作全面细致的配置,导致用户可以随意地通过代理服务器访问许多色情.反动的非法站点,而这些行为往往又很难追踪,给管理工作带来极大的不便. Squid是Linux下一个缓存Internet数据的代理服务器软件,其接收用户的下载申请,并自动处理所下载的数据.也就是说,当一个用户想要下载一个主页时,可以向Squid发出一个申请,要Squid代替其进行