In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to enable JMX monitoring through Tomcat. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Build a simulation environment:
Operating system: centos7
Memory: 1G
Jdk:1.8.0_131
Tomcat:8.0.48
When the environment is ready, we will not demonstrate directly here, but directly configure the jmx of tomcat.
1. Go to the bin directory of tomcat
# cd / opt/tomcat/apache-tomcat-8.0.48/bin/
2. Edit the configuration file
# vim catalina.sh
3. Add parameters above in the following figure
What it looks like after the parameter is added
3.1.This configuration does not require an account password to connect to jmx:
CATALINA_OPTS= "$CATALINA_OPTS-Dcom.sun.management.jmxremote-Djava.rmi.server.hostname=192.168.100.117-Dcom.sun.management.jmxremote.port=9999-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=false"
Screenshot after configuration:
Parameter description:
Hostname: the ip address of the server where the monitoring tomcat is located
Jmxremote.port: Port number, which is the monitoring port number to be enabled
Jmxremote.ssl: whether to open a ssl connection or not
Authenticate:false indicates that monitoring does not require users and passwords.
3.2. User name and password need to be configured:
CATALINA_OPTS= "$CATALINA_OPTS-Dcom.sun.management.jmxremote-Djava.rmi.server.hostname=192.168.100.117-Dcom.sun.management.jmxremote.port=9999-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=true-Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password-Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"
Screenshot after configuration:
Parameter description:
Authenticate: enable account verification for true
Access.file: permissions file path
Password.file: password file path
3.3. This step is not required when password authentication is not configured. This step is required when users are enabled and password authentication is enabled.
3.3.1. Find the jdk installation directory
If you don't know where to install to the directory, you can find it through the command:
# java-verbose
3.3.2. Change to the jdk directory
Enter # cd jre/lib/management/
There will be jmxremote.access jmxremote.password.template files in the file directory and copied to the conf directory of tomcat
# cp jmxremote.* / opt/tomcat/apache-tomcat-8.0.48/conf/
3.3.3. Modify jmxremote.access file
3.3.4. Rename the password file:
# mv jmxremote.password.template jmxremote.password
3.3.5. Edit password file
# vim jmxremote.password
3.3.6. After editing the file, modify the permissions of the access file and the password file, otherwise tomcat will not start.
# chmod 600 jmxremote.*
4. Start tomcat
[root@ha bin] #. / startup.sh Using CATALINA_BASE: / opt/tomcat/apache-tomcat-8.0.48Using CATALINA_HOME: / opt/tomcat/apache-tomcat-8.0.48Using CATALINA_TMPDIR: / opt/tomcat/apache-tomcat-8.0.48/tempUsing JRE_HOME: / usrUsing CLASSPATH: / opt/tomcat/apache-tomcat-8.0.48/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-8.0.48/bin/tomcat-juli.jarTomcat started.
4.1. after doing the above, use the jvisualvm.exe connection that comes with jdk, and you can test it under windows
Double-click to open the jmx connection
Restart tomcat to test whether jmx can still be connected
#. / shutdown.sh
4.2.1. Connect to jmx again to see if you can connect to
The data monitoring chart can not be viewed and cannot be connected.
Why did this problem arise?
The conclusion given on the Internet is:
Tomcat's jmx remote health needs two ports, one is the registration port and the other is the service port. The 9999 port specified in the previous configuration is the registration port, and tomcat will randomly specify a service port when it is started. Because we have only one registered port, after restarting the service, the registration port has not changed, and the service port has changed. Once again through the registration port connection can not connect to the previous service port, there is no way to specify the server connection, the service port is random.
One way is to set the fixed registration port and service port of jmx, which is implemented through the jar package.
5. Log in to the tomcat official website (note that only 1.8.5 can be used on my tomcat version 1.8.0 official website)
Web site: https://tomcat.apache.org/
Find JMX Remote jar based on your tomcat version
6. Upload what you downloaded to the lib directory of tomcta
You can also wget the connection to the jar package directly to the lib directory.
# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/extras/catalina-jmx-remote.jar
7. Edit the server.xml file under the conf directory of tomcat
# vim server.xml
Add the following:
8. Edit catalina.sh under the bin directory of tomcat
# vim catalina.sh
Delete parameters:
-Dcom.sun.management.jmxremote.port=9999
9. Restart tomcat test. Jmx registration port is 10001 and service port is 10002.
10. Restart the tomcat connection test again
When we double-click the jmx remote connection created earlier, we will find that it cannot be connected. Why? here we should pay attention to the pid number in the above connection. After query, we find that this pid number is the pid number of tomcat in linux. When we restart tomcat, a new pid number will be generated, so we need to create a new connection if we want to connect.
11. When we create a new jmx connection, we will get a new pid number.
12. At this point, we have successfully tested it, so that when we use zabbix to monitor tomcat using jmx, we do not have to worry about tomcat restarting the jmx port connection.
Thank you for reading! This is the end of the article on "how to turn on JMX monitoring through Tomcat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.