阴 19°
公司要发布一个apk应用,但不能让用户全速下载。Tomcat本身不能对速度限制。
思路
1、整合Apache和Tomcat
2、Apache加载Bandwidth模块
一、准备所需软件
1、httpd-2.4.7.tar.gz http://mirror.esocc.com/apache/httpd/
2、jakarta-tomcat-connectors-1.2.15-src.tar.gz http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/
3、tomcat方面因为已经安装了,我这边就不需要了
二、安装apache
# tar xzvf httpd-2.4.7.tar.gz # cd httpd-2.4.7 # ./configure --prefix=/usr/local/apache --enable-so # make # make install
三、编译生成mod_jk
# tar xzvf jakarta-tomcat-connectors-1.2.15-src.tar.gz # cd jakarta-tomcat-connectors-1.2.15-src/jk/native # ./configure --with-apxs=/usr/local/apache/bin/apxs # make # cp ./apache-2.0/mod_jk.so /usr/local/apache/modules/
四、连接apache和tomcat
1、
cd /usr/local/apache/conf/ vim mod_jk.conf
添加
# 指出mod_jk模块工作所需要的工作文件workers.properties的位置 JkWorkersFile /usr/local/apache/conf/workers.properties # Where to put jk logs JkLogFile /usr/local/apache/logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" # 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理 JkMount /servlet/* worker1 JkMount /*.jsp worker1
2、
vi workers.properties
添加
# Defining a worker named worker1 and of type ajp13 worker.list=worker1 # Set properties for worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.socket_timeout=300
3、修改apache主配置文件
vim /usr/loacl/apache/conf/httpd.conf
添加index.jsp支持
<IfModule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>
添加别名(根据各自需要了)
我的tomcat放在/usr/apache-tomcat-7.0.47
Alias /test2 "/usr/apache-tomcat-7.0.47/webapps/test"
<Directory "/usr/apache-tomcat-7.0.47/webapps/test">
AllowOverride None
Options Indexes MultiViews
Order allow,deny
Allow from all
</Directory>
加载apache-tomcat连接模块
找到LoadModule的地方添加一段
LoadModule jk_module modules/mod_jk.so
同样在nclude conf/extra/httpd-ssl.conf下面添加一段
Include /usr/local/apache2/conf/mod_jk.conf
4、配置tomcat
vim /usr/apache-tomcat-7.0.47/conf/server.xml
添加或修改
<Context path="/test2" docBase="/usr/apache-tomcat-7.0.47/webapps/test" reloadable="false" crossContext="true" />
标红的地址必须和apache上别名下面的标红地址一致
5、编写一个jsp页面
vim /usr/apache-tomcat-7.0.47/webapps/test/index.jsp
<HTML> <HEAD> <TITLE>JSP测试页面---HelloWorld!</TITLE> </HEAD> <BODY> <% out.println("<h1>Hello World!<br>世界,你好!</h1>"); %> </BODY> </HTML>
6、重启apache和tomcat
/usr/local/apache/bin/httpd -k restart /usr/apache-tomcat-7.0.47/bin/shutdown.sh /usr/apache-tomcat-7.0.47/bin/start.sh
7、测试一下
成功。。。