Linux_SquidProxyServer代理服务器

简介: 目录目录Squid proxy serverWeb proxy server operating principleSquid featuresSetup squid serverSetup transparent proxySquit authent...

目录

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
AI 代码解读

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.
AI 代码解读

Example:Deny cache web paper

acl deny php,...
cache_deny:deny php
AI 代码解读

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
AI 代码解读

Setup squid server

step1. General squid

yum install -y squid
AI 代码解读

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
AI 代码解读

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
AI 代码解读

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
AI 代码解读

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.
AI 代码解读

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
AI 代码解读

Squit authentication

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

/usr/lib64/squid/ncsa_auth --> authentication mudule
AI 代码解读

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

acl auth_user proxy_auth REQUIRED
http_access allow auth_user
AI 代码解读

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
AI 代码解读
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
AI 代码解读

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
AI 代码解读

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
AI 代码解读

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
AI 代码解读

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
AI 代码解读

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

maximum_object__size 3 MB
reply_body_max_size 100 MB
AI 代码解读

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

acl burl urlpath_regex -i Sex adult
        #-i --> key word
http_access deny burl
AI 代码解读

配置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
AI 代码解读

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  #一次用户认证的有效时间
AI 代码解读

设置客户端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
AI 代码解读
目录
打赏
0
0
0
0
37
分享
相关文章
|
2月前
|
Websoft9:为开发者打造的高效 Linux 服务器面板
Websoft9 是一款以开源应用部署与管理为核心的服务器面板,采用“环境即服务”模式。它通过运行环境标准化、自动化配置、安全融合和资源管理四个方面实现平台与环境的深度协同。支持多语言框架预集成、云原生组件整合,提供 200+ 应用模板一键部署,并具备全流程安全防护和统一资源监控能力,助力开发者高效管理和扩展应用环境。
64 0
|
17天前
|
阿里云linux服务器使用脚本通过安全组屏蔽异常海外访问ip
公网网站可能会遭受黑客攻击导致访问异常,使用此脚本可以屏蔽掉异常IP 恢复访问。也可自行设置定时任务定期检测屏蔽。
120 28
在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾
以上就是在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾的步骤。这个过程就像是一场接力赛,数据从MySQL数据库中接力棒一样传递到备份文件,再从备份文件传递到其他服务器,最后再传递回MySQL数据库。这样,即使在灾难发生时,我们也可以快速恢复数据,保证业务的正常运行。
95 28
在Linux服务器中遇到的立即重启后的绑定错误:地址已被使用问题解决
总的来说,解决"地址已被使用"的问题需要理解Linux的网络资源管理机制,选择合适的套接字选项,以及合适的时间点进行服务重启。以上就是对“立即重启后的绑定错误:地址已被使用问题”的全面解答。希望可以帮你解决问题。
91 20
|
2月前
|
Linux系统管理:服务器时间与网络时间同步技巧。
以上就是在Linux服务器上设置时间同步的方式。然而,要正确运用这些知识,需要理解其背后的工作原理:服务器根据网络中的其他机器的时间进行校对,逐步地精确自己的系统时间,就像一只犹豫不决的啮齿动物,通过观察其他啮齿动物的行为,逐渐确定自己的行为逻辑,既简单,又有趣。最后希望这个过程既能给你带来乐趣,也能提高你作为系统管理员的专业素养。
124 20
Linux云服务器如何搭建LNMP环境
LNMP环境是Linux系统中常用的Web服务架构,由Linux、Nginx、MySQL/MariaDB和PHP组成,适用于高效托管动态网站。本文以CentOS 7为例,详细介绍了LNMP环境的搭建步骤,包括Nginx、MariaDB和PHP的安装与配置,以及最终通过创建`index.php`文件验证环境是否成功部署。具体操作涵盖配置YUM仓库、安装服务、编辑配置文件、启动服务等关键步骤,确保用户能够顺利搭建并运行LNMP环境。
76 1
Linux云服务器如何搭建LNMP环境
深度体验阿里云系统控制台:SysOM 让 Linux 服务器监控变得如此简单
作为一名经历过无数个凌晨三点被服务器报警电话惊醒的运维工程师,我对监控工具有着近乎苛刻的要求。记得去年那次大型活动,我们的主站流量暴增,服务器内存莫名其妙地飙升到90%以上,却找不到原因。如果当时有一款像阿里云 SysOM 这样直观的监控工具,也许我就不用熬通宵排查问题了。今天,我想分享一下我使用 SysOM 的亲身体验,特别是它那令人印象深刻的内存诊断功能。
Linux服务器部署docker windows
在当今软件开发中,Docker成为流行的虚拟化技术,支持在Linux服务器上运行Windows容器。流程包括:1) 安装Docker;2) 配置支持Windows容器;3) 获取Windows镜像;4) 运行Windows容器;5) 验证容器状态。通过这些步骤,你可以在Linux环境中顺利部署和管理Windows应用,提高开发和运维效率。
197 1
云上体验最佳的服务器操作系统 - Alibaba Cloud Linux | 飞天技术沙龙-CentOS 迁移替换专场
本次方案的主题是云上体验最佳的服务器操作系统 - Alibaba Cloud Linux ,从 Alibaba Cloud Linux 的产生背景、产品优势以及云上用户使用它享受的技术红利等方面详细进行了介绍。同时,通过国内某社交平台、某快递企业、某手机客户大数据业务 3 大案例,成功助力客户实现弹性扩容能力提升、性能提升、降本增效。 1. 背景介绍 2. 产品介绍 3. 案例分享
推荐几个不错的 Linux 服务器管理工具
推荐几个不错的 Linux 服务器管理工具
377 6
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等