Squid快速入门(yum安装)

加油站代理服务器

前言

  Squid是一个Linux系统下优秀的代理服务器软件。Squid可以配置普通上网代理(正向代理)、反向代理、透明代理。Squid接收用户的下载申请,并自动处理所下载的数据。当一个用户想要下载一个主页时,可以向 Squid 发出一个申请,要 Squid 代替其进行下载,然后 Squid 连接所申请网站并请求该主页,接着把该主页传给用户同时保留一个备份,当别的用户申请同样的页面时,Squid 把保存的备份立即传给用户。

       按照代理类型的不同,可以将 Squid 代理分为正向代理和反向代理,正向代理中,根据实现方式的不同,又可以分为普通代理和透明代理。

  • 普通代理:需要客户机在浏览器中指定代理服务器的地址、端口。
  • 透明代理:适用于企业的网关主机(共享接入 Internet)中,客户机不需要指定代理服务器地址、端口等信息,代理服务器需要设置防火墙策略将客户机的 Web 访问数据转交给代理服务程序处理。
  • 反向代理:是指以代理服务器来接受 Internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 Internet 上请求连接的客户端,此时代理服务器对外就表现为一个服务器。

环境与需求

环境

所有加油站均可以连接内网,为10.0.0.0/8网段内。

省内所有加油站通过代理访问【https://yyt.etcsd.com/ltk

本例:

系统:CentOS6.5。

[root@uu ~]# uname -an

Linux uu 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

配置模式为普通上网代理(正向代理)。

Squid主机IP为110.225.11.206。

 

 

系统优化

 

hostname zhang

 

/etc/init.d/iptables stop

chkconfig iptables off

> /etc/issue

 

cd /etc/yum.repos.d/

wget http://mirrors.neusoft.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

sed -i 's#$releasever#6.5#g' CentOS6-Base-163.repo

 

echo 'export LC_ALL=C'>> /etc/profile

echo $LC_ALL

source /etc/profile

cd ~

yum install lrzsz tree lsof -y

setenforce 0

getenforce

 

echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1'>>/var/spool/cron/root

chkconfig --list | awk '{print $1}' |grep -Ev "sshd|network|rsyslog|crond|sysstat"|sed -r 's#(.*)#chkconfig \1 off#g'|bash

chkconfig --list |grep 3:on

exit

 

 

vi /etc/sysconfig/i18n --?LANG="zh_CN.UTF-8"

.  /etc/sysconfig/i18n  

 

yum方法

安装

yum安装

注释:版本较低,不易控制。

yum install squid -y

chkconfig --level 35 squid on 

cp /etc/squid/squid.conf /etc/squid/squid.conf.bak

 

配置

> /etc/squid/squid.conf

vim /etc/squid/squid.conf

 

http_port 3128

cache_mem 256 MB 

max_filedescriptors 10240

maximum_object_size 4 MB   //设置squid磁盘缓存最大文件,超过4M的文件不保存到硬盘

minimum_object_size 0 KB   //设置squid磁盘缓存最小文件

maximum_object_size_in_memory 4096 KB   //设置squid内存缓存最大文件,超过4M的文件不保存到内存

cache_dir ufs /var/spool/squid 1024 16 256   //定义squid的cache存放路径 、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh        //log文件日志格式

access_log /var/log/squid/access.log combined  //log文件存放路径和日志格式

cache_log /var/log/squid/cache.log   //设置缓存日志

logfile_rotate 60   //log轮循 60天

cache_swap_high 95  //cache目录使用量大于95%时,开始清理旧的cache

cache_swap_low 90   //cache目录清理到90%时停止。

acl manager proto cache_object

acl localhost src 127.0.0.1/32 ::1

acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

acl localnet src 10.0.0.0/8     # RFC1918 possible internal network

acl SSL_ports port 443

acl Safe_ports port 80          # http

acl Safe_ports port 443         # https

acl CONNECT method CONNECT

acl http proto HTTP

acl good_domain dstdomain yyt.etcsd.com

http_access allow manager localhost

http_access allow http good_domain

http_access deny http !good_domain

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow all

coredump_dir /var/spool/squid

refresh_pattern ^ftp:           1440    20%     10080

refresh_pattern ^gopher:        1440    0%      1440

refresh_pattern -i (/cgi-bin/|\?) 0     0%      0

refresh_pattern .               0       20%     4320

visible_hostname zhang

cache_mgr 15666661331@163.com

 

初始化和启动

killall squid

squid -k parse

squid -z

service squid start

netstat -ntpl

#############################注释:##############################

squid -z    #初始化缓存目录,squid新版本3.1可以省略

/etc/init.d/squid start    #启动squid服务

squid  -k check    #可以检测配置文件是否有错;可以简写为-kche

squid -k rec    #可以重新加载配置,reconfig的简写;

service squid restart    #重启squid服务;重启经常性的很慢,可以先killall squid,在启动服务;

netstat -ntpl      #查看端口是否打开:

 

在windows上设置代理

打开IE -> 工具 -> Internet选项 -> 连接 -> 局域网设置。勾选代理服务器下面的方格。设置地址为squid代理服务器IP,端口为3128。

posted @ 2018-01-23 15:54  Cmelo  阅读(2938)  评论(0编辑  收藏  举报