以下是在同一台服务器上运行多个 JBoss 实例的两种方式。
将每个实例绑定到不同的 IP 地址
这是解决此问题的最简单和最推荐的方法。如果服务器有多个 NIC,那么这很简单。如果不是,那么必须“多宿主”服务器。换言之,通过操作系统配置为服务器分配多个 IP 地址。像这样启动实例:
$JBOSS_HOME1/bin/run.sh -b <ip-addr-1>
$JBOSS_HOME2/bin/run.sh -b <ip-addr-2>
相同的$JBOSS_HOME 可以与$JBOSS_HOME/server 中的多个“配置文件”一起使用。例如:
$JBOSS_HOME/bin/run.sh -b <ip-addr-1> -c node1
$JBOSS_HOME/bin/run.sh -b <ip-addr-2> -c node2
服务绑定管理器
配置“服务绑定管理器”来告诉 JBoss 实例使用哪些端口。
取消注释$JBOSS_HOME/server/$PROFILE/conf/jboss-service.xml 中的“jboss.system:service=ServiceBindingManager”MBean。
<mbean code="org.jboss.services.binding.ServiceBindingManager"
name="jboss.system:service=ServiceBindingManager">
<attribute name="ServerName">ports-01</attribute>
<attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
<attribute name="StoreFactoryClassName">
org.jboss.services.binding.XMLServicesStoreFactory
</attribute>
</mbean>
这告诉 JBoss 使用由 $JBOSS_HOME/docs/examples/binding-manager/sample-bindings.xml 中的“ports-01”定义的端口编号方案。该方案将每个端口的第二个最高有效数字增加 100。例如,JNDI 端口默认为 1099,但使用 ports-01 方案为 1199; HTTP 端口默认为 8080,但使用 ports-01 方案时为 8180。 sample-bindings.xml 文件包含 4 个端口方案:
- 默认端口
- ports-01
- ports-02
- ports-03
您可能希望从命令行或通过系统属性配置启动时使用的端口集。如果是这样,请调整 MBean 的 ServerName 以引用系统属性,例如:
<mbean code="org.jboss.services.binding.ServiceBindingManager"
name="jboss.system:service=ServiceBindingManager">
<attribute name="ServerName">${jboss.service.binding.set:ports-default}</attribute>
<attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
<attribute name="StoreFactoryClassName">
org.jboss.services.binding.XMLServicesStoreFactory
</attribute>
</mbean>
现在通过run.sh/run.bat 上的以下属性直接更改它或将其添加到您的run.conf 选项中:
-Djboss.service.binding.set=ports-01
如果您需要在 sample-bindings.xml 中默认定义超过 4 个端口集,请参考以下 JBOSS 6 EAP 文章:
https://access.redhat.com/site/solutions/237933