squid服务

· squid介绍

squid(squid cache):一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器

· squid代理

正向代理

正向代理分为:
标准代理:指明代理服务器的IP地址和端口号
透明代理:不指明代理服务器的IP地址和端口号

反向代理

反向代理:承担原始WEB服务器的静态页面的请求,防止原始服务器过载

· squid部署

一、正向代理

标准正向代理

1.安装squid服务

[root@xiudaochengxian ~]# yum -y install squid
Complete!

2.添加一块网卡
在这里插入图片描述
添加一块网卡(桥接模式)
网卡1 IP:192.168.1.105
网卡2 IP:192.168.1.2

3.ping外网和内网

[root@xiudaochengxian ~]# 
[root@xiudaochengxian ~]# ping -c4 baidu.com
PING baidu.com (220.181.38.251) 56(84) bytes of data.
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=38 time=51.9 ms
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=2 ttl=38 time=74.5 ms
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=3 ttl=38 time=92.3 ms
64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=4 ttl=38 time=57.5 ms

--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3010ms
rtt min/avg/max/mdev = 51.998/69.129/92.396/15.791 ms

[root@xiudaochengxian ~]# ping -c4 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
64 bytes from 192.168.10.1: icmp_seq=1 ttl=254 time=3.68 ms
64 bytes from 192.168.10.1: icmp_seq=2 ttl=254 time=4.52 ms
64 bytes from 192.168.10.1: icmp_seq=3 ttl=254 time=8.05 ms
64 bytes from 192.168.10.1: icmp_seq=4 ttl=254 time=76.2 ms

--- 192.168.10.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3010ms
rtt min/avg/max/mdev = 3.683/23.128/76.253/30.715 ms

4.客户端测试
这里用的是Windows server 2012 r2
网卡是仅主机模式,连不上外网

打开浏览器点开internet选项—>连接选项—>局域网设置

在这里插入图片描述
在这里插入图片描述

透明正向代理

1.安装squid

[root@xiudaochengxian ~]# yum -y install squid
Complete!

2.编辑squid主配置文件(第59行,62行)

[root@xiudaochengxian ~]# vim /etc/squid/squid.conf
 59 http_port 3128 transparent					#transparent:透明的
 62 cache_dir ufs /var/spool/squid 100 16 256	#设置缓存路径

3.编辑转发配置文件
添加一行

[root@xiudaochengxian ~]# vim /etc/sysctl.conf 
 11 net.ipv4.ip_forward=1			#开启ip转发

4.让转发参数立即生效

[root@xiudaochengxian ~]# sysctl -p
net.ipv4.ip_forward = 1

5.清空防火墙

[root@xiudaochengxian ~]# iptables -F

6.写入防火墙策略

[root@xiudaochengxian ~]# iptables -t nat -A POSTROUTING -p udp --dport 53 -o ens33 -j MASQUERADE 
#-t nat -A POSTROUTING    	路由后做net的方式(SNAT技术)
#-p udp--dport 53			转发udp协议53端口号的流量
#-o ens33					通过连外网的网卡进行转发
#-j MASQUERADE				伪装技术

7.将网站80端口请求转发到3128端口上

[root@xiudaochengxian ~]# iptables -t nat -A POSTROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
[root@xiudaochengxian ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ens33 -j SNAT 192.168.1.105				#桥接网卡IP地址

8.使squid服务生效
先停止squid服务

[root@xiudaochengxian ~]#systemctl stop squid

检测拼写错误

[root@xiudaochengxian ~]# squid -k parse
2021/08/04 21:15:24| Initializing https proxy context		#网站代理服务成功

新建缓存目录(16个)
这里就不展示了,总共有16个目录

[root@xiudaochengxian ~]# squid -Z

9.重启squid服务

[root@xiudaochengxian ~]#systemctl restart squid

二、反向代理

1.安装squid服务

[root@xiudaochengxian ~]# yum -y install squid
Complete!

2.编辑squid主配置文件(第59行,60行)
格式:
59 http_port 桥接网卡IP地址:80 vhost
60 cache_peer 网站源服务器IP地址 parent 80 0 orginserver

[root@xiudaochengxian ~]# vim /etc/squid/squid.conf
59 http_port 192.168.1.105:80 vhost
60 cache_peer 47.110.217.22 parent 80 0 originserver

3.重启squid服务并加入开机启动项

[root@xiudaochengxian ~]#systemctl restart squid
[root@xiudaochengxian ~]#systemctl enable squid

4.客户端测试
输入本机IP就可以访问网站,这里就不展示了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值