准备三台设备
centos7 --- http服务 --- 192.168.254.11
centos7 --- 代理服务器 --- 192.168.254.22
win10 --- 测试 --- 192.168.254.3
先测试不通过代理能否正常访问
没问题
基础配置
squid : Optimising Web Delivery (squid-cache.org)
去官网下载源码包
yum -y install gcc-c++ perl*
tar xf squid-3.5.23.tar.gz -C /usr/src
cd /usr/src/squid-3.5.23/
./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-linux-netfilter --enable--linux-tproxy --enable-async-io=240 --enable-default-err-language=Simplify_Chinese --disable-poll --enable-epoll --enable-gnuregex
make && make install
# 时间长,耐心等待
ln -s /usr/local/squid/sbin/* /usr/local/sbin/
useradd -M -s /sbin/nologin squid
chown -R squid:squid /usr/local/squid/var/
sed -i '/^http_port/a cache_effective_user squid\ncache_effective_group squid' /etc/squid.conf
squid -k parse
squid -z
squid
# 启动服务
netstat -anpt | grep "squid"
kill -9 后面的进程号 ,可以关闭此服务
优化启动项
如果你觉得这样关闭的话很不方便可以使用
vi /etc/init.d/squid
写入
#!/bin/bash # chkconfig: 35 90 25 # config file:/etc/squid.conf # Description: squid - internet object cache. PID="/usr/local/squid/var/run/squid.pid" CONF="/etc/squid.conf" CMD="/usr/local/squid/sbin/squid" case "$1" in start) netstat -utpln |grep squid &>/dev/null if [ $? -eq 0 ];then echo "squid is running." else echo "squid is starting." $CMD fi ;; stop) $CMD -k kill &>/dev/null rm -rf $PID &>/dev/null echo "squid is stoped." ;; status) [ -f $PID ] &>/dev/null if [ $? -eq 0 ];then netstat -anpt |grep squid else echo "squid is not running" &&/bin/false fi ;; restart) $0 stop $0 start ;; reload) $CMD -k reconfigure ;; check) $CMD -k parse ;; *) echo "Usage:$0 {start|stop|restart|reload|check|status}" exit 1 ;; esac
chmod +x /etc/init.d/squid
chkconfig --add squid
systemctl restart squid
配置传统代理服务器
sed -i '55ahttp_access allow all' /etc/squid.conf
##设置acl策略为允许所有,必须在deny前
sed -i '59areply_body_max_size 10 MB' /etc/squid.conf
##允许下载最大文件大小为10M
/etc/init.d/squid reload
# 如果你没做上面的优化脚本那么这步可以使用kill代替
测试
在win10上
运行--》inetcpl.cpl--》链接--》局域网--》代理:192.168.10.1 --》3128
我们的192.168.254.3代理192.168.254.22,192.168.254.22访问的192.168.254.11
代理访问的同时。还会缓存下来,会加快接下来的重复访问