Tomcat的后台管理功能
配置 Tomcat 后台授权用户
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim tomcat-8081/conf/tomcat-users.xml |
刷新manager.html页面,还是403,后面重新启动tomcat,403,这就奇怪了…
还是403
后面查看相关tomcat官网,还需要此manager.xml文件,赋予远程管理的权限
Each deployed webapp has a context.xml file that lives in $CATALINA_BASE/conf/[enginename]/[hostname] (conf/Catalina/localhost by default) and has the same name as the webapp (manager.xml in this case). If no file is present, default values are used.
So, you need to create a file conf/Catalina/localhost/manager.xml and specify the rule you want to allow remote access.1
2
3
4
5
6
7
8[root@iZuf6iq8e7ya9v3ix71k0pZ localhost]# pwd
/usr/local/tomcat/tomcat-8081/conf/Catalina/localhost
[root@iZuf6iq8e7ya9v3ix71k0pZ localhost]# vim manager.xml
...
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
重新启动 tomcat,刷新manger.html
发布服务到服务器端
配置二级域名解析
服务的分布结构
8083 manager.smniuhe.com rudy-manager-web(表现层)
8084 smniuhe.com:8084 rudy-manager(服务层)
8085 smniuhe.com:8085 rudy-content(服务层)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65# 查看服务器内存占用情况
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# free -m
total used free shared buff/cache available
Mem: 3790 1707 793 0 1289 1831
Swap: 0 0 0
# 释放网页缓存,目录项和索引
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# sync
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# echo 3 > /proc/sys/vm/drop_caches
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# free -m
total used free shared buff/cache available
Mem: 3790 1706 1994 0 89 1914
Swap: 0 0 0
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# ll
总用量 9480
-rw-r--r-- 1 root root 9536557 1月 30 23:28 apache-tomcat-8.5.27.tar.gz
-rw-r----- 1 root root 156775 3月 26 11:36 dubbo-governance.log
drwxr-xr-x 9 root root 4096 3月 26 11:36 tomcat-8081
drwxr-xr-x 9 root root 4096 3月 20 13:38 tomcat-8083
# cp热部署配置
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# cp tomcat-8081/conf/Catalina/localhost/manager.xml tomcat-8083/conf/Catalina/localhost/
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim tomcat-8083/conf/tomcat-users.xml
...
...
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="root" password="root" roles="manager-gui,manager-script"/>
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# cp -rf tomcat-8083 tomcat-8084
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# cp -rf tomcat-8083 tomcat-8085
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim tomcat-8084/conf/server.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim tomcat-8085/conf/server.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim start-345.sh
...
/usr/local/tomcat/tomcat-8083/bin/startup.sh
/usr/local/tomcat/tomcat-8084/bin/startup.sh
/usr/local/tomcat/tomcat-8085/bin/startup.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# chmod +x start-345.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# vim stop-345.sh
...
/usr/local/tomcat/tomcat-8083/bin/shutdown.sh
/usr/local/tomcat/tomcat-8084/bin/shutdown.sh
/usr/local/tomcat/tomcat-8085/bin/shutdown.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# chmod +x stop-345.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ tomcat]# ./start-345.sh
# 配置maven插件
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<path>/</path>
<port>8080</port>
<url>http://smniuhe.com:8084/manager/text</url>
<username>root</username>
<password>root</password>
</configuration>
</plugin>
</plugins>
</build>
# create maven-redeployConfiguraion:
clean tomcat7:redeploy -DskipTests