tomcat部署
java环境安装
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@localhost ~]# java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)
[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# sed -i "s/=enforcing/=disabled/g" /etc/selinux/config
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 0
Permissive
下载和解压tomcat
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.65.tar.gz
[root@localhost ~]# tar xf apache-tomcat-9.0.65.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s apache-tomcat-9.0.65/ tomcat
[root@localhost local]# ll
total 0
drwxr-xr-x. 9 root root 220 Aug 16 04:06 apache-tomcat-9.0.65
drwxr-xr-x. 2 root root 6 Jun 22 2021 bin
drwxr-xr-x. 2 root root 6 Jun 22 2021 etc
drwxr-xr-x. 2 root root 6 Jun 22 2021 games
drwxr-xr-x. 2 root root 6 Jun 22 2021 include
drwxr-xr-x. 2 root root 6 Jun 22 2021 lib
drwxr-xr-x. 3 root root 17 Aug 16 01:55 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin
drwxr-xr-x. 5 root root 49 Aug 16 01:55 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
lrwxrwxrwx. 1 root root 21 Aug 16 04:07 tomcat -> apache-tomcat-9.0.65/
#测试页面
[root@localhost ~]# vim index.jsp
[root@localhost ~]# cat index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("Hellow World");
%>
</body>
</html>
[root@localhost ~]# mkdir /usr/local/tomcat/webapps/test
[root@localhost ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@localhost ~]# ll /usr/local/tomcat/webapps/test/
total 4
-rw-r--r--. 1 root root 141 Aug 16 04:11 index.jsp
#开启tomcat服务
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh
[root@localhost ~]# chmod +x /etc/profile.d/tomcat.sh
[root@localhost ~]# source /etc/profile.d/tomcat.sh
这个时候,很多服务还没开启,按照下面的步骤开启
#开启8009端口,调高与httpd连接的效率
[root@localhost conf]# pwd
/usr/local/tomcat/conf
[root@localhost conf]# vim server.xml
#取消注释
...
<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" />
...
[root@localhost ~]# catalina.sh stop
[root@localhost ~]# catalina.sh start
#8009端口起来
[root@localhost conf]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 [::1]:8009 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
启动Server status,设置登录名为tomcat,密码为tomcat
[root@localhost conf]# pwd
/usr/local/tomcat/conf
[root@localhost conf]# vim tomcat-users.xml
#添加
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
[root@localhost META-INF]# ls
context.xml
[root@localhost META-INF]# vim context.xml
增加允许访问的网络
allow="192\.168\.192\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
[root@localhost conf]# catalina.sh stop
[root@localhost conf]# catalina.sh start
manager app的样式
#开启host manager
[root@localhost conf]# pwd
/usr/local/tomcat/conf
[root@localhost conf]# vim tomcat-users.xml
...
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
...
#放行ip
[root@localhost META-INF]# pwd
/usr/local/tomcat/webapps/host-manager/META-INF
[root@localhost META-INF]# vim context.xml
allow="192\.168\.192\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
[root@localhost conf]# catalina.sh stop
[root@localhost conf]# catalina.sh start