安装Tomcat
安装JDK
https://www.oracle.com/java/technologies/downloads/#license-lightbox
mkdir -p /usr/java
tar xf jdk-11.0.22_linux-x64_bin.tar.gz
ln -sv /usr/java/jdk /usr/java/jdk-11.0.22
配置环境变量:
cat > /etc/profile.d/java.sh << 'EOF'
JAVA_HOME=/usr/java/jdk/
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
EOF
# 注意:'EOF'向文件中追加内容不解析。
测试:
source /etc/profile.d/java.sh
java -version
安装Tomcat
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.87/bin/apache-tomcat-9.0.87.tar.gz
tar xf apache-tomcat-9.0.87.tar.gz -C /usr/local/
ln -sv /usr/local/apache-tomcat-9.0.87/ /usr/local/tomcat
配置环境变量:
echo 'export TOMCAT_HOME=/usr/local/tomcat'>>/etc/profile.d/tomcat.sh
source /etc/profile.d/tomcat.sh
检查tomcat是否安装成功:
/usr/local/tomcat/bin/version.sh
Tomcat启动与停止
Tomcat启动停止文章来源:https://www.toymoban.com/news/detail-852113.html
启动程序
/usr/local/tomcat/bin/startup.sh
关闭程序
/usr/local/tomcat/bin/shutdown.sh
为tomcat提供服务启动脚本。
启动后访问页面:
为tomcat提供服务启动脚本。文章来源地址https://www.toymoban.com/news/detail-852113.html
vim /usr/lib/systemd/system/tomcat.service
##添加如下内容
[Unit]
Description=Apache Tomcat 9
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/java/jdk
Environment=CATALINA_HOME=/usr/local/tomcat
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start tomcat
到了这里,关于linux上安装Tomcat的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!