`
ithero
  • 浏览: 146845 次
社区版块
存档分类
最新评论

squid3.0反向代理

阅读更多

apache(81端口)+squid(80端口)(apache和squid跑在同一个机器上面 要实现反向代理 )我将我的外网域名用abc.com代替了

apache简单配置如下:
Listen 81
NameVirtualHost *
<VirtualHost *>
<Directory "/usr/local/www/">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    Satisfy all
</Directory>
    
    ServerName    www.abc.com
    ServerAdmin webadmin@abc.com
    DocumentRoot "/usr/local/www/"
    DirectoryIndex index.jsp
#    ErrorLog "/usr/local/apache/logs/abc-error_log"
#    SetEnvIf Remote_Addr "::1" dontlog
#    CustomLog "/usr/local/apache/logs/abc-access_log" combined env=!dontlog
</VirtualHost>

此时可以通过lsof -i:81查看谁占用81端口
确保http://www.abc.com:81 访问没有问题得到的是/usr/local/www发布的站点

开始squid的安装配置:

wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE2.tar.gz

#useradd squid
#groupadd squid

#tar zxvf squid-3.0.STABLE2.tar.gz 
#cd squid-3.0.STABLE2
#./configure --prefix=/usr/local/squid --disable-carp --with-aufs-threads=32 --with-pthreads --enable-storeio='ufs,aufs,coss,null' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru' --disable-wccp --enable-kill-parent-hack --disable-snmp --disable-poll --disable-select --enable-auth=basic --with-aio --disable-ident-lookup --with-filedescriptors=65536
#make
#make install

可能需要创建一些文件 这些都是配置文件中需要调用的(这个要注意文件的属主和权限)
#cd /usr/local/squid/var/logs/
#touch cache.log
#chmod 755 cache.log 
#chown squid:squid cache.log 
#touch page_zs_access_log
#chmod 755 page_zs_access_log
#chown squid:squid page_zs_access_log

#cd /usr/local/squid/etc/ 
# > squid.conf
# vi squid.conf(211.**.**.**为服务器的ip地址)


visible_hostname www.abc.com
http_port 80 vhost vport 
cache_mem 512 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /tmp 512 16 256
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/squid/var/logs/page_zs_access_log combined
pid_filename /usr/local/squid/var/logs/squid.pid
cache_store_log none
cache_peer 211.**.**.** parent 81 0 no-query no-digest originserver name=www
cache_peer_domain www www.abc.com 
cache_peer_access www allow all
http_access allow all
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe 
cache deny QUERY 
cache_effective_user squid 
cache_effective_group squid

#/usr/local/squid/sbin/squid -k parse
可以根据这个测试命令用来验证squid.conf的语法和配置(下面是OK的如果不OK会有相应的提示根据提示来修改配置文件)
2008/03/19 15:29:48| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)

#/usr/local/squid/sbin/squid -z
用来Creating Swap Directories

vi一个squid.sh的启动脚本如下:赋予可执行权限
#!/bin/sh
#
ulimit -HSn 15000
# this script starts and stops Squid
echo 15000 > /proc/sys/fs/file-max
case "$1" in
start)
          /usr/local/squid/sbin/squid -s
          echo -n ' Squid'
          ;;
stop)
          /usr/local/squid/sbin/squid -k shutdown
          ;;
esac

#./squid.sh start就可以启动squid了(还有测试命令如:/usr/local/squid/sbin/squid -CNd1参考下)

查看有没有启动可以
#ps fax|grep squid
13750 pts/3    S+     0:00                      \_ grep squid
30474 ?        Ss     0:00 /usr/local/squid/sbin/squid -s
30476 ?        S      0:01 \_ (squid) -s
则证明OK

通过命令lsof -i:80查看谁占用了80端口

[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户
219.147.203.146 - - [19/Mar/2008 14:48:54] "GET http://www.abc.com/images/ckt/chuank_11.gif HTTP/1.1" 200 1100 "http://www.abc.com/post.do?m=show&id=35558" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" TCP_MEM_HIT:NONE

[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户
124.64.41.91 - - [19/Mar/2008 15:49:09] "GET http://www.abc.com/products/big/1647/0803/20080319020212_289.jpg HTTP/1.1" 200 65589 "http://www.abc.com/manager.production.do?p_cid=13" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" TCP_HIT:NONE

[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MISS
该指令可以看到在squid运行过程中,有那些文件没有被squid缓存,而是现重原始服务器获取并返回给访问用户
220.181.38.190 - - [17/Mar/2008:17:23:34 +0800] "GET http://www.abc.com/post.do?pcid=198 HTTP/1.1" 200 25162 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)" TCP_MISS:DIRECT

 

可以查看下命中率及其他相关信息
#/usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
[root@www ~]# /usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
HTTP/1.0 200 OK
Server: squid/3.0.STABLE2
Mime-Version: 1.0
Date: Wed, 19 Mar 2008 07:37:22 GMT
Content-Type: text/plain
Expires: Wed, 19 Mar 2008 07:37:22 GMT
Last-Modified: Wed, 19 Mar 2008 07:37:22 GMT
X-Cache: MISS from www.abc.com
Via: 1.0 www.abc.com (squid/3.0.STABLE2)
Connection: close

Squid Object Cache: Version 3.0.STABLE2
Start Time:     Wed, 19 Mar 2008 06:47:32 GMT
Current Time:   Wed, 19 Mar 2008 07:37:22 GMT
Connection information for squid:
        Number of clients accessing cache:      244
        Number of HTTP requests received:       30303
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   608.2
        Average ICP messages per minute since start:    0.0
        Select loop called: 532175 times, 5.617 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 90.3%, 60min: 75.5%
        Hits as % of bytes sent:        5min: 31.8%, 60min: 45.4%
        Memory hits as % of hit requests:       5min: 6.1%, 60min: 32.8%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.1%
        Storage Swap size:      35624 KB
        Storage Swap capacity:   6.8% used, 93.2% free
        Storage Mem size:       37232 KB
        Storage Mem capacity:    7.1% used, 92.9% free
        Mean Object Size:       21.38 KB
        Requests given to unlinkd:      418
Median Service Times (seconds) 5 min    60 min:
        HTTP Requests (All):   0.00000 0.00000
        Cache Misses:          0.07409 0.00000
        Cache Hits:            0.00000 0.00000
        Near Hits:             0.00000 0.00000
        Not-Modified Replies: 0.00000 0.00000
        DNS Lookups:           0.00000 0.00000
        ICP Queries:           0.00000 0.00000
Resource usage for squid:
        UP Time:        2989.216 seconds
        CPU Time:       1.396 seconds
        CPU Usage:      0.05%
        CPU Usage, 5 minute avg:        0.05%
        CPU Usage, 60 minute avg:       0.05%
        Process Data Segment Size via sbrk(): 8044 KB
        Maximum Resident Size: 0 KB
        Page faults with physical i/o: 1
Memory usage for squid via mallinfo():
        Total space in arena:    8312 KB
        Ordinary blocks:         8283 KB     19 blks
        Small blocks:               0 KB      0 blks
        Holding blocks:         48028 KB    306 blks
        Free Small blocks:          0 KB
        Free Ordinary blocks:      28 KB
        Total in use:           56311 KB 100%
        Total free:                28 KB 0%
        Total size:             56340 KB
Memory accounted for:
        Total accounted:        44495 KB 79%
        memPool accounted:      44495 KB 79%
        memPool unaccounted:    11844 KB 21%
        memPoolAlloc calls:   5319189
        memPoolFree calls:    5198329
File descriptor usage for squid:
        Maximum number of file descriptors:   15000
        Largest file desc currently in use:     61
        Number of file desc currently in use:   37
        Files queued for open:                   0
        Available number of file descriptors: 14963
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
          3412 StoreEntries
          3402 StoreEntries with MemObjects
          3401 Hot Object Cache Items
          1666 on-disk objects
[root@www ~]# /usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
HTTP/1.0 200 OK
Server: squid/3.0.STABLE2
Mime-Version: 1.0
Date: Wed, 19 Mar 2008 07:45:48 GMT
Content-Type: text/plain
Expires: Wed, 19 Mar 2008 07:45:48 GMT
Last-Modified: Wed, 19 Mar 2008 07:45:48 GMT
X-Cache: MISS from www.abc.com
Via: 1.0 www.abc.com (squid/3.0.STABLE2)
Connection: close

Squid Object Cache: Version 3.0.STABLE2
Start Time:     Wed, 19 Mar 2008 06:47:32 GMT
Current Time:   Wed, 19 Mar 2008 07:45:48 GMT
Connection information for squid:
        Number of clients accessing cache:      173
        Number of HTTP requests received:       36309
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   623.2
        Average ICP messages per minute since start:    0.0
        Select loop called: 633105 times, 5.522 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 87.9%, 60min: 77.5%
        Hits as % of bytes sent:        5min: 25.9%, 60min: 42.0%
        Memory hits as % of hit requests:       5min: 7.8%, 60min: 27.8%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.1%
        Storage Swap size:      42468 KB
        Storage Swap capacity:   8.1% used, 91.9% free
        Storage Mem size:       45360 KB
        Storage Mem capacity:    8.7% used, 91.3% free
        Mean Object Size:       22.40 KB
        Requests given to unlinkd:      513
Median Service Times (seconds) 5 min    60 min:
        HTTP Requests (All):   0.00000 0.00000
        Cache Misses:          0.08265 0.00091
        Cache Hits:            0.00000 0.00000
        Near Hits:             0.00000 0.00000
        Not-Modified Replies: 0.00000 0.00000
        DNS Lookups:           0.00000 0.00000
        ICP Queries:           0.00000 0.00000
Resource usage for squid:
        UP Time:        3496.007 seconds
        CPU Time:       1.644 seconds
        CPU Usage:      0.05%
        CPU Usage, 5 minute avg:        0.06%
        CPU Usage, 60 minute avg:       0.05%
        Process Data Segment Size via sbrk(): 8580 KB
        Maximum Resident Size: 0 KB
        Page faults with physical i/o: 1
Memory usage for squid via mallinfo():
        Total space in arena:    8848 KB
        Ordinary blocks:         8828 KB     72 blks
        Small blocks:               0 KB      0 blks
        Holding blocks:         57000 KB    372 blks
        Free Small blocks:          0 KB
        Free Ordinary blocks:      19 KB
        Total in use:           65828 KB 100%
        Total free:                19 KB 0%
        Total size:             65848 KB
Memory accounted for:
        Total accounted:        53423 KB 81%
        memPool accounted:      53423 KB 81%
        memPool unaccounted:    12424 KB 19%
        memPoolAlloc calls:   6293795
        memPoolFree calls:    6157879
File descriptor usage for squid:
        Maximum number of file descriptors:   15000
        Largest file desc currently in use:    155
        Number of file desc currently in use: 149
        Files queued for open:                   0
        Available number of file descriptors: 14851
        Reserved number of file descriptors:   100
        Store Disk files open:                  22
Internal Data Structures:
          3730 StoreEntries
          3720 StoreEntries with MemObjects
          3686 Hot Object Cache Items
          1896 on-disk objects

分享到:
评论

相关推荐

    centos下简单配置安装Squid 3.0反向代理

    安装篇: 本教程应用环境为干净centos 5.5 ,预先分好并加载/data分区,并且关闭selinux及iptables 首先修改文件描述符并设定临时端口范围,这些设置重启后生效 代码如下: cat &gt;&gt; /etc/security/limits.conf &lt;...

    CDN学习资料可以看看

    通过深入阅读并理解"Squid3.0反向代理的文档.doc",你可以获得构建和管理Squid CDN系统的宝贵知识,并进一步了解CDN技术如何在实际应用中提高网络性能和稳定性。此外,掌握Squid的使用对于网络管理员、系统架构师和...

    Nginx服务器实现数据静态压缩的方法

    如果你用的是squid 3.0以前的版本并且用的是 ngnix server的话可能会碰到如下问题: 不用squid直接打开页面则客户端返回的是压缩的状态,如果启用squid加速会发现下载下来的页面不是压缩状态。这里面主要是没有启动...

    55links友情链接网址跟踪器

    55links友情链接网址跟踪器,放在桌面,每次直接打开就可以访问55links友情链接交易平台,方便快捷。

    [AB PLC例程源码][MMS_046180]CompactFlash Data Storage.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    moore_01_0909.pdf

    moore_01_0909

    FIBR English learning

    FIBR English learning

    [AB PLC例程源码][MMS_042350]How to send-receive SMS text messages using Westermo modem.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    OIF_IEEE802.3_liaison_19OCt09.pdf

    OIF_IEEE802.3_liaison_19OCt09

    SerU,做网络安全FTP内容的实验必备

    做网络安全FTP内容的实验必备

    nagarajan_01_1107.pdf

    nagarajan_01_1107

    [AB PLC例程源码][MMS_043879]Programming in SFC and ST Language.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    mellitz_3cd_01_0318.pdf

    mellitz_3cd_01_0318

    PyQt6实战派 配套代码

    PyQt6实战派 配套代码

    陕西省省级非物质文化遗产民俗经纬度数据统计表

    陕西省省级非物质文化遗产经纬度数据统计表 统计内容包含以下字段: 1. 项目名称 2. 遗产类别 3. 入选批次 4. 所属地区 5. 申报地区/单位 6. 地理经度 7. 地理纬度 该统计表系统记录了陕西省省级非物质文化遗产的地理空间信息,为文化遗产的数字化保护与研究工作提供了重要的数据支撑。

    ran_3ck_02a_0918.pdf

    ran_3ck_02a_0918

    毕业设计-基于springboot+vue开发的汽车租赁管理系统【源码+sql+可运行】50308.zip

    毕业设计_基于springboot+vue开发的汽车租赁管理系统【源码+sql+可运行】【50308】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码; 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - 业务管理:汽车管理、客户管理、租赁订单 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!

    Runcorder - 跑步训练管理系统

    # Runcorder - 跑步训练管理系统 Runcorder 是一款专为跑步爱好者、马拉松运动员及高校体育生设计的本地化跑步训练管理工具,基于 Python 开发,结合 Tkinter 图形界面与强大的数据处理能力,为用户提供从训练记录到数据分析的全方位支持。无论是初学者还是专业跑者,Runcorder 都能帮助你科学规划训练、精准追踪进度,并通过可视化图表直观呈现训练成果,让你的跑步训练更智能、更高效! - **多用户管理**:支持创建、加载和删除用户档案,每个用户的数据独立存储,确保隐私与安全。 - **科学训练记录**:全维度记录跑步数据,包括日期、里程、配速、自评和晨跑标记,支持智能输入校验,避免数据错误。 - **多维数据分析**:通过动态可视化图表展示跑步里程趋势、平均配速曲线,支持自定义 Y 轴范围,帮助用户深入理解训练效果。 - **高阶功能**:提供 4 种科学训练模式(有氧/无氧/混合),支持历史记录修改与删除,数据以 JSON 格式持久化存储,跨平台兼容。

    paatzsch_01_0708.pdf

    paatzsch_01_0708

Global site tag (gtag.js) - Google Analytics