cd /home
rm -rf apache-tomcat-8.0.39.tar.gz
mkdir /usr/local/tomcat
wget archive.apache.org/dist/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz
tar -zxvf apache-tomcat-8.0.39.tar.gz -C /usr/local/
ln -s /usr/local/apache-tomcat-8.0.39/ /usr/local/tomcat
tomcat内存优化,tomcatinsetclasspath.sh
这下面的 JAVA_HOME环境,若在安装JDK时配置了,可以省略。
PermSize=64M-XX:MaxPermSize=128m在TOMCAT8中开始去除了。
vim/usr/local/tomcat/bin/setclasspath.sh
export JAVA_HOME="/usr/local/jdk"
export JAVA_OPTS=" -Xms512m-Xmx1024m -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
tomcat线程优化,tomcatconfserver.xml
命令:sed -i's/redirectPort="8443"/redirectPort="8443" maxThreads="2000" minSpareThreads="100" maxSpareThreads="1000" acceptCount="1000"/'//usr/local/tomcat/conf/server.xml
下面手动个性
<Connectoraddress="127.0.0.1" port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
maxThreads="2000"minSpareThreads="100" maxSpareThreads="1000" acceptCount="1000" redirectPort="8443" />
如果使用apache和tomcat做集群的负载均衡,并且使用ajp协议做apache和tomcat的协议转发
<Connector port="8009" protocol="AJP/1.3" connectionTimeout="20000"
maxThreads="2000"minSpareThreads="100" maxSpareThreads="1000" acceptCount="1000" redirectPort="8443" />
由于tomcat有多个connector,所以tomcat线程的配置,又支持多个connector共享一个线程池。
<Executor name="tomcatThreadPool"namePrefix="catalina-exec-" maxThreads="500"minSpareThreads="20" maxIdleTime="60000" />
最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60秒。
然后,修改<Connector ...>节点,增加executor属性,executor设置为线程池的名字:
<Connector executor="tomcatThreadPool"port="80" protocol="HTTP/1.1" connectionTimeout="60000" keepAliveTimeout="15000"maxKeepAliveRequests="1" redirectPort="443" />
可以多个connector公用1个线程池,所以ajp connector也同样可以设置使用tomcatThreadPool线程池。
/etc/init.d 是 /etc/rc.d/init.d的软链接(soft link)
添加/etc/init.d/tomcat
vim /etc/init.d/tomcat
内容附文件
chmod 755 /etc/init.d/tomcat
servicetomcat start[stop/restart]
wget http://localhost:8080 //验证安装成功否
tail -f /usr/local/tomcat/logs/catalina.out
解决多个实例多个Tomcat启动、停止端口冲突问题
如果需要启动多个tomcat,则需要修改server.xml文件如:
<Serverport="8005" shutdown="SHUTDOWN"> ---->
<Serverport="8195"shutdown="SHUTDOWN">
<Connectorport="8080" protocol="HTTP/1.1" connectionTimeout="20000"redirectPort="8443" /> ---->
<Connectorport="8091"protocol="HTTP/1.1" maxThreads="150" minSpareThreads="25"maxSpareThreads="75" enableLookups="false"redirectPort="8443" acceptCount="100" debug="0"connectionTimeout="20000" disableUploadTimeout="true" />
<Connectorport="8009" protocol="AJP/1.3" redirectPort="8443" /> ---->
<Connectorport="8199"protocol="AJP/1.3" redirectPort="8443" />
<Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false"> ---->
<Host name="10.10.3.54" appBase="/home/defaut"unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false" >
或者虚拟目录
<Host>
<Contextpath="" docBase="/var/wwwroot"reloadable="true">
</Host>
或者
<Hostname="localhost" appBase="/home/default" unpackWARs="true"autoDeploy="true">
<!-- SingleSignOn valve, shareauthentication between web applications
Documentation at:/docs/config/valve.html -->
<!--
<ValveclassName="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes allexample.
Documentation at:/docs/config/valve.html
Note: The pattern used isequivalent to using pattern="common" -->
<ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t"%r" %s %b" />
</Host>
布署文件拷贝到/home/tomcat/