标签:sha pad body 转发 查看端口 check 内存 客户 开启
简介:具体实验操作:
squid 192.168.120.128
web 192.168.120.129
squid-3.5.23软件包网址:链接:https://pan.baidu.com/s/1MbswuQi7pmuNj6XAZmmiJg 密码:8xu6
-------------------------手工编译安装squid-------------------------------------
[root@localhost ~]#mkdir /abc
[root@localhost ~]#mount.cifs //192.168.100.1/rhel7 /abc
[root@localhost ~]#cd /abc/Y2C
[root@localhost Y2C]#tar zxvf squid-3.5.23.tar.gz -C /opt/
[root@localhost Y2C]#cd /opt/
[root@localhost opt]# yum install gcc gcc-c++ make -y
----------------------------配置-------------------------------------------------
[root@localhost opt]# cd squid-3.5.23/
[root@localhost squid-3.5.23]# ./configure --prefix=/usr/local/squid \
--sysconfdir=/etc \
--enable-arp-acl \
--enable-linux-netfilter \
--enable-linux-tproxy \
--enable-async-io=100 \
--enable-err-language="Simplify_Chinese" \
--enable-underscore \
--enable-poll \
--enable-gnuregex
[root@localhost squid-3.5.23]# make && make install
[root@localhost squid-3.5.23]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/
[root@localhost squid-3.5.23]# useradd -M -s /sbin/nologin squid
[root@localhost squid-3.5.23]# chown -R squid.squid /usr/local/squid/var/
[root@localhost squid-3.5.23]# vim /etc/squid.conf
#56行
http_access allow all #在http_access deny all上面插入
#61行
cache_effective_user squid #添加 指定程序用户
#62行
cache_effective_group squid #添加 指定账号基本组
[root@localhost squid-3.5.23]# squid -z #初始化缓存目录
[root@localhost squid-3.5.23]# squid #启动服务
[root@localhost squid-3.5.23]# netstat -ntap | grep 3128 #查看端口
tcp6 0 0 :::3128 :::* LISTEN 45271/(squid-1)
[root@localhost squid-3.5.23]# cd /etc/init.d/
[root@localhost init.d]# vim squid
#!/bin/bash
#chkconfig: 2345 90 25
PID="/usr/local/squid/var/run/squid.pid"
CONF="/etc/squid.conf"
CMD="/usr/local/squid/sbin/squid"
case "$1" in
start)
netstat -natp | grep squid &> /dev/null
if [ $? -eq 0 ]
then
echo "squid is running"
else
echo "正在启动 squid..."
$CMD
fi
;;
stop)
$CMD -k kill &> /dev/null
rm -rf $PID &> /dev/null
;;
status)
[ -f $PID ] &> /dev/null
if [ $? -eq 0 ]
then
netstat -natp | 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|status|reload|check|restart}"
;;
esac
------------------------传统代理-------------------------------------------------
[root@localhost init.d]# chmod +x squid
[root@localhost init.d]# chkconfig --add squid
[root@localhost init.d]# chkconfig --level 35 squid on #开机自启动
[root@localhost init.d]# service squid stop #关闭
[root@localhost init.d]# service squid start #开启
[root@localhost init.d]# service squid check #检查语法
[root@localhost init.d]# vim /etc/squid.conf
61 cache_mem 64 MB #指定缓存功能所使用的内存空间大小,便于保持访问比较频繁的WEB
对象,容量最好为4的倍数,单位为MB,建议设为物理内存的1/4
62 reply_body_max_size 10 MB #允许用户下载的最大文件大小(默认为0,不进行限制)
63 maximum_object_size 4096 KB #允许保存到缓存空间的最大对象大小,以KB为单位,超过
大小限制的文件将不被缓存,而是直接转发给用户
[root@localhost init.d]# service squid restart
正在关闭 squid...
正在启动 squid...
[root@localhost init.d]# iptables -F
[root@localhost init.d]# setenforce 0
[root@localhost init.d]# iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
操作完成后,在客户机上访问192.168.120.128
在访问网站前,先设置代理
到web服务器上查看访问来源
客户机查看web的网页可以被squid服务器所代理
==============================================================
----------------------------------------在第二台上操作-----------------------------------------------
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
-------------------------------------------设置透明代理-----------------------------------------------
配置双网卡内网ens33 外网ens36
squid 192.168.100.1 内网 ens33
12.0.0.1 外网 ens36
web 12.0.0.12
client 192.168.100.50
#在web上操作:
[root@localhost logs]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=static
IPADDR=12.0.0.12
NETMASK=255.255.255.0
GATEWAY=12.0.0.1
[root@localhost logs]# service network restart
Restarting network (via systemctl): [ 确定 ]
#代理服务器上
[root@localhost logs]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#vim ifcfg-ens33
IPADDR=192.168.100.1
NETMASK=255.255.255.0
[root@localhost network-scripts]#cp ifcfg-ens33 ifcfg-ens37
[root@localhost network-scripts]#vim ifcfg-ens37
删除uidd
BOOTPROTO=static
NAME=ens37
DEVICE=ens37
IPADDR=12.0.0.1
[root@localhost network-scripts]#service network restart
----------------------------------代理服务器上-------------------------------------------
[root@localhost network-scripts]#echo "1" > /proc/sys/net/ipv4/ip_forward
[root@localhost network-scripts]#iptables -F
[root@localhost network-scripts]#iptables -t nat -F
[root@localhost network-scripts]#setenforce 0
[root@localhost network-scripts]#vim /etc/squid.conf
60 http_port 192.168.100.1:3128 transparent
[root@localhost network-scripts]# iptables -t nat -I PREROUTING -i ens33 -s 192.168.100.0/24 -p tcp --dport 80 -j REDIRECT --to 3128
[root@localhost network-scripts]#iptables -t nat -I PREROUTING -i ens33 -s 192.168.100.0/24 -p tcp --dport 443 -j REDIRECT --to 3128
[root@localhost network-scripts]#service squid reload
用客户机访问12.0.0.12
(关闭代理设置再访问)
访问后到web上
[root@localhost ~]# cd /etc/httpd/
[root@localhost httpd]# cd logs
[root@localhost logs]# ls
access_log error_log
[root@localhost logs]# vim access_log
#squid的传统代理和透明代理就完成了,下一次再介绍squid的日志和反向代理#
标签:sha pad body 转发 查看端口 check 内存 客户 开启
原文地址:http://blog.51cto.com/13756916/2176983