在WebLogic Server上驯服JMX
讓我們先假設(shè)幾件事:
上面應(yīng)該可以讓您啟用JMX的獨(dú)立應(yīng)用程序。
現(xiàn)在,如果您想在WebLogic Server上執(zhí)行類似的操作,那么我的一些好東西和說明可能會(huì)對您有所幫助。 繼續(xù)閱讀...
WebLogic Server(WLS)的MBeanServer
JConsole技巧
像許多其他EE服務(wù)器一樣,WLS將擁有自己的MBeanServer。 但是,要查看MBean,您需要使用jconsole做一些額外的工作。 假設(shè)您有一個(gè)在本地主機(jī)上啟動(dòng)的默認(rèn)配置WLS,則可以像這樣連接到它。
jconsole -J-Djava.class.path="$JAVA_HOME/lib/jconsole.jar:$MW_HOME/wlserver/server/lib/wljmxclient.jar" -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote然后在提示您登錄時(shí),輸入以下內(nèi)容:
Remote Process: service:jmx:iiop://localhost:7001/jndi/weblogic.management.mbeanservers.runtime User: <same userid you used setup WLS to their console app.> Password: <same password you used setup WLS to their console app.>現(xiàn)在,您應(yīng)該看到WLS已經(jīng)作為EE服務(wù)器公開給您的所有MBean。 您可以在此處添加自己的服務(wù)。
使用JMX連接進(jìn)行編程
您可以在獨(dú)立應(yīng)用程序內(nèi)部遠(yuǎn)程連接到WLS MBeanServer。 這是您需要的典型連接代碼
String serviceName = "com.bea:Name=DomainRuntimeService,Type= weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";try {ObjectName service = new ObjectName(serviceName);} catch (MalformedObjectNameException e) {throw new RuntimeException("Not able to create JMX ObjectName: " + serviceName);}String protocol = "t3";String jndiroot = "/jndi/";String mserver = "weblogic.management.mbeanservers.runtime";try {JMXServiceURL serviceURL = new JMXServiceURL(protocol, "localhost", 7001, jndiroot + mserver);Hashtable h = new Hashtable();h.put(Context.SECURITY_PRINCIPAL, username);h.put(Context.SECURITY_CREDENTIALS, password);h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);MBeanServerConnection remoteMBeanServer = connector.getMBeanServerConnection();// TODO: Do what you need with remoteMBeanServer here.} catch (Exception e) {throw new RuntimeException("Not able to initiate MBeanServer protocol= " + protocol +", jndiroot= " + jndiroot + ", mserver= " + mserver);}只是為了獲得遠(yuǎn)程MBeanServer連接而準(zhǔn)備的大量鍋爐代碼! 幸運(yùn)的是,還有另一種更簡單的方法。 繼續(xù)閱讀...
JNDI技巧
也可以通過JNDI查找來使用WLS MBeanServer服務(wù)。 Spring可以再次幫助您進(jìn)行JNDI查找,您只需要將其注入需要它的其他服務(wù)即可。 例如:
<bean id="jmxServerRuntime" class="org.springframework.jndi.JndiObjectFactoryBean"><property name="jndiName" value="java:comp/env/jmx/runtime"/></bean><bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"><property name="beans"><map><entry key="myproject.services:name=MyCoolService" value-ref="myCoolService"/></map></property><property name="server" ref="jmxServerRuntime"/></bean>請注意,我們已經(jīng)從WLS JNDI服務(wù)中查找了一個(gè)“服務(wù)器”屬性。 如果在WAR應(yīng)用程序中使用它,并將其部署到WLS實(shí)例上,那么,您將可以在WLS JMX上使用公開服務(wù)!
注意
僅當(dāng)您的Spring xml配置是JAR所在的同一服務(wù)器中部署的WAR / JAR / EAR的一部分時(shí),以上方法才有效! 如果不是,則需要使用不帶“ env”部分的該JNDI名稱,例如“ java:comp / env / jmx / runtime”。
 有關(guān)如何使用JMX和WLS的更多詳細(xì)信息,請參見此處的文檔: http : //docs.oracle.com/cd/E12839_01/web.1111/e13728/accesswls.htm#i1119556 
翻譯自: https://www.javacodegeeks.com/2013/06/taming-the-jmx-on-weblogic-server.html
總結(jié)
以上是生活随笔為你收集整理的在WebLogic Server上驯服JMX的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: (linux %date)
- 下一篇: DDOS攻击行为(ddos攻击的行为)
