千家信息网

squid传统代理和透明代理

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,缓存代理概述web代理的工作机制:缓存网页对象,减少重复请求代理的基本类型传统代理:适用于Internet,需明确指定服务端透明代理:客户机不需要指定代理服务器的地址和端口,是通过默认路由,防火墙将w
千家信息网最后更新 2025年02月04日squid传统代理和透明代理

缓存代理概述

web代理的工作机制:缓存网页对象,减少重复请求

代理的基本类型

传统代理:适用于Internet,需明确指定服务端透明代理:客户机不需要指定代理服务器的地址和端口,是通过默认路由,防火墙将web重定向给代理

使用代理的好处

提高web访问速度隐藏客户机的真实IP地址

一,传统代理

实验环境

squid服务器 192.168.13.179web服务器 192.168.13.151client测试机192.168.13.135

1,在squid服务器上安装squid代理服务器

[root@squid ~]# mkdir /abc[root@squid ~]# mount.cifs //192.168.100.3/LNMP-C7 /abc/   ##挂载[root@squid ~]# cd /abc/[root@squid abc]# tar zxvf squid-3.4.6.tar.gz -C /opt  ##解压[root@squid abc]# yum install gcc gcc-c++ make -y  ##安装环境组件[root@squid abc]# cd /opt/squid-3.4.6[root@squid squid-3.4.6]# ./configure \--prefix=/usr/local/squid \  ##安装路径--sysconfdir=/etc \   ##配置文件目录--enable-arp-acl \   ##支持acl访问控制列表--enable-linux-netfilter \   ##支持网络筛选--enable-linux-tproxy \   ##支持透明--enable-async-io=100 \   ##io优化--enable-err-language="Simplify_Chinese" \   ##报错显示简体中文--enable-underscore \--enable-poll \--enable-gnuregex   ##支持正则表达[root@squid squid-3.4.6]# make && make install   ##编译安装[root@squid squid-3.4.6]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/  ##便于系统识别[root@squid squid-3.4.6]# useradd -M -s /sbin/nologin squid   ##创建系统用户[root@squid squid-3.4.6]# chown -R squid.squid /usr/local/squid/var/  ##给目录所有文件属主属组权限

2,修改squid配置文件,并优化启动项

[root@squid squid-3.4.6]# vim /etc/squid.conf   ##修改squid配置文件# And finally deny all other access to this proxyhttp_access allow all   ##添加此项#http_access deny all ##注释,允许终端访问# Squid normally listens to port 3128http_port 3128cache_effective_user squid   ##指定用户squidcache_effective_group squid ##指定组[root@squid squid-3.4.6]# squid -k parse ##检查配置文件语法[root@squid squid-3.4.6]# squid -z  ##初始化缓存目录[root@squid squid-3.4.6]# squid  ##开启服务[root@squid squid-3.4.6]# netstat -ntap | grep 3128  ##查看squid端口[root@squid squid-3.4.6]# cd /etc/init.d/[root@squid init.d]# vim squid    ##编辑service启动squid的脚本#!/bin/bash#chkconfig: 2345 90 25PID="/usr/local/squid/var/run/squid.pid"   ##PID文件进程号CONF="/etc/squid.conf"   ##主配置文件CMD="/usr/local/squid/sbin/squid"   ##启动命令case "$1" instart)                netstat -ntap | grep squid &> /dev/null                if [ $? -eq 0 ]                then                  echo "squid is running"                 else                 echo "正在启动 squid...."                  $CMD                fi                ;;stop)                $CMD -k kill &> /dev/null   ##关闭squid                rm -rf $PID &> /dev/null    ##删除PID文件                ;;status)                [ -f $PID ] &> /dev/null                 if [ $? -eq 0 ]                                then                                 netstat -ntap | grep squid                                else                                 echo "squid is not running"                fi                ;;restart)                $0 stop &> /dev/null                echo "正在关闭 squid..."                $0 start &> /dev/null                echo "正在启动 squid..."                ;;reload)                $CMD -k reconfigure  ##重载配置文件                ;;check)                $CMD -k parse   ##检查语法                ;;*)                echo "用法:$0{start|stop|reload|status|check|restart}"                ;;esac[root@squid init.d]# chmod +x squid   ##给执行权限[root@squid init.d]# chkconfig --add squid   ##添加到service管理中[root@squid init.d]# chkconfig --level 35 squid on  ##开机自启

3,设置传统代理配置

