Tomcat
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
tomcat部署
//关闭selinux和防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@localhost ~]# systemctl disable --now firewalld.service
//安装java
[root@localhost ~]# dnf -y install java-17-openjdk.x86_64
//下载tomcat二进制包,并解压
[root@localhost ~]# wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.23/bin/apache-tomcat-10.0.23.tar.gz
[root@localhost ~]# tar -xf apache-tomcat-10.0.23.tar.gz -C /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv apache-tomcat-10.0.23/ tomcat
[root@localhost local]# cd tomcat/
//自定义index.jsp测试网页
[root@localhost tomcat]# mkdir webapps/test
[root@localhost tomcat]# vim webapps/test/index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("Hello World");
%>
</body>
</html>
//启动服务
[root@localhost 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 tomcat]# ss -anlt
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 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
访问测试
配置三个api页面
[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="admin-gui"/>
<user username="nbr" password="123456" roles="admin-gui"/>
[root@localhost ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
//在allowr那一行增加自己访问的ip网段
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="192\.168\.10\.\d+|150\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
//重启服务
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh stop
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh start
设置Server Status 和Manager App 页面
[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="nbr" password="123456" roles="admin-gui,manager-gui"/>
[root@localhost ~]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
//在allowr那一行增加自己访问的ip网段
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="192\.168\.10\.\d+| 150\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
//重启服务
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh stop
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh start
编辑service文件
//先关闭服务
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh stop
[root@localhost ~]# vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=tomcat server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/catalina.sh start
ExecStop=/usr/local/tomcat/bin/catalina.sh stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
//设置服务开机自启
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now tomcat.service
[root@localhost ~]# ss -anlt
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 100 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*
标签:bin,Tomcat,tomcat,root,usr,local,localhost
From: https://www.cnblogs.com/nie123/p/16736529.html