温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

雪山飞鹄

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

BlogJava 首页 新随笔 联系 聚合 管理
  215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
  1. 单台Linux服务器中如何部署多个独立应用,即多个应用不能run在一个jboss实例中?
    换言之,这个问题也可以这样描述:在单台Linux服务器中服务启动多个Jboss实例?
    默认情况下,jboss启动时加载server/default/目录下的配置,要实现多个实例的启动,主要是解决端口冲突的问题,因为一套端口只能被一个应用占有;
    一般来说,我们可以在Jboss启动时通过-Djboss.server.home设置当前实例启动时加载不同的目录来实现;
    比如Jboss主程序安装在/usr/xx/jboss/,应用放在/home/admin/app/;那此时就可以cp一份default目录到当前应用app目录下,通过-Djboss.server.home=/home/admin/app/default来启动该实例;
    若直接在/usr/xx/jboss/server/下复制default目录并改名为yy,则可以用更简单的参数-c yy来启动;
    对于多应用的情况,我们仍然要解决端口冲突的问题,有两种方式:
    其一,直接修改各应用对应的default目录下的所有配置端口,主要涉及配置文件conf/jboss-service.xml、tomcat下的server.xml;该方法比较土,很容易出错,因为端口众多,只要有一项端口没有改,jboss就将无法正常启动;若应用较少,比如就只有2个,那这种方式勉强可以用用;
    其二,在jboss-service.xml中启用jboss.system:service=ServiceBindingManager这个mbean服务,设置ServerName、StoreURL属性;将各套应用对应的端口全部配置在同一个文件中;推荐采用该方案,具体可参考:

  1. <mbean code="org.jboss.services.binding.ServiceBindingManager" 
  2.   name="jboss.system:service=ServiceBindingManager"> 
  3.   <attribute name="ServerName">ports-01</attribute> 
  4.   <attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute> 
  5.   <attribute name="StoreFactoryClassName"> 
  6.     org.jboss.services.binding.XMLServicesStoreFactory 
  7.   </attribute> 
  8. </mbean> 

 

  • Jboss无法正常启动,报异常javax.management.MBeanRegistrationException: preRegister() failed?
    一般来说,上面的异常出现在4.2及其以后的版本中,比较详细的异常如下:
    1. javax.management.MBeanRegistrationException: preRegister() failed: [ObjectName='jboss.remoting:service=NetworkRegistry', Class=org.jboss.remoting.network.NetworkRegistry (org.jboss.remoting.network.NetworkRegistry@16b6c55)] 
    2.         at org.jboss.mx.server.registry.BasicMBeanRegistry.invokePreRegister(BasicMBeanRegistry.java:713
    3.         at org.jboss.mx.server.registry.BasicMBeanRegistry.registerMBean(BasicMBeanRegistry.java:211
    4.         at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    5.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25
    6.         at java.lang.reflect.Method.invoke(Method.java:585
    7.         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155
    8.         ... 51 more 
    9. Caused by: java.lang.RuntimeException: Exception creating identity: mall_dev4: mall_dev4 
    10.         at org.jboss.remoting.ident.Identity.get(Identity.java:211
    11.         at org.jboss.remoting.network.NetworkRegistry.preRegister(NetworkRegistry.java:268
    12.         at org.jboss.mx.server.AbstractMBeanInvoker.invokePreRegister(AbstractMBeanInvoker.java:966
    13.         at org.jboss.mx.modelmbean.ModelMBeanInvoker.invokePreRegister(ModelMBeanInvoker.java:489
    14.         at org.jboss.mx.server.AbstractMBeanInvoker.preRegister(AbstractMBeanInvoker.java:654
    15.         at org.jboss.mx.server.registry.BasicMBeanRegistry.invokePreRegister(BasicMBeanRegistry.java:697
    16.         ... 56 more 

    这主要是因为Jboss启动了一个jboss.remoting:service=NetworkRegistry的mbean服务,启动时却又无法根据当前hostname找到IP!
    解决方案为在/etc/hosts中绑定当前服务器的主机名和IP,比如10.2.224.214 mall_dev4;
    对于4.2系列之前的版本,如果没有绑定主机名和IP,虽然会出现以下的异常,但并不一定会影响应用的正常启动;
    1. 11:32:12,427 WARN  [ServiceController] Problem starting service jboss:service=invoker,type=http 
    2. java.net.UnknownHostException: mall_dev4: mall_dev4 
    3.         at java.net.InetAddress.getLocalHost(InetAddress.java:1308
    4.         at org.jboss.invocation.http.server.HttpInvoker.checkInvokerURL(HttpInvoker.java:204
    5.         at org.jboss.invocation.http.server.HttpInvoker.startService(HttpInvoker.java:101
    6.         at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289
    7.         at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245
    8.         at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) 
    9.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25
    10.         at java.lang.reflect.Method.invoke(Method.java:585
    11.         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155
    12.         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94
    13.         at org.jboss.mx.server.Invocation.invoke(Invocation.java:86
    14.         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264
    15.         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659
    16.         at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978
    17.         at $Proxy0.start(Unknown Source) 
    18.         at org.jboss.system.ServiceController.start(ServiceController.java:417
  • Jboss已经正常启动,但是无法用IP或者绑定IP访问应用?
    熟悉Linux相关知识的筒靴都知道一个端口是绑定在某个地址上的,可以是一个,也可以是多个,一个端口在同一个地址上不能被两个应用占有;
    出现这个问题一般是因为你使用的是4.2系列及其之后的版本,因为从这个系列开始,Jboss默认绑定的端口由之前的0.0.0.0变成了127.0.0.1;前者表示绑定当前服务器下所有地址,包括自身的IP、127.0.0.1;而后者只绑定了127.0.0.1,而没有绑定本机IP,通过IP去访问应用自然也就无法成功了,因为访问的IP地址没有开放对应的端口;
    对于默认的这种情况,一般来说jboss是要和apache搭配使用的,apache暴露应用外部访问的端口,然后apache再监听本地(也就是127.0.0.1)的端口;
    当然这个默认配置也是可以修改的,方式也比较多,比如:
    方式1,启动脚本中通过参数-b, --host=<host or ip>指定地址,比如-b 0.0.0.0就表示绑定所有地址;
    方式2,启动脚本中通过参数-Djboss.bind.address指定地址,比如-Djboss.bind.address=0.0.0.0;
    方式3,直接修改需要对外暴露的端口绑定地址,比如tomcat/server.xml中的http端口绑定address信息;
  • Jboss正常启动,但是用shutdown脚本无法关闭应用?
    对于jboss的关闭,shutdown命令允许好几种方式的关闭,可以参考该命令的帮助:
    1. usage: shutdown [options] <operation> 
    2. options: 
    3.     -h, --help                Show this help message (default
    4.     -D<name>[=<value>]        Set a system property 
    5.     --                        Stop processing options 
    6.     -s, --server=<url>        Specify the JNDI URL of the remote server 
    7.     -n, --serverName=<url>    Specify the JMX name of the ServerImpl 
    8.     -a, --adapter=<name>      Specify JNDI name of the MBeanServerConnection to use 
    9.     -u, --user=<name>         Specify the username for authentication 
    10.     -p, --password=<name>     Specify the password for authentication 
    11. operations: 
    12.     -S, --shutdown            Shutdown the server 
    13.     -e, --exit=<code>         Force the VM to exit with a status code 
    14.     -H, --halt=<code>         Force the VM to halt with a status code 
    一般来说,我们使用-s参数来关闭,也即通过JNDI URL;
    若是基于JNDI URL的方式出现这种情况一般有三种可能:
    其一,当前应用所使用的default目录内的内容与当前运行jboss自身的default内容不一致,比如当前jboss版本为4.0.5,而启动时指定的default却是从jboss 4.2.1中cp过来的;这种情况在搭建环境时经常出现,因为一般直接从另外一台linux服务器中scp过来,但其实两台服务器自身安装的jboss版本不一致;
    其二,shutdown命令中指定的JNDI端口与实际应用启动的JNDI端口不一致
    其三,/etc/hosts中对当前主机名绑定的IP地址不正确,比如当前服务器实际的IP地址为10.2.224.214,而hosts中绑定的却是10.0.0.1;
    总之,出现此类情况都是因为jboss自身无法正确接收到正确的关闭命令所致,一般来说在jboss的server.log中会抛如下的异常信息:
    1. Exception in thread "main" javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host: 10.0.0.1; nested exception is:  
    2.         java.net.ConnectException: Connection timed out]  
    3.         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:707)  
    4.         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)  
    5.         at javax.naming.InitialContext.lookup(InitialContext.java:351)  
    6.         at org.jboss.Shutdown.main(Shutdown.java:202)  
    7. Caused by: java.rmi.ConnectException: Connection refused to host: 10.0.0.1; nested exception is:  
    8.         java.net.ConnectException: Connection timed out  
    9.         at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)  
    10.         at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)  
    11.         at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)  
    12.         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)  
    13.         at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)  
    14.         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)  
    15.         ... 3 more  
  • 如何对Linux下的Jboss应用进行debug?
    其实这个问题和Jboss是否部署在Linux下没有直接关系,可以在jboss启动时指定远程debug端口即可,比如:
    1. -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n 

    然后在eclipse中新建remote debug时指定对应的端口即可;

  • Linux下Jboss启动、关闭、端口配置等常见问题FAQ 
    关于JBOSS端口被占用的问题
    posted on 2012-03-28 10:58 雪山飞鹄 阅读(5365) 评论(0)  编辑  收藏

    只有注册用户登录后才能发表评论。


    网站导航: