ubuntu squid 代理服务器安装配置

安装:

下载安装包 http://pan.baidu.com/s/1mitvwpE

解压 tar -xzvf file.tar.gz

编译:

进入sbin目录  执行

./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-gnuregex --enable-icmp --enable-snmp --enable-default-err-language="Simplify_Chinese" --enable-kill-parent-hack --enable-cache-digests --enable-underscore --enable-poll --enable-async-io=240 --enable-arp-acl --enable-delay-pools --enable-follow-x-forwarded-for --with-large-files --with-default-user=squid

这个过程会花费一些时间。之后执行 make ; make install;

进入 /usr/local/squid/sbin/squid

squid -z   初始化缓存目录

squid reload 重新加载配置

squid restart 重新启动

squid -k parse 检查squid.conf 配置文件,如有错误会提示

squid -N -d1 前台启动,打印启动信息

squid -s 后台启动,并存储启动日志

squid -k shutdown 停止服务

 

ok,检查本地访问:

切换至squid/bin目录,执行 squidclient www.sina.com  查看返回信息。

 

配置文件:

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 cao src xx.xx.xx.xx   #cao是名字 随便起   后是允许的ip


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

http_access deny !Safe_ports

http_access allow cao  #允许上边定义的cao地址

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

http_access allow all

http_port xx.xx.xx.xx:xx #服务器地址和设置一个任意端口号,默认3128

cache_dir ufs /usr/local/squid/var/cache/squid 100 16 256

coredump_dir /usr/local/squid/var/cache/squid


dns_nameservers 114.114.114.114  #dns

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

 

最后附上配置详解:

#acl all src 0.0.0.0/0.0.0.0 and http_access allow all选项定义了一个访问控制列表。详细情况参见和Squid软件
#携带的文档。这里的访问控制列表允许所有对代理服务的访问,因为这里该代理是加速web服务器。
acl all src 0.0.0.0/0.0.0.0                 #允许所有IP访问
acl manager proto http                 #manager url协议为http
acl localhost src 127.0.0.1/255.255.255.255  #允午本机IP
acl to_localhost dst 127.0.0.1                 #允午目的地址为本机IP
acl Safe_ports port 80                # 允许安全更新的端口为80
acl CONNECT method CONNECT        #请求方法以CONNECT
http_access allow all                #允许所有人使用该代理.因为这里是代理加速web服务器
http_reply_access allow all                #允许所有客户端使用该代理

acl OverConnLimit maxconn 16        #限制每个IP最大允许16个连接,防止攻击
http_access deny OverConnLimit

icp_access deny all                        #禁止从邻居服务器缓冲内发送和接收ICP请求.
miss_access allow all                #允许直接更新请求
ident_lookup_access deny all                                #禁止lookup检查DNS
http_port 8080 transparent                                #指定Squid监听浏览器客户请求的端口号。

hierarchy_stoplist cgi-bin ?                #用来强制某些特定的对象不被缓存,主要是处于安全的目的。
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY

cache_mem 1 GB        #这是一个优化选项,增加该内存值有利于缓存。应该注意的是:
                     #一般来说如果系统有内存,设置该值为(n/)3M。现在是3G 所以这里1G
fqdncache_size 1024        #FQDN 高速缓存大小
maximum_object_size_in_memory 2 MB        #允许最大的文件载入内存

memory_replacement_policy heap LFUDA  #动态使用最小的,移出内存cache
cache_replacement_policy heap LFUDA         #动态使用最小的,移出硬盘cache

cache_dir ufs /home/cache 5000 32 512  #高速缓存目录 ufs 类型使用的缓冲值最大允午1000MB空间,
#32个一级目录,512个二级目录

max_open_disk_fds 0                                 #允许最大打开文件数量,0 无限制
minimum_object_size 1 KB                         #允午最小文件请求体大小
maximum_object_size 20 MB                 #允午最大文件请求体大小

cache_swap_low 90                            #最小允许使用swap 90%
cache_swap_high 95                            #最多允许使用swap 95%

ipcache_size 2048                                # IP 地址高速缓存大小 2M
ipcache_low 90                                #最小允许ipcache使用swap 90%
ipcache_high 95                                  #最大允许ipcache使用swap 90%


access_log /var/log/squid/access.log squid        #定义日志存放记录
cache_log /var/log/squid/cache.log squid
cache_store_log none                        #禁止store日志

emulate_httpd_log on        #将使Squid仿照Web服务器的格式创建访问记录。如果希望使用
                                #Web访问记录分析程序,就需要设置这个参数。

refresh_pattern . 0 20% 4320 override-expire override-lastmod reload-into-ims ignore-reload   #更新cache规则

acl buggy_server url_regex ^http://.... http://          #只允许http的请求
broken_posts allow buggy_server

acl apache rep_header Server ^Apache                 #允许apache的编码
broken_vary_encoding allow apache

request_entities off                                        #禁止非http的标分准请求,防止攻击
header_access header allow all                        #允许所有的http报头
relaxed_header_parser on                                #不严格分析http报头.
client_lifetime 120 minute                                #最大客户连接时间 120分钟

cache_mgr sky@test.com                        #指定当缓冲出现问题时向缓冲管理者发送告警信息的地址信息。

cache_effective_user squid                        #这里以用户squid的身份Squid服务器
cache_effective_group squid

