Squid代理上网服务

######

1、squid的概念

squid是一种用来缓存Internet数据的软件。接受来自人们需要下载的目标(object)的请求并适当的处理这些请求。也就是说,如果一个人想下载一web界面,他请求squid为他取得这个页面。squid随之
连接到远程服务器并向这个页面发出请求。然后,squid显式地聚集数据到客户端机器,而且同时复制一份。当下一次有人需要同一页面时, squid可以简单的从磁盘中读到它,那样数据会立即传输到客户机上。

2、Squid代理作用

通过缓存的方式为用户提供Web访问加速
对用户的Web访问进行过滤控制

3、Squid工作流程

当代理服务器中有客户端需要的数据时:
a. 客户端向代理服务器发送数据请求;
b. 代理服务器检查自己的数据缓存;
c. 代理服务器在缓存中找到了用户想要的数据,取出数据;
d. 代理服务器将从缓存中取得的数据返回给客户端。
当代理服务器中没有客户端需要的数据时:
1.客户端向代理服务器发送数据请求;
2.代理服务器检查自己的数据缓存;
3.代理服务器在缓存中没有找到用户想要的数据;
4.代理服务器向Internet 上的远端服务器发送数据请求;
5.远端服务器响应,返回相应的数据;
6.代理服务器取得远端服务器的数据,返回给客户端,并保留一份到自己的数据缓存中。

4、Squid安装配置

4.1、在可以上网的机器test01安装squid

[root@test01 ~]# yum install squid -y
[root@test01
~]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.50.20 netmask 255.255.255.0 broadcast 192.168.50.255 inet6 fe80::f816:3eff:feb1:c2c9 prefixlen 64 scopeid 0x20<link> ether fa:16:3e:b1:c2:c9 txqueuelen 1000 (Ethernet) RX packets 887995 bytes 2246987013 (2.0 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 914010 bytes 1447569963 (1.3 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.2、对test01机器squid服务进行配置

[root@test01 ~]# cat /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 local src 192.168.50.0/24              #此处添加配置含义:允许此网段服务器通过test01服务代理出网
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 local  #添加local含义:引用上面添加规则
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

4.3、启动squid服务

[root@test01 ~]# systemctl restart squid

4.4、配置不可上网服务器test02环境变量

[root@test02 ~]# tail -2 /etc/profile   #在/etc/profile中添加如下两行配置
http_proxy=192.168.50.20:3128           #指定squid代理服务器IP(squid部署服务器):端口
export http_proxy
[root@test02
~]# source /etc/profile

######

原文地址:https://www.cnblogs.com/faithH/p/14075022.html