一:Tomcat安装部署
#1.安装
iptables -F
setenforce 0
cd /opt
"上传 jdk-8u201-linux-x64.rpm"
rpm -ivh jdk-8u201-linux-x64.rpm
java -version
#2.设置环境变量
vim /etc/profile
"最后一行添加"
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile
#3.启动与关闭服务
cd /opt
"上传 apache-tomcat-9.0.16.tar.gz"
tar xzvf apache-tomcat-9.0.16.tar.gz
mv apache-tomcat-9.0.16 /usr/local/tomcat
/usr/local/tomcat/bin/startup.sh
netstat -ntap|grep 8080
ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/
ln -s /usr/local/tomcat/bin/shutdown.sh /usr/bin/
startup.sh
shutdown.sh
#4.优化启动速度
vim /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security
securerandom.source=file:/dev/urandom //把random修改为urandom 不依赖系统中断
#5.配置语法检查
catalina.sh //主命令脚本
configtest.sh //语法检查脚本
#6.添加service管理
cd /etc/init.d/
vim tomcat
#!/bin/bash
#chkconfig: 35 86 89
TOMCATBIN=/usr/local/tomcat/bin/catalina.sh
export JAVA_HOME=/usr/local/java
start(){
$TOMCATBIN start
}
stop(){
$TOMCATBIN stop
}
restart(){
stop
start
}
status(){
if [ -f ‘/var/run/tomcat.pid‘ ];then
echo ‘tomcat is running‘
else
echo ‘tomcat is not run‘
fi
}
configtest(){
$TOMCATBIN configtest
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
configtest)
configtest;;
*)
echo ‘{start|stop|restart|configtest|status}‘
esac
chmod +x tomcat
service tomcat stop
service tomcat start
二:服务优化
1.虚拟主机
#创建首页目录和文件
mkdir /usr/local/tomcat/webapps/kgc
echo "<h1>this is kgc page</h1>" > /usr/local/tomcat/webapps/kgc/index.jsp
mkdir /usr/local/tomcat/webapps/accp
echo "<h1>this is accp page</h1>" > /usr/local/tomcat/webapps/accp/index.jsp
#配置域名解析服务
#构建虚拟主机
vim /usr/local/tomcat/conf/server.xml
<Host name="www.accp.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/tomcat/webapps/accp" path="" reloadable="true"/>
</Host>
<Host name="www.kgc.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/tomcat/webapps/kgc" path="" reloadable="true"/>
2.Tomcat配置文件参数优化
vim /usr/local/tomcat/conf/server.xml
<Connector port="8080" protocol="HTTP/11.1"
connectionTimeout="20000"
redirectPort="8443"
minSpareThreads="50"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="300"
maxThreads="500"
processorCache="500"
URIEncoding="UTF-8"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,image/gif,image /jpg,image/png"/>
......
shutdown.sh
startup.sh
原文:https://blog.51cto.com/14625831/2548323