Article Directory
A, Tomcat Introduction
1.1, Tomcat core components
1.2, Tomcat directory structure
Two, Tomcat deployment steps
2.1, JDK installation
2.2, install Tomcat
2.3, optimize the startup speed of Tomcat
Third, the virtual host configuration
Demand 3.1, virtual hosts
3.2, the configuration process
A, Tomcat Introduction
Free, open source Web application server
Apache Software Foundation (Apache Software Foundation) Jakarta project, a core project
By the Apache, Sun and a number of companies and individuals jointly developed with
I loved Java enthusiasts, and has been recognized by some software developers
More popular Web application server
1.1, Tomcat core components
Tomcat consists of a series of components, wherein there are three core components:
Web container: complete functionality of a Web server.
Servlet container: Catalina named, for processing Servlet code.
JSP container: Dynamic JSP pages into Servlet for translating the code.
1.2, Tomcat directory structure
bin:
Store startup and shutdown Tomcat script file, more commonly used is catalina.sh, startup.sh, shutdown.sh three documents
conf:
Tomcat server storing various profiles, more commonly used it is server.xml, context.xml, tomcat-users. Xm1, web.xml four files.
lib:
Tomcat server storage jar package, generally do not make any changes unless connecting third-party services, such as redis, it would need to add the corresponding jar package
logs:
Tomcat log storage
temp:
When storing the resulting file to run Tomcat
webapps:
Stored project resources directory
work:
Tomcat working day record, Tomcat general clearing the cache when it will use to
Two, Tomcat deployment steps
1. Download and install jdk
2. Install and start Tomcat
2.1, JDK installation
Before deploying Tomcat must be installed jdk, jdk is necessary because the environment Tomcat runs. And jdk installation is relatively simple, there are many versions, here we choose rpm version.
The installation package is downloaded to the local, create a shared folder, share a virtual machine centos7.
1, to mount the installation packages, the installation jdk
mkdir /abc
mount.cifs //192.168.56.1/lamp7 /abc ##lamp7是我本机的共享文件
rpm -ivh jdk-8u201-linux-x64.rpm
2, set the JDK environment variables and enter into force
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 PATN=$JAVA_HOME/bin:$PATH
#环境变量生效
source /etc/profile
#查看 java 版本
java -version
2.2, install Tomcat
1, the installation package extract to / usr / local
执行下面的命令,从 Tomcat 官网下载 apache-tomcat-9.0.16.tar.gz 稳定版本,将安装包 apache-tomcat-9.0.16.tar.gz 上传到/root目录下
##将安装包tomcat 移动到目录/usr/local 下
tar zxvf apache-tomecat-9.0.16.tar.gz -C /usr/loacl
cd /usr/local
mv apache-tomcat-9.0.16 /tomcat
2, optimal path, start tomcat
##启动tomcat ##
#开启
ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/
输入 :startup.sh
#关闭
ln -s /usr/loacl/tomcat/bin/shutdown.sh /usr/bin/
输入:shutdown.sh
3, the browser input http://192.168.111.145:8080
)
2.3, optimize the startup speed of Tomcat
The first time you start Tomcat view the log will find very slow start, by default require tens of seconds, you can modify the parameters to improve jdk, open /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java. security file.
cd /usr/java//jdk1.8.0_201-amd64/jre/lib/
cd security
vim java.security
##查询 random
securerandom.source=flie:/dev/random
##改成
securerandom.source=flie:/dev/urandom
Then, restart Tomcat will find a lot shorter start-up time.
Note: In the actual work environment, the effect is significant, we are here only simulated in a virtual machine, the effect is not too obvious.
Third, the virtual host configuration
Demand 3.1, virtual hosts
Sometimes the company will need to run multiple projects, it certainly can not be run on a single server multiple Tomcat service, it will consume too many system resources. At this point, we need to use the Tomcat virtual host.
Two new domain name www.kgc.com and www.accp.com, through two domain names to a different project content.
step
1. Create kgc project directories and files and accp
2. Modify the Tomcat main configuration file
3. Restart the Tomcat service
4. Test
3.2, the configuration process
1, DNS resolve configuration provides two domain names.
yum install bind -y
vim /etc/named.conf
vim /etc/named.rfc1912.zones
cd /var/named
cp -p named.localhost kgc.com.zone
vim kgc.com.zone
cp -p kgc.zom.zone accp.zom.zone
Start the service, turn off the firewall.
##启动服务,关闭防火墙。
systemctl start named
systemctl stop firewalld
setenforce 0
Both projects create directories and files
##创建kgc和accp项目 目录和文件
cd /usr/local/tomcat/webapps/
mkdir /usr/local/tomcat/webapps/kgc
echo "this is kgc page\!" > /usr/local/tomcat/webapps/kgc/index.jsp
mkdir /usr/local/tomcat/webapps/accp
echo "this is accp page\!" > /usr/local/tomcat/webapps/accp/index.jsp
2, the main configuration file modified Tomcat
vim /usr/local/tomcat/conf/server.xml
<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" />
</Host>
<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>