一、构建传统代理服务器
1.环境配置
主机 | 主机名 | 操作系统 | IP 地址 | 主要软件 |
---|---|---|---|---|
Squid-Server | CentOS 7-5 | CentOS 7 | 192.168.126.15 | squid-3.5.28.tar.gz |
Web1 | CentOS 7-4 | CentOS 7 | 192.168.126.14 | httpd |
客户端 | Win10 | Windows | 192.168.126.10 | / |
2.构建步骤
2.1 Squid-Server
vim /etc/squid.conf
......
http_access allow all
http_access deny all
http_port 3128
cache_effective_user squid
cache_effective_group squid
#63行,插入
cache_mem 64 MB
#指定缓存功能所使用的内存空间大小,便于保持访问较频繁的WEB对象,容量最好为4的倍数,单位为MB,建议设为物理内存的1/4
reply_body_max_size 10 MB
#允许用户下载的最大文件大小,以字节为单位,当下载超过指定大小的Web对象时,浏览器的报错页面中会出现“请求或访问太大”的提示默认设置0表示不进行限制
maximum_object_size 4096 KB
#允许保存到缓存空间的最大对象大小,以KB为单位,超过大小限制的文件将不被缓存,而是直接转发给用户
service squid restart
或
systemctl restart squid
#重启服务以使配置生效
netstat -natp | grep squid
#确认是否启动成功
生产环境中还需要修改防火墙规则:
iptables -F
iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
iptables -L INPUT
2.2 客户机的代理配置
- 配置客户端(Win10)的 IP 地址
- 打开浏览器,配置代理功能
2.3 Web1
注:这里是第二台 Linux(Web1) 了
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum -y install httpd
#用 YUM 安装 apache httpd 服务
systemctl start httpd
#开启服务并确认端口是否已启动
netstat -natp | grep 80
2.4 检测
在浏览器输入 Web 服务器 IP 地址进行访问
查看 Web1 访问日志的新增记录
tail -f /var/log/httpd/access_log
二、构建透明代理服务器
1.环境配置
主机 | 主机名 | 操作系统 | IP 地址 | 主要软件 |
---|---|---|---|---|
Squid-Server | CentOS 7-5 | CentOS 7 | ens33:192.168.126.15、ens36:12.0.0.1 | squid-3.5.28.tar.gz |
Web1 | CentOS 7-4 | CentOS 7 | 12.0.0.12 | httpd |
客户端 | Win10 | Windows | 192.168.126.10 | / |
2.构建步骤
2.1 Web1
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/sysconfig/network-scripts/ifcfg-ens33
#修改网卡配置中的 IP、子网掩码及网关
systemctl restart network
#注,重启后,远程终端将连接不上,需回到 VMware
ifconfig
yum -y install httpd
systemctl restart httpd.service
2.2 Squid
#关机状态下,添加一块网卡,然后再开机
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-ens36
vim ifcfg-ens33
vim ifcfg-ens36
#具体配置我下面贴图展示
systemctl restart network
ifconfig
添加提供内网服务的IP地址,和支持透明代理选项 transparent
#60行,修改
vim /etc/squid.conf
......
http_access allow all
http_access