icp_port 0                       #指定Squid从邻居服务器缓冲内发送和接收ICP请求的端口号。
                     #这里设置为0是因为这里配置Squid为内部Web服务器的加速器,
                     #所以不需要使用邻居服务器的缓冲。0是禁用

# cache_peer 设置允许更新缓存的主机,因是本机所以127.0.0.1
cache_peer 127.0.0.1 parent 80 0 no-query default multicast-responder no-netdb-exchange
cache_peer_domain 127.0.0.1                                 
hostname_aliases 127.0.0.1

error_directory /usr/share/squid/errors/Simplify_Chinese        #定义错误路径

always_direct allow all                # cache丢失或不存在是允许所有请求直接转发到原始服务器
ignore_unknown_nameservers on        #开反DNS查询,当域名地址不相同时候,禁止访问
coredump_dir  /var/log/squid                 #定义dump的目录

max_filedesc 2048                #最大打开的文件描述

half_closed_clients off        #使Squid在当read不再返回数据时立即关闭客户端的连接。
                                #有时read不再返回数据是由于某些客户关闭TCP的发送数据
                                #而仍然保持接收数据。而Squid分辨不出TCP半关闭和完全关闭。

buffered_logs on #若打开选项“buffered_logs”可以稍稍提高加速某些对日志文件的写入,该选项主要是实现优化特性。

#防止天涯盗链,转嫁给百度
acl tianya referer_regex -i tianya
http_access deny tianya
deny_info  tianya
#阻止baidu蜘蛛
acl baidu req_header User-Agent Baiduspider
http_access deny baidu
#限制同一IP客户端的最大连接数
acl OverConnLimit maxconn 128
http_access deny OverConnLimit

#防止被人利用为HTTP代理,设置允许访问的IP地址
acl myip dst 222.18.63.37
http_access deny !myip

#允许本地管理
acl Manager proto cache_object
acl Localhost src 127.0.0.1 222.18.63.37
http_access allow Manager Localhost
cachemgr_passwd 53034338 all
http_access deny Manager

#仅仅允许80端口的代理
acl all src 0.0.0.0/0.0.0.0
acl Safe_ports port 80 # http
http_access deny !Safe_ports
http_access allow all

#Squid信息设置
visible_hostname happy.swjtu.edu.cn
cache_mgr  ooopic2008@qq.com

#基本设置
cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65535 bytes

#2.6的反向代理加速配置
cache_peer 127.0.0.1 parent 80 0 no-query originserver

#错误文档
error_directory /usr/local/squid/share/errors/Simplify_Chinese

#单台使用,不使用该功能
icp_port 0

hierarchy_stoplist cgi-bin ?

acl QUERY urlpath_regex cgi-bin \? .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY

acl apache rep_header Server ^Apache
broken_vary_encoding allow apache


refresh_pattern ^ftp:           1440 20%     10080
refresh_pattern ^gopher:        1440 0%    1440
refresh_pattern .             0    20%     4320

cache_store_log none
pid_filename /usr/local/squid/var/logs/squid.pid
emulate_httpd_log on
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log combined
coredump_dir /usr/local/squid/var/cache
cache_dir ufs /usr/local/squid/var/cache 10000 16 256

dns_children 32
hosts_file /etc/hosts

cache_mem 400 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 32768 KB
maximum_object_size_in_memory 4096 KB
emulate_httpd_log on


#防止盗链
acl picurl url_regex -i \.bmp$ \.png$ \.jpg$ \.gif$ \.jpeg$
acl mystie1 referer_regex -i happy.swjtu.edu.cn
http_access allow mystie1 picurl
acl nullref referer_regex -i ^$
http_access allow nullref
acl hasref referer_regex -i .+
http_access deny hasref picurl

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是Squid代理服务器配置与管理实验小结。 Squid是一款功能强大的代理服务器软件,可以实现缓存、反向代理、访问控制等功能。在Linux系统中,我们可以通过安装Squid软件包来搭建代理服务器。 下面是Squid代理服务器配置与管理实验小结: 1. 安装Squid软件包 在Linux系统中,我们可以使用包管理器来安装Squid软件包。例如,在Ubuntu系统中,可以使用以下命令来安装Squid: ``` sudo apt-get install squid ``` 2. 配置Squid代理服务器 Squid代理服务器配置文件为/etc/squid/squid.conf。在这个文件中,我们可以配置代理服务器的缓存设置、访问控制、反向代理等功能。 例如,我们可以通过以下配置来设置Squid代理服务器的缓存大小为1GB: ``` cache_dir ufs /var/spool/squid 1000 16 256 ``` 3. 启动Squid代理服务器 启动Squid代理服务器非常简单,只需要使用以下命令即可: ``` sudo service squid start ``` 4. 管理Squid代理服务器Squid代理服务器运行期间,我们可以通过以下命令来管理代理服务器: - 停止代理服务器:sudo service squid stop - 重启代理服务器:sudo service squid restart - 查看代理服务器状态:sudo service squid status 另外,我们还可以使用Squid提供的命令行工具来管理代理服务器,例如: - 清除缓存:sudo squid -k shutdown && sudo rm -rf /var/spool/squid/* - 查看缓存统计信息:sudo squidclient -p 3128 mgr:info 以上是Squid代理服务器配置与管理实验小结,希望对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值