您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 铜仁分类信息网,免费分类信息发布

squid3加速web服务器

2024/10/24 4:48:02发布49次查看
测试环境: 操作系统 :centos5.0 web 服务器 :apache2 + tomcat 5.5 jdk : j2se 1.5.5 1. 下载 squid-3.0.stable9.tar.gz (测试时最新的版本)。 http://www.squid-cache.org/versions/v3/3.0/squid-3.0.stable9.tar.gz 2. 添加用户及组 # useradd squid -m
测试环境:
     操作系统:centos5.0  
     web服务器:apache2 + tomcat 5.5
     jdk  : j2se 1.5.5
1.下载squid-3.0.stable9.tar.gz (测试时最新的版本)。
http://www.squid-cache.org/versions/v3/3.0/squid-3.0.stable9.tar.gz
2. 添加用户及组
# useradd squid -m -c squid user -d /dev/null-s /sbin/nologin
3. 解压并编译安装
tar squid-3.0.stable9.tar.gz
cd squid-3.0.stable9
./configure--prefix=/data/squid3 --disable-carp --with-aufs-threads=32 --with-pthreads--enable-storeio='ufs,aufs, 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
makeinstall
安装完毕。
4. 配置
可能需要创建一些文件这些都是配置文件中需要调用的(这个要注意文件的属主和权限)
1) [root@www~]#cd /data/squid3/var/logs/
2) [root@www~]#touch cache.log
3) [root@www~]#chmod 755 cache.log
4) [root@www~]#chown squid:squid cache.log
5) [root@www~]#touch page_zs_access_log
6) [root@www~]#chmod 755 page_zs_access_log
7) [root@www~]#chown squid:squid page_zs_access_log
8) [root@www~]#cd /data/squid3/etc/
9) 配置squid配置文件 squid.conf
[root@www~]# vi squid.conf                 (192.168.3.11为服务器的ip地址)
visible_hostnamewww.test.com
http_port80 vhost vport
cache_mem512 mb
maximum_object_size_in_memory2048 kb
memory_replacement_policylru
cache_dirufs /tmp 512 16 256
max_open_disk_fds0
minimum_object_size0 kb
maximum_object_size32768 kb
logformatcombined %>a %ui %un [%tl] %rm %ru http/%rv %hs %h %{user-agent}>h %ss:%sh
access_log/data/squid3/var/logs/page_zs_access_log combined
pid_filename/data/squid3/var/logs/squid.pid
cache_store_lognone
cache_peer192.168.3.11 parent 81 0 no-query no-digest originserver name=www
cache_peer_domainwww www.test.com
cache_peer_accesswww allow all
http_accessallow all
aclquery urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cachedeny query
cache_effective_usersquid
cache_effective_groupsquid
10)[root@www ~]#/data/squid3/sbin/squid -k parse
可以根据这个测试命令用来验证squid.conf的语法和配置(下面是ok的如果不ok会有相应的提示根据提示来修改配置文件)
2008/10/1421:14:56| processing configuration file: /data/squid3/etc/squid.conf (depth 0)
11)[root@www ~]#/data/squid3/sbin/squid -z
用来创建缓存目录
12)vi一个squid.sh的启动脚本如下:赋予可执行权限
[root@www~]#vi squid.sh
#!/bin/sh
#
ulimit-hsn 15000
#this script starts and stops squid
echo15000 > /proc/sys/fs/file-max
case$1 in
start)
          /data/squid3/sbin/squid -s
          echo -n ' squid'
          ;;
stop)
          /data/squid3/sbin/squid -k shutdown
          ;;
