CentOS 6.5下Squid代理服务器的安装与配置

CentOS 6.5下Squid代理服务器的安装与配置

一、系统环境

操作系统:CentOS release 6.5 

Squid版本:squid-3.1.10-20.el6_5.3.x86_64

SELINUX=disabled

HTTP Service: stoped

二、安装Squid服务

2.1 检查squid软件是否安装

# rpm -qa|grep squid

2.2 如果未安装,则使用yum 方式安装

# yum -y install squid

2.3 设置开机自启动

# chkconfig --level 35 squid on             //在3、5级别上自动运行squid服务

三、squid服务器的配置文件说明

squid 的主配置文件是 /etc/squid/squid.conf,所有squid的设定都是在这个文件里配置

 

http_port 3128      //设置监听的IP与端口号
cache_mem 64 MB      //额外提供给squid使用的内存,squid的内存总占用为 X * 10+15+“cache_mem”,其中X为squid的cache占用的容量(以GB为单位),
               //比如下面的cache大小是100M,即0.1GB,则内存总占用为0.1*10+15+64=80M,推荐大小为物理内存的1/3-1/2或更多。              
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 100 16 256   //定义squid的cache存放路径 、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量
logformat combined %&gt;a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}&gt;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%时,开始清理旧的
cachecache_swap_low 90   //cache目录清理到90%时停止。
acl localnet src 192.168.1.0/24  //定义本地网段
http_access allow localnet  //允许本地网段使用
http_access deny all  //拒绝所有
visible_hostname squid.david.dev  //主机名
cache_mgr mchina_tang@qq.com  //管理员邮箱

 

四、普通代理服务

4.1 编辑squid 主配置文件/etc/squid/squid.conf

 

 

#

# Recommended minimum configuration:

#

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

# Example rule allowing access from your local networks.

# Adapt to list your (internal) IP networks from where browsing

# should be allowed

acl localnet src 10.0.0.0/8     # RFC1918 possible internal network

acl localnet src 172.16.0.0/12  # RFC1918 possible internal network

acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

acl localnet src fc00::/7       # RFC 4193 local private network range

acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443

acl Safe_ports port 80          # http

acl Safe_ports port 21          # ftp

acl Safe_ports port 443         # https

acl Safe_ports port 70          # gopher

acl Safe_ports port 210         # wais

acl Safe_ports port 1025-65535  # unregistered ports

acl Safe_ports port 280         # http-mgmt

acl Safe_ports port 488         # gss-http

acl Safe_ports port 591         # filemaker

acl Safe_ports port 777         # multiling http

acl CONNECT method CONNECT

#

# Recommended minimum Access Permission configuration:

#

# Only allow cachemgr access from localhost

http_access allow manager localhost

http_access deny manager

# Deny requests to certain unsafe ports

http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports

http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent

# web applications running on the proxy server who think the only

# one who can access services on "localhost" is a local user

#http_access deny to_localhost

#

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

#

# Example rule allowing access from your local networks.

# Adapt localnet in the ACL section to list your (internal) IP networks

# from where browsing should be allowed

http_access allow localnet

http_access allow localhost

# And finally deny all other access to this proxy

http_access allow all

# 我的设置是 http_access allow all 上面句是静止的

# Squid normally listens to port 3128

http_port 3128

# We recommend you to use at least the following line.

hierarchy_stoplist cgi-bin ?

cache_mem 512 MB

# Uncomment and adjust the following to add a disk cache directory.

cache_dir ufs /var/spool/squid 20480 16 256

cache_log /var/log/squid/cache.log

cache_access_log /var/log/squid/access.log

cache_store_log /var/log/squid/store.log

visible_hostname 192.168.3.34

cache_mgr ops@xuexibao.cn

# Leave coredumps in the first cache dir

coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.

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

4.2 初始化

# squid –z

4.3 防火墙配置

用编辑器打开/etc/sysconfig/iptables ,添加开放端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT

[root@localhost ~]# service iptables restart

4.4 启动Squid

# /etc/init.d/squid start

 

五、在路由器中映射本机IP至端口的固定IP,测试代理服务

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值