国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Tomcat:使用JMX監管Tomcat的幾種方式

2019-11-14 23:29:39
字體:
來源:轉載
供稿:網友
Tomcat:使用JMX監管Tomcat的幾種方式

Tomcat使用JMX管理方式,在Tomcat的自帶應用manager就是使用了JMX方式來管理Tomcat,以此完成Web應用的動態部署、啟動、停止。

然而manager應用是一種本地使用JMX接口的方式。對于其它的遠程客戶端該 怎么做呢?

方式1:JConsole客戶端:

1)設置環境變量CATALINA:

set CATALINA_OPTS=-Dcom.sun.management.jmxremote  -Dcom.sun.management.jmxremote.port=9999  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false

這是Windows的設置方式。

linux /Unix 設置方式:exportCATALINA_OPTS=-Dcom.sun.management.jmxremote' 'CATALINA_OPTS=-Dcom.sun.management.jmxremote' 'CATALINA_OPTS=-Dcom.sun.management.jmxremote' '-Dcom.sun.management.jmxremote.authenticate=false

網上有很多人說是設置java_OPTS,建議不要這么做。

2)啟動Tomcat

3)打開JConsole,設置遠程連接地址:tomcat_ip:9999

tomcat_ip 是Tomcat所在機器的IP,9999就是上面設置的端口。

方式二:使用Ant build.xml

具體使用方式參見:http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#JMXaccessorGetTask:__get_attribute_value_Ant_task

原理同下。

方式三:在Java代碼中使用Ant Task

GetTask task=new GetTask();task.setURL("http://tomcat_ip:9999/manager");task.setUser("xxx");task.setPassWord("xxx");PRoject pro=new Project();task.setOutproperty("output");task.setProject(pro);task.execute();String responseText=project.getProperty("output");

原理:使用url連接訪問manager應用,從而manager使用JMX管理。

方式四:在Java代碼中直接訪問manager應用

public void tomcatHome(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        URL url=new URL("http://localhost:8080/manager/html");        HttpURLConnection  conn=(HttpURLConnection)url.openConnection();                conn.setAllowUserInteraction(false);        conn.setDoInput(true);        conn.setUseCaches(false);                conn.setDoOutput(false);        conn.setRequestMethod("GET");                conn.setRequestProperty("Accept-Charset", "utf-8");        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");                String username="admin";        String password="admin";        String authoInfo=new String(Base64.encode((username + ":" + password).getBytes()));        conn.setRequestProperty("Authorization", "Basic "+authoInfo);        conn.setRequestProperty("Connection", "keep-alive");        conn.connect();                InputStream input=conn.getInputStream();        response.setContentType("text/html;charset=UTF-8");        PrintWriter out= response.getWriter();        byte[] bs=new byte[1024];        int len=-1;                while((len=input.read(bs))!=-1){            out.write(new String(bs, 0, len));        }        out.flush();        out.close();            }

原理同上。

方式五:在Java中直接使用JMX API訪問

參見我前面的博文 。當然了,這種方式,網絡上也是常見的。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄯善县| 沅江市| 保亭| 墨竹工卡县| 马边| 武定县| 天水市| 九台市| 伊吾县| 青海省| 马关县| 安徽省| 林周县| 福泉市| 边坝县| 容城县| 巢湖市| 保靖县| 宣武区| 阿图什市| 年辖:市辖区| 长沙市| 都昌县| 沧州市| 循化| 永福县| 兴业县| 漳平市| 高密市| 连山| 泰来县| 肥乡县| 丰镇市| 柘荣县| 辉县市| 招远市| 贵州省| 封丘县| 册亨县| 千阳县| 阿坝|