esac
#chmod+x squid.sh
5. 启动squid
[root@www~]#./squid.sh start就可以启动squid了
查看有没有启动可以
[root@www~]#ps fax|grep squid
13750 pts/3    s+    0:00                      \_ grepsquid
30474?        ss     0:00 /data/squid3/sbin/squid -s
30476?        s      0:01 \_ (squid) -s
通过命令lsof -i:80查看谁占用了80端口
查看squid的访问日志。
[root@www ~]# tail –f /data/squid3/var/logs/page_zs_access_log
查看命中率及其他相关信息
[root@www ~]# /data/squid3/bin/squidclient -p 80 -hlocalhost mgr:info
http/1.0 200 ok
server: squid/3.0.stable9
mime-version: 1.0
date: tue, 14 oct 2008 13:22:40 gmt
content-type: text/plain
expires: tue, 14 oct 2008 13:22:40 gmt
last-modified: tue, 14 oct 2008 13:22:40 gmt
x-cache: miss from www.6558855.com
via: 1.0 www.6558855.com (squid/3.0.stable9)
connection: close
squid object cache: version 3.0.stable9
start time:    tue, 14 oct 2008 11:25:50 gmt
current time:  tue, 14 oct 2008 13:22:40 gmt
connection information for squid:
        number ofclients accessing cache:      2
        number ofhttp requests received:       772
        number oficp messages received:        0
        number oficp messages sent:    0
        number ofqueued icp replies:   0
        number ofhtcp messages received:       0
        number ofhtcp messages sent:   0
        requestfailure ratio:   0.00
        average http requests per minute sincestart:   6.6
        average icpmessages per minute since start:    0.0
        select loopcalled: 7081542 times, 0.990 ms avg
cache information for squid:
        hits as %of all requests:      5min: 0.0%, 60min:89.7%
        hits as %of bytes sent:        5min: -0.0%, 60min:-0.0%
        memory hitsas % of hit requests:       5min: 0.0%,60min: 0.0%
        disk hitsas % of hit requests: 5min: 0.0%, 60min: 0.0%
        storageswap size:      104 kb
        storage swap capacity:   0.0% used, 100.0% free
        storage memsize:       228 kb
        storage memcapacity:    0.0% used, 100.0% free
        mean objectsize:       10.40 kb
        requestsgiven to unlinkd:      68
median service times (seconds)  5 min   60 min:
        httprequests (all):   0.00000  0.00000
        cachemisses:          0.00000  0.00000
        cachehits:            0.00000  0.00000
        nearhits:             0.00000  0.00000
       not-modified replies: 0.00000  0.00000
        dnslookups:           0.00000  0.00000
        icpqueries:           0.00000  0.00000
resource usage for squid:
        uptime:        7009.125 seconds
        cputime:       0.948 seconds
        cpuusage:      0.01%
        cpu usage,5 minute avg:        0.00%
        cpu usage,60 minute avg:       0.01%
        processdata segment size via sbrk(): 2968 kb
        maximumresident size: 0 kb
        page faultswith physical i/o: 2
memory usage for squid via mallinfo():
        total spacein arena:    3240 kb
        ordinaryblocks:         3194 kb     17 blks
        smallblocks:               0 kb      0 blks
        holdingblocks:         11472 kb     17 blks
        free smallblocks:          0 kb
        freeordinary blocks:      45 kb
        total inuse:           14666 kb 100%
        totalfree:                45 kb 0%
        totalsize:             14712 kb
memory accounted for:
        totalaccounted:         3001 kb  20%
        mempoolaccounted:       3001 kb  20%
        mempoolunaccounted:    11710 kb  80%
       mempoolalloc calls:    147106
        mempoolfreecalls:     145713
file descriptor usage for squid:
        maximumnumber of file descriptors:   15000
        largestfile desc currently in use:     14
        number offile desc currently in use:    8
        filesqueued for open:                   0
        availablenumber of file descriptors: 14992
        reservednumber of file descriptors:   100
        store diskfiles open:                   0
internal data structures:
            45storeentries
            41storeentries with memobjects
            40 hotobject cache items
            10on-disk objects
6. 关于动态页面的缓存。
       如jsp页面。
       利用header为jsp服务器减压
     在参与缓存的jsp中加入如下程序,进行“last-modified”和“expires”的设置;
longfile_lmodified = new file(/tmp/catchmodified.lastmodified();
response.setbuffersize(16);
response.setdateheader(last-modified,file_lmodified);
response.setdateheader(expires,system.currenttimemillis() / 1000 * 1000 + 300000);
response.flushbuffer();
%>
7. 添加自动更新记时方式
[root@www ~]#vi refreshcatch.sh
#/bin/sh
/bin/echo>/tmp/catchmodified
chmod+x refreshcatch.sh
然后在crontab里写一句
*/5 * * * *  /data/squid3/refreshcatch.sh
铜仁分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录