背景
通过管理同行界面可以监控到jvm使用状况,线程的启动状况,请求的执行时间等很多参数。前面做maxthreads设置的时候通过该界面监控tomcat状态,非常好用。
添加tomcat-users.xml配置
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/> <role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="admin" password="123456" roles="admin-gui,manager-gui,manager-jmx, manager-script,manager-status"/>
</tomcat-users>
首先配置了4个角色
manager-gui
允许访问html接口(即URL路径为/manager/html/)
manager-script
允许访问纯文本接口(即URL路径为/manager/text/)
manager-jmx
允许访问JMX代理接口(即URL路径为/manager/jmxproxy/)
manager-status
允许访问Tomcat只读状态页面(即URL路径为/manager/status/)
然后配置了统一的登录名admin和密码123456(生产一定要注意密码复杂度)
设置登录权限
这里"xxx.xx.xx.xx允许访问的ip,生产环境最好指定内网的地址,tomcat被外网访问是很危险的。
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="xxx.xx.xx.xx" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
打开web ui的页面
ip地址+端口+manager,页面提示输入密码。输入上面设置的密码即可进入页面
http://xx.xx.1x3.1x4:8088/manager/
结语
如果你想知道你的配置文件是否生效,以及执行过程中的状态,通过图形界面会很方便。