TOMCAT容器部署和tomcat虚拟主机及其优化
文章目录
一、Tomcat部署
【1】上传JDK软件包和tomcat压缩包并解压
cd /opt
mkdir tomcat
rpm -ivh jdk-8u201-linux-x64.rpm
tar zxvf apache-tomcat-9.0.16.tar.gz -C /usr/local
【2】声明JDK全局变量
cd /usr/java/jdk1.8.0_201-amd64/
pwd
/usr/java/jdk1.8.0_201-amd64/
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】查看Java版本是否改变
java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
【4】优化命令为系统识别
ln -s /usr/local/apache-tomcat-9.0.16/bin/shutdown.sh /usr/bin/
ln -s /usr/local/apache-tomcat-9.0.16/bin/startup.sh /usr/bin/
【5】启动tomcat并验证
/usr/bin/startup.sh
netstat -natp |grep 8080
【6】优化启动
vim /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security
# In addition, if "file:/dev/random" or "file:/dev/urandom" is
# specified, the "NativePRNG" implementation will be more preferred than
# SHA1PRNG in the Sun provider.
securerandom.source=file:/dev/urandom
二、虚拟主机设置
【1】在tomcat工作目录下创建站点
cd /usr/local//apache-tomcat-9.0.16/webapps/
mkdir kgc benet
vim kgc/index.jsp
<h1>this is kgc page</h1>
vim benet/index.jsp
<h1>this is benet page</h1>
【2】tomcat虚拟主机配置
vim /usr/local/apache-tomcat-9.0.16/conf/server.xml
<Host name="www.kgc.com" appBase="/usr/local/apache-tomcat-9.0.16/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/apache-tomcat-9.0.16/webapps/kgc"
path="" reloadable="true" />
</Host>
<Host name="www.benet.com" appBase="/usr/local/apache-tomcat-9.0.16/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context docBase="/usr/local/apache-tomcat-9.0.16/webapps/benet"
path="" reloadable="true" />
</Host>
【3】配置域名
yum install -y bind
vim /etc/named.conf
listen-on port 53 { any; };
allow-query { any; };
vim /etc/named.rfc1912.zones
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "benet.com" IN {
type master;
file "benet.com.zone";
allow-update { none; };
};
cp -p /var/named/named.localhost /var/named/kgc.com.zone
vim /var/named/kgc.com.zone
www IN A 192.168.60.10
cp -p /var/named/kgc.com.zone /var/named/benet.com.zone
【4】启动服务和tomcat
systemctl start named
/usr/local/apache-tomcat-9.0.16/bin/shutdown.sh
/usr/local/apache-tomcat-9.0.16/bin/startup.sh
【5】访问不同的域名显示不同的结果
www.kgc.com:8080
www.benet.com:8080
三、Tomcat优化
【1】修改tomcat配置文件
vim /usr/local/apache-tomcat-9.0.16/conf/server.xml
<Connector port="8080"
protocol="HTTP/1.1
connectionTimeout="20000"
redirectPort="8443"
minSpareThreads="50" ##############最小空闲线程数
enableLookups="false" #########是否反查域名
disableUploadTimeout="true" ###########上传时候是否使用超时机制
acceptCount="300" #########可传入最大连接请求的队列长度,默认100
maxThreads="500" ############最大线程数
processorCache="500" #########
URIEncoding="UTF-8" #########tomcat容器编码格式
compression="on" ############是否对响应的数据进行压缩
compressionMinSize="2048" #########表示压缩响应的最小值
compressableMimeType="text/html,text/xml,text/javascript,text/css,
text/plain,image/gif,image/jpg,image/png"
/> ########指定对那些文件进行压缩
【2】重启tomcat
/usr/local/apache-tomcat-9.0.16/bin/shutdown.sh
/usr/local/apache-tomcat-9.0.16/bin/startup.sh