squid+tomcat+jdk+urlrewritefilter

来源:互联网 发布:mac 怎么设置端口 编辑:程序博客网 时间:2024/05/21 14:41
一、软件:

CODE:

squid-2.6.STABLE23.tar.gz
apache-tomcat-6.0.20-src.tar.gz
jdk-6u17-linux-x64.bin
urlrewritefilter-2.6.zip
下载地址:

CODE:

http://www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE23.tar.gz
http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.20/src/apache-tomcat-6.0.20-src.tar.gz
http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u18-linux-x64.bin?BundledLineItemUUID=gvpIBe.o0B4AAAEn90tk0Tt9&OrderID=s9FIBe.oLBYAAAEn60tk0Tt9&ProductID=p_9IBe.pFJcAAAElWitRSbJV&FileName=/jdk-6u18-linux-x64.bin
http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip
二、安装:
1、Squid:
#tar zvxf squid-2.6.STABLE23.tar.gz
#cd squid-2.6.STABLE23
#vi install.sh

CODE:

./configure \
   "--prefix=/usr/local/squid2" \
   "--disable-dependency-tracking" \
   "--enable-dlmalloc" \
   "--enable-gnuregex" \
   "--enable-async-io" \
   "--with-pthreads" \
   "--enable-storeio=ufs,aufs,diskd,null" \
   "--disable-wccp" \
   "--disable-wccpv2" \
   "--enable-kill-parent-hack" \
   "--enable-cachemgr-hostname=localhost" \
   "--enable-default-err-language=Simplify_Chinese" \
   "--with-build-environment=POSIX_V6_ILP32_OFFBIG" \
   "--with-maxfd=65535" \
   "--with-aio" \
   "--disable-poll" \
   "--enable-epoll" \
   "--enable-linux-netfilter" \
   "--enable-large-cache-files" \
   "--disable-ident-lookups" \
   "--enable-default-hostsfile=/etc/hosts" \
   "--with-dl" \
   "--with-large-files" \
   "--enable-removal-policies=heap,lru" \
   "--enable-delay-pools" \
   "--enable-snmp" \
   "--disable-internal-dns"
make
make install
#sh install.sh
2、Tomcat:
#tar zvxf apache-tomcat-6.0.20-src.tar.gz
#mv apache-tomcat-6.0.20 tomcat-6.0.20
3、JDK:
#chmod u+x jdk-6u17-linux-x64.bin
#./ jdk-6u17-linux-x64.bin
安装过程需要输入yes
4、Urlrewrite:
#unzip urlrewritefilter-2.6.zip
#cp urlrewritefilter-2.6/WEB-INF/lib/urlrewrite-2.6.0.jar /usr/local/tomcat-6.0.20/webapps/ROOT/WEB-INF/lib/
#cp urlrewritefilter-2.6/WEB-INF/urlrewrite.xml /usr/local/tomcat-6.0.20/webapps/ROOT/WEB-INF

三、配置:
1、Squid:
#cd /usr/local/squid2/etc/
#vi squid.conf

CODE:

http_port 80 vhost vport
cache_peer 127.0.0.1 parent 8080 0 no-query originserver no-digest name=tomcat
cache_peer_domain tomcat tomcat.linuxtone.org

visible_hostname cache.linuxtone.org
cache_mgr hamgua@linuxtone.org
cache_effective_user squid
cache_effective_group squid

acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl Safe_ports port 80
acl Safe_ports port 8080
acl SSL_ports port 443
acl CONNECT method CONNECT

http_access allow all
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny all
icp_access allow all

cache_replacement_policy lru
#cache_dir
cache_dir aufs /usr/local/squid2/cache 32768 64 64
cache_mem 2048 MB
max_open_disk_fds 0
#maximum_object_size 512 KB
#maximum_object_size_in_memory 256 KB
maximum_object_size 20 MB
maximum_object_size_in_memory 8 MB

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

