参考链接:https://blog.csdn.net/github_38336924/article/details/82253553
1、检查是否安装tomcat
systemctl status tomcat
2、查看tomcat的相关信息
yum info tomcat
[root@iZ2zebn3hsgwu61wulgeqhZ ~]# yum info tomcat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name : tomcat
Arch : noarch
Version : 7.0.76
Release : 9.el7_6
Size : 91 k
Repo : base/7/x86_64
Summary : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
URL : http://tomcat.apache.org/
License : ASL 2.0
Description : Tomcat is the servlet container that is used in the official Reference
: Implementation for the Java Servlet and JavaServer Pages technologies.
: The Java Servlet and JavaServer Pages specifications are developed by
: Sun under the Java Community Process.
:
: Tomcat is developed in an open and participatory environment and
: released under the Apache Software License version 2.0. Tomcat is intended
: to be a collaboration of the best-of-breed developers from around the world.
3、安装tomcat(默认安装路径是/usr/share/tomcat/
)
yum -y install tomcat
4、检查tomcat是否安装成功
[root@iZ2zebn3hsgwu61wulgeqhZ ~]# rpm -q tomcat
tomcat-7.0.76-9.el7_6.noarch
5、在配置文件中加入tomcat的环境变量(/etc/profile)
CATALINA_BASE=/usr/share/tomcat
CATALINA_HOME=/usr/share/tomcat
export JAVA_HOME PATH CLASSPATH CATALINA_BASE CATALINA_HOME
6、执行生效命令并查看tomcat变量
[root@iZ2zebn3hsgwu61wulgeqhZ etc]# source /etc/profile
[root@iZ2zebn3hsgwu61wulgeqhZ etc]# echo $CATALINA_BASE
/usr/share/tomcat
[root@iZ2zebn3hsgwu61wulgeqhZ etc]#
7、开放8080端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent
8、重启防火墙
systemctl restart firewalld.service
9、设置开机启动tomcat
systemctl enable tomcat.service
[root@iZ2zebn3hsgwu61wulgeqhZ etc]# systemctl enable tomcat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.
10、安装根页面(tomcat-webapps)和Tomcat Web
应用程序管理器和Virtual Host Manager(tomcat-admin-webapps)
yum install -y tomcat-webapps tomcat-admin-webapps
11、安装在线文档(yum install -y tomcat-docs-webapp tomcat-javadoc)
12、安装成功后,检查目录是否存在
[root@iZ2zebn3hsgwu61wulgeqhZ etc]# cd /usr/share/tomcat/webapps
[root@iZ2zebn3hsgwu61wulgeqhZ webapps]# ll
total 24
drwxr-xr-x 14 root root 4096 Mar 16 11:08 docs
drwxr-xr-x 8 tomcat tomcat 4096 Mar 16 11:07 examples
drwxr-xr-x 5 root tomcat 4096 Mar 16 11:07 host-manager
drwxr-xr-x 5 root tomcat 4096 Mar 16 11:07 manager
drwxr-xr-x 3 tomcat tomcat 4096 Mar 16 11:07 ROOT
drwxr-xr-x 5 tomcat tomcat 4096 Mar 16 11:07 sample
13、修改tomcat-users.xml
的文件(vi /usr/share/tomcat/conf/tomcat-users.xml)
(1) 新增访问用户manager-gui
和admin-gui
<tomcat-users>
<user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
(2) 重启tomcat服务
sudo systemctl restart tomcat
14、访问8080端口