您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > linux65-squid代理服务器
一:安装squid按top设置好各个设备的ip地址1:共享软件夹soft012:将squid从共享目录中拷贝到linux中[root@s2src]#mkdir/aaa[root@s2src]#mount-ousername=administrator//172.16.1.100/soft01/aaa[root@s2src]#cd/aaa[root@s2src]#cp*/usr/src[root@s2src]#cd/usr/arc[root@s2src]#tarzxvfsquid-3.4.6.tar.gz[root@s2src]#cdsquid-3.4.63:配置安装参数[root@s2squid-3.4.6]#./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-gnuregex4:编译并安装[root@s2squid-3.4.6]#make&&makeinstall[root@s2squid-3.4.6]#ln-s/usr/local/squid/sbin/*/usr/local/sbin/[root@s2squid-3.4.6]#useradd-M-s/sbin/nologinsquid\\M:不建立宿主目录[root@s2squid-3.4.6]#chown-Rsquid:squid/usr/local/squid/var/4:编辑配置文件[root@s2~]#vi/etc/squid.conf添加下面两行(可以放在末尾)cache_effective_usersquid\\指定squid程序的用户cache_effective_groupsquid\\指定squid账号的基本组5:检查配置结果[root@s2~]#squid-kparse\\检查配置文件的语法是否正确[root@s2~]#squid-z\\初始化缓存目录[root@s2~]#squid\\启动squid服务[root@s2~]#netstat-anpt|grepsquid6:使用squid服务脚本[root@s2~]#vi/etc/init.d/squid输入以下内容#!/bin/bash#chkconfig:23459025#config:/etc/squid.conf#pidfile:/usr/local/squid/var/run/squid.pid#description:squid-internetobjectcache.PID=usr/local/squid/var/run/squid.pidCONF=/etc/squid.confCMD=/usr/local/squid/sbin/squidcase$1instart)netstat-anpt|grepsquid&/dev/nullif[$?-eq0]thenechosquidisrunningelseecho正在启动squid……..$CMDfi;;stop)$CMD-kkill&/dev/nullrm-rf$PID&/dev/null;;status)[-f$PID]&/dev/nullif[$?-eq0]thennetstat-anpt|grepsquidelseechosquidisnotrunningfi;;restart)$0stop&/dev/nullecho正在关闭squid……$0start&/dev/nullecho正在启动squid……;;reload)$CMD-kreconfigure;;check)$CMD-kparse;;*)echo用法:$0{start|stop|restart|reload|check|status};;esac将squid添加为系统服务[root@s2init.d]#chmod+x/etc/init.d/squid[root@s2init.d]#chkconfig--addsquid[root@s2init.d]#chkconfigsquidon二:传统代理将web,squid,和客户端都桥接到同一个网卡上1:修改配置文件[root@s2~]#vi/etc/squid.conf添加reply_body_max_size10MB\\下载文件的大小限制http_accessallowall\\放在http_accessdenyall前面2:在防火墙上添加允许策略[root@s2~]#iptables-IINPUT-ptcp--dport3128-jACCEPT[root@s2~]#serviceiptablessave[root@s2~]#servicesquidreload3:设置客户端a:windows客户端b:linux客户端vim/etc/profile添加如下内容HTTP_PROXY====192.168.1.,192.168.4.exportHTTP_PROXYHTTPS_PROXYFTP_PROXYNO_PROXY测试:客户端上访问网站,关掉squid的network后再访问。三:透明代理再为squid服务器添加一个网卡:设置ip地址为192.168.4.1,并修改客户端的ip地址:192.168.4.110将web服务器和squid的eth0桥接到vm1,将squid的eth1和客户端桥接到vm1:修改配置文件以支持透明代理[root@s2~]#vi/etc/squid.conf找到http_port3128这一行,将其修改为http_port192.168.4.1:3128transparent[root@s2~]#servicesquidreload\\重启squid服务2:设置iptables重定向策略[root@s2~]#iptables-tnat-IPREROUTING-ieth1-s192.168.10.0/24-ptcp--dport80-jREDIRECT--to3128[root@s2~]#iptables-tnat-IPREROUTING-ieth1-s192.168.10.0/24-ptcp--dport443-jREDIRECT--to3128[root@s2~]#serviceiptablessave3:客户端设置a:windows客户端验证透明代理,将代理服务器的钩去掉,并保存设置,设置其网关为squid的eth1的ip地址,然后访问web服务无法访问重启squid服务在试[root@localhost~]#tail/usr/local/squid/var/logs/access.log四:ACL访问控制1:查看acl[root@s2~]#vi/etc/squid.confacllocalnetsrc10.0.0.0/8#RFC1918possibleinternalnetworkacllocalnetsrc172.16.0.0/12#RFC1918possibleinternalnetworkacllocalnetsrc192.168.0.0/16#RFC1918possibleinternalnetworkacllocalnetsrcfc00::/7#RFC4193localprivatenetworkrangeacllocalnetsrcfe80::/10#RFC4291link-local(directlyplugged)machinesaclSSL_portsport443aclSafe_portsport80#httpaclSafe_portsport21#ftpaclSafe_portsport443#httpsaclSafe_portsport70#gopheraclSafe_portsport210#waisaclSafe_portsport1025-65535#unregisteredportsaclSafe_portsport280#http-mgmtaclSafe_portsport488#gss-http2:源ip为控制条件修改acllocalnetsrc192.168.0.0/16#RFC1918possibleinternalnetwork为aclaaasrc192.168.0.0/16#RFC1918possibleinternalnetwork在acl列的末尾添加http_accessdenyaaa[root@s2~]#servicesquidreload测试客户端还能否访问web服务(测试过后再改回来,便于后续实验)客户端可以清空一下缓存,避免不出效果3:黑名单文件作为控制条件[root@s2~]#vi/etc/squid.conf修改acllocalnetsrc192.168.0.0/16#RFC1918possibleinternalnetwork为aclMYLANsrc192.168.0.0/16#RFC1918possibleinternalnetwork针对目标ip建立黑名单[root@s2~]#mkdir/etc/squid[root@s2~]#cd/etc/squid[root@s2squid]#viipblock.list添加172.16.16.172[root@s2squid]#vidmblock.list添加qq.com[root@s2~]#vi/etc/squid.conf添加(在acl列表的末尾,放在http_accessallow前面)aclIPBLOCKdst/etc/squid/ipblock.listaclDMBLOCKdstdomain/etc/squid/dmblock.listhttp_accessdenyMYLANIPBLOCKhttp_accessdenyMYLANDMBLOCK[root@s2~]#servicesquidreload4:测试日志三、squid日志分析1、安装GD库[root@s2~]#yum-yinstallgd将gd-devel拷贝至usr/src中[root@s2~]#cd/usr/src[root@s2src]#yum-yinstallgd-devel-2.0.35-11.el6.x86_64.rpm2、安装sarg[root@s2~]#cd/usr/src[root@s2src]#tarzxvfsarg-2.3.7.tar.gz[root@s2src]#cdsarg-2.3.7[root@s2sarg-2.3.7]#./configure--prefix=/usr/local/sarg--sysconfdir=/etc/sarg--enable-extraprotection&&make&&makeinstall3、配置[root@s2~]#cd/etc/sarg/[root@s2sarg]#vimsarg.conf里面要改的东西较多,可以删掉sarg.conf,在创建一个将红色部分的内容复制进去[root@s2sarg]#grep-v^#/etc/sarg/sarg.conf|grep-v^$7access_log/usr/local/squid/var/logs/access.log25titleSquidUserAccessReports120output_dir/var/
本文标题:linux65-squid代理服务器
链接地址:https://www.777doc.com/doc-2888438 .html