refresh_pattern -i /$                        60      70%     170     reload-into-ims
refresh_pattern -i .html$                    60      70%     170     reload-into-ims
refresh_pattern -i .shtml$                   60      70%     170     reload-into-ims
refresh_pattern -i .htm$                     210     70%     960     reload-into-ims

#refresh_pattern -i .jsp$                     60      70%     170     reload-into-ims
#refresh_pattern -i .[do|do\?.+]              60      70%     170     reload-into-ims

refresh_pattern -i .css$                     300     90%     1440    reload-into-ims
refresh_pattern -i .[js|js\?.+]              300     90%     1440    reload-into-ims

refresh_pattern -i \.jpg$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.gif$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.swf$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.jpg$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.png$                    1440    70%     2880    ignore-reload  
refresh_pattern -i \.bmp$                    1440    70%     2880    ignore-reload

refresh_pattern -i \.doc$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.ppt$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.xls$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.pdf$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.rar$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.zip$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.txt$                    1440    70%     2880    ignore-reload
refresh_pattern -i \.ico$                    1440    70%     2880    ignore-reload

header_access Via deny all
header_access Server deny all
#header_access X-Cache deny all
#header_access X-Cache-Lookup deny all

hierarchy_stoplist cgi-bin
acl QUERY urlpath_regex cgi-bin index\.do login\.jsp logIfr\.jsp logIfr\.jsp\?logout\=1
#acl QUERY urlpath_regex cgi-bin ? \.do
cache deny QUERY


# logfile
emulate_httpd_log on
logformat combined %{X-Forwarded-For}>h %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
#access_log none
#access_log /usr/local/squid2/var/logs/access.log combined
logformat linuxtone [%tl] %6tr %>a  %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt "%{Referer}>h" "%{User-Agent}>h"
access_log /usr/local/squid2/var/logs/access.log linuxtone
#cache_store_log /var/log/squid3/store.log
cache_store_log /dev/null
cache_log /usr/local/squid2/var/logs/cache.log
logfile_rotate 12
检查配置文件有没有问题
#/usr/local/squid2/sbin/squid –k parse
启动squid:
# ulimit -SHn 65535
#/usr/local/squid2/sbin/squid –s
2、Jdk:
在profile最后加入jdk变量
#vi /etc/profile

CODE:

JAVA_HOME=/usr/local/jdk1.6.0_18
PATH=/usr/local/jdk1.6.0_18/bin:$PATH
CLASSPATH=.:/usr/local/jdk1.6.0_18/lib:/usr/local/jdk1.6.0_18/lib/tool.jar:/usr/local/jdk1.6.0_18/lib/dt.jar
CLASSPATH=$CLASSPATH:$JAVA_HOME/jre/lib
export JAVA_HOME PATH CLASSPATH
让环境变量生效
#source /etc/profile
3、Tomcat:
Tomcat默认不要配置什么东西,有就根据项目工程进行配置
启动tomcat:
#sh /usr/local/tomcat-6.0.20/bin/startup.sh
4、Urlrewrite-tomcat:
配置自己的tomcat的rewrite规则,例如
#vi /usr/local/tomcat-6.0.20/webapps/ROOT/WEB-INF/urlrewrite.xml

CODE:

    <rule>
         <from>^/index.shtml$</from>
         <to>/index.do</to>
    </rule>
重启tomcat使rewrite生效
# sh /usr/local/tomcat-6.0.20/bin/shutdown.sh
# sh /usr/local/tomcat-6.0.20/bin/startup.sh



在你对应的jsp页面加入如下信息,让伪静态页面被squid缓存:


CODE:

<%
//本页面允许在浏览器端或缓存服务器中缓存,时限为0.5小时。
Date date = new Date();
response.setDateHeader("Last-Modified",date.getTime());
response.setDateHeader("Expires",date.getTime()+(long)(0.5*3600*1000));
%>

0 0