[root@squid init.d]# vim /etc/squid.conf  ##修改主配置文件# Squid normally listens to port 3128http_port 3128cache_mem 64 MB   ##内存空间大小reply_body_max_size 10 MB  ##允许下载最大文件大小maximum_object_size 4096 KB   ##允许保存缓存空间最大对象大小[root@squid init.d]# service squid restart[root@squid init.d]# iptables -L  ##查看表内容[root@squid init.d]# iptables -F  ##清空表缓存[root@squid init.d]# setenforce 0[root@squid init.d]# iptables -I INPUT -p tcp --dport 3128 -j ACCEPT ##允许3128端口[root@squid init.d]# service squid reload  ##重载配置文件

4,在web服务器上安装http服务

[root@web ~]# systemctl stop firewalld.service   ##关闭防火墙[root@web ~]# setenforce 0[root@web ~]# yum install httpd -y  ##安装web服务[root@web ~]# systemctl start httpd.service

使用client访问web网页

[root@web ~]# cd /etc/httpd/logs/  ##查看日志文件[root@web logs]# vim access_log  ##此时是135地址访问的

5,修改客户机浏览器代理设置

##重新利用客户机访问web服务器[root@web ~]# cd /etc/httpd/logs/  ##查看日志文件[root@web logs]# vim access_log  ##此时是179代理服务器访问的

二,透明代理

实验拓扑

实验环境

squid服务器 ens33:192.168.13.184                    ens36:192.168.10.1 (仅主机模式)web服务器 192.168.13.151client 192.168.10.10  (仅主机模式)

1,在squid服务上添加一块网卡,并设置ip地址

[root@squid ~]# cd /etc/sysconfig/network-scripts/[root@squid network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36[root@squid network-scripts]# vim ifcfg-ens36  ##修改ens36ip信息BOOTPROTO=static##删除uuid修改33为36IPADDR=192.168.10.1NETMASK=255.255.255.0  [root@squid network-scripts]# service network restart   ##重启网络服务[root@squid network-scripts]# vim /etc/sysctl.conf   ##开启路由转发net.ipv4.ip_forward=1[root@squid network-scripts]# sysctl -p   ##加载

2,在web服务器上指定静态路由

[root@web ~]# route add -net 192.168.10.0/24 gw 192.168.13.184  ##添加静态路由

3,在squid服务器上设置透明代理

[root@squid network-scripts]# vim /etc/squid.conf   ##设置配置文件http_port 192.168.10.1:3128 transparent   ##设置透明代理cache_effective_user squidcache_effective_group squid[root@squid network-scripts]# service squid stop  ##关闭开启squid服务[root@squid network-scripts]# service squid start[root@squid network-scripts]# iptables -F  ##清空表缓存[root@squid network-scripts]# iptables -t nat -F[root@squid network-scripts]# iptables -t nat -I PREROUTING -i ens36 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to 3128##定义规则入口ens36,80端口重定向到3128[root@squid network-scripts]# iptables -t nat -I PREROUTING -i ens36 -s 192.168.10.0/24 -p tcp --dport 443 -j REDIRECT --to 3128##https443端口[root@squid network-scripts]# iptables -I INPUT -p tcp --dport 3128 -j ACCEPT##允许3128端口访问

4,用测试机测试

5,在web服务器上查看访问日志文件

[root@web ~]# cd /var/log/httpd/[root@web httpd]# vim access_log   ##查看访问日志信息

##此时是184访问的并不是测试机的地址访问的

谢谢阅读!!

服务 代理 文件 服务器 配置 缓存 地址 端口 客户 客户机 日志 路由 支持 测试 传统 大小 正在 环境 目录 测试机 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络安全知识有奖竞答题目 数据库连接池数初始为0 湖北项目软件开发哪家专业 合肥普乐士网络技术 金融软件开发一般用什么语言 我的世界可以无限挖资源的服务器 北京楼控管理软件开发定制 数据库xa 大学网络技术部面试自我介绍 远端服务器回放不了 软件开发后台维护工资 网络安全宣传周自查报告 小飞象解说硬核服务器 安徽易合网络技术有限公司 一台服务器运行多台mysql 新时代国家安全和网络安全 奇零网络技术工作室入驻百家号 安全教案网络安全教学反思 空间数据库的三大特征 服务器内存多少合适 成都桑普德软件开发有限公司 软件开发中心图片 淘宝软件开发框架 saas一般用啥数据库 泰韬网络技术有限公司 永登网络安全周2021 如何理解软件开发的本质是建模 江苏办公系统软件开发多少钱 美服lol服务器 数据库优化技术分析论文
0