如何yum部署Squid?

Forward Proxy

1 基础理论

1.1 概念

Squid是一个高性能的代理缓存服务器,他可以缓冲Internet的数据。
简单地说,你可以通过他去间接地向一台Web服务器发起一个页面请求,Squid会响应你的请求到Web服务器取得响应的页面并缓存下载并转发给你。

1.2 Squid的应用场景

1.2.1 正向代理

– 以减轻客户端的网关网络流量为目的
– 客户端的浏览器通过改代理服务器浏览互联网的页面
– 代理服务器通过缓存技术减轻网关的网络流量
注:即我们平时所说的上网代理,也是本次实践的主题

1.2.2 反向代理

– 以减轻后端服务器的负载为目的
– 将原来客户端浏览器到Web服务器的直接页面请求变成间接的页面请求请求(透过代理来完成)
– 代理服务器通过缓存技术减轻后端服务器打的负载
– 代理服务器只提供静态的内容使得后端的动态页面服务器更加的安全

2. 实践部分

2.1 基本配置

2.1.1 环境信息

Squid Server:
IP Address = 10.168.0.80
Gateway = 10.168.0.1
Operating System = CentOS 7.x

Squid Client:
IP Address = 10.168.0.x
Gateway = no set
Operating System = CentOS 7.x
注:
– 请注解掉网关,或者配置一个错误的网关地址
– 目的是防止客户端通过网关与外部通讯,或防火墙配置亦可。

2.1.2 基本配置

In Squid Server:

yum install -y squid

2.1.3 配置防火墙

In Squid Server:

firewall-cmd --permanent --add-service squid
firewall-cmd --reload
firewall-cmd --list-all

2.2 配置Squid服务端

In Squid Server:

2.2.1 修改配置文件

egrep -v "^#|^$" /etc/squid/squid.conf

参数如下:

acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

2.2.2 启动代理并配置自动运行

systemctl start squid
systemctl enable squid

2.3 配置Squid客户端

In Squid Client:

2.3.1 设置客户端的代理服务器

export http_proxy="http://user1:passwd1@10.168.0.80:3128"
export https_proxy="http://user1:passwd1@10.168.0.80:3128"

由于配置没有开启认证,请省略用户名和密码,

export http_proxy="http://10.168.0.80:3128"
export https_proxy="http://10.168.0.80:3128"

2.3.2 测试客户端的代理

curl http://www.cmdschool.org
curl https://www.cmdschool.org

注:请不要尝试去ping或者nslookup,因为代理的只是http协议。

参阅文档:
==================
https://wiki.squid-cache.org/ConfigExamples

没有评论

发表回复

Forward Proxy
如何基于openSSH部署Socks代理服务?

1 前言 一个问题,一篇文章,一出故事。 笔者需要实现Socks代理服务以便于内网的电脑客户端可以通 …

Forward Proxy
如何修改Squid的日志格式?

1 前言 一个问题,一篇文章,一出故事。 笔者查看Squid的访问日志发现时间部分是时间戳,笔者感觉 …

Forward Proxy
如何配实现Squid多开实例同时运行?

1 前言 一个问题,一篇文章,一出故事。 笔者整理本文的原因是遇到Squid遇到需要在同一台服务器启 …