阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

JBoss7配置-支持IPv4和IPv6双栈环境

182次阅读
没有评论

共计 17078 个字符,预计需要花费 43 分钟才能阅读完成。

由于实验室项目需要,将 EJB 3.0 的程序部署在 JBoss AS 7.1.1.Final 中,并要求支持 IPv4 与 IPv6。但其默认配置并不支持 IPv6,于是查阅 JBoss Community Documentation,即官方文档,在 5.4.1 Interfaces and ports 节中找到了相关介绍,研究后对 JBoss 进行配置修改,使 JBoss 中 EJB 3.0 的程序能够在 IPv4 和 IPv6 双栈环境下正常运行,包括客户端在 IPv4 环境下获取 Remote 远程接口对象,调用远程对象的方法收发 IPv6 的 udp 报文等。本文不细讲 EJB 程序,只介绍如何配置 JBoss 使其支持 IPv4 和 IPv6 双栈环境。

文章结构

    第一部分——JBoss7.1 官方文档中关于 IPv6 部分的说明

    第二部分——项目中针对 JBoss 配置文件修改的详细介绍

——————————————————————————–

Linux 服务器 JBoss 运行环境搭建步骤和开机自动启动脚本编写运行  http://www.linuxidc.com/Linux/2015-01/111484.htm

RHEL6.5 安装 OpenJDK1.7.0 + JBoss7.1.1 + Maven3.0.4  http://www.linuxidc.com/Linux/2014-04/99854.htm

企业 Java 应用服务器之 JBoss7.1 与 Apache 整合  http://www.linuxidc.com/Linux/2014-03/98495.htm

Linux 环境下以后台运行方式启动 JBoss  http://www.linuxidc.com/Linux/2014-04/99290.htm

——————————————————————————–

 第一部分——JBoss7.1 官方文档中关于 IPv6 部分的说明

5.4.1 Interfaces and ports

Interface declarations

    domain.xml, host.xml 和 standalone.xml 都包含声明接口的部分。当我们看这些在 XML 文件中接口声明时,就会发现接口的选择条件 (selection criteria) 有两种类型: 一种是单独的 XML 元素,接口绑定到通配符地址;另外一种是接口或者地址有一个或者多个特征值需要满足。

    举例说明,首先是一个接口条件选择的例子,每个接口都有特定的 IP 地址:

<interfaces>
  <interface name=”management”>
    <inet-address value=”127.0.0.1″/>
  </interface>
  <interface name=”public”>
    <inet-address value=”127.0.0.1″/>
  </interface>
</interfaces>

    接着是使用通配符的例子:

<interface name=”global”>
  <!– Use the wildcard address –>
  <any-address/>
</interface>

<interface name=”ipv4-global”>
  <!– Use the IPv4 wildcard address –>
  <any-ipv4-address/>
</interface>

<interface name=”ipv6-global”>
  <!– Use the IPv6 wildcard address –>
  <any-ipv6-address/>
</interface>

<interface name=”external”>
  <nic name=”eth0″/>
</interface>

Socket Binding Groups

    JBoss AS 7 中 socket 的配置类似于 interface 的声明,Sockets 用一个逻辑名来声明,可以在整个配置中引用。多个 Sockets 声明可以用一个特定的名字声明成为一个组。这样在配置一个在管理域里的 server group 时可以方便的引用一个特定的 socket binding group。Socket binding group 通过接口逻辑名来引用接口:

<socket-binding-group name=”standard-sockets” default-interface=”public”>
  <socket-binding name=”jndi” port=”1099″/>
  <socket-binding name=”jmx-connector-registry” port=”1090″/>
  <socket-binding name=”jmx-connector-server” port=”1091″/>
  <socket-binding name=”http” port=”8080″/>
  <socket-binding name=”https” port=”8443″/>
  <socket-binding name=”jacorb” port=”3528″/>
  <socket-binding name=”jacorb-ssl” port=”3529″/>
  <socket-binding name=”osgi-http” port=”8090″/>
  <socket-binding name=”remoting” port=”4447″/>
  <socket-binding name=”txn-recovery-environment” port=”4712″/>
  <socket-binding name=”txn-status-manager” port=”4713″/>
  <socket-binding name=”messaging” port=”5445″/>
  <socket-binding name=”messaging-throughput” port=”5455″/>
</socket-binding-group>

一个 socket binding 包含以下信息:
•name – socket 配置的逻辑名,可以在配置的其他任何地方引用。
•port –  这个配置中 socket 要绑定到的基础端口(注意 server 可以通过配置增减所有端口值来覆盖这一配置。)
•interface(可选)– 配置中 socket 要绑定接口的逻辑名(参考上面的接口声明)。如果没有指定,socket binding group 配置元素中的 default-interface 属性值将会被使用。
•multicast-address(可选)– 如果 socket 用于多播,将会使用这个多播地址。
•multicast-port(可选)–  如果 socket 用于多播,将会使用这个多播端口
•fixed-port(可选, 默认是 false)– 如果是 true,  端口值将一直使用这个值,这个值不会被使用增减端口值而覆盖。

IPv4 versus IPv6

    JBoss AS7 supports the use of both IPv4 and IPv6 addresses. By default, AS7 is configured for use in an IPv4 network and so if you are running AS7 in an IPv4 network, no changes are required. If you need to run AS7 in an IPv6 network, the changes required are minimal and involve changing the JVM stack and address preferences, and adjusting any interface IP address values specified in the configuration (standalone.xml or domain.xml).

Stack and address preference

    The system properties java.net.preferIPv4Stack and java.net.preferIPv6Addresses are used to configure the JVM for use with IPv4 or IPv6 addresses. With AS7, in order to run using IPv4 addresses, we need to specify java.net.preferIPv4Stack=true; in order to run the AS7 with IPv6 addresses, we need to specify java.net.preferIPv4Stack=false (the JVM default) and java.net.preferIPv6Addresses=true. The latter ensures that any hostname to IP address conversions always return IPv6 address variants.

    These system properties are conveniently set by the JAVA_OPTS environment variable, defined in the standalone.conf (or domain.conf) file. For example, to change the IP stack preference from its default of IPv4 to IPv6, edit the standalone.conf (or domain.conf) file and change its default IPv4 setting:

if [“x$JAVA_OPTS” = “x”]; then
JAVA_OPTS=” … -Djava.net.preferIPv4Stack=true …”

to an IPv6 suitable setting:

if [“x$JAVA_OPTS” = “x”]; then
JAVA_OPTS=” … -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true …”

IP address literals

    To change the IP address literals referenced in standalone.xml (or domain.xml), first visit the interface declarations and ensure that valid IPv6 addresses are being used as interface values. For example, to change the default configuration in which the loopback interface is used as the primary interface, change from the IPv4 loopback address:

<interfaces>
  <interface name=”management”>
    <inet-address value=”${jboss.bind.address.management:127.0.0.1}”/>
  </interface>
  <interface name=”public”>
    <inet-address value=”${jboss.bind.address:127.0.0.1}”/>
  </interface>
</interfaces>

to the IPv6 loopback address:

<interfaces>
  <interface name=”management”>
    <inet-address value=”${jboss.bind.address.management:[::1]}”/>
  </interface>
  <interface name=”public”>
    <inet-address value=”${jboss.bind.address:[::1]}”/>
  </interface>
</interfaces>

    Note that when embedding IPv6 address literals in the substitution expression, square brackets surrounding the IP address literal are used to avoid ambiguity. This follows the convention for the use of IPv6 literals in URLs.
    Over and above making such changes for the interface definitions, you should also check the rest of your configuration file and adjust IP address literals from IPv4 to IPv6 as required.

——————————————————————————–

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-06/119101p2.htm

第二部分——项目中针对 JBoss 配置文件修改的详细介绍

    根据如上的介绍,为了使 JBoss 支持 IPv6,我们需要修改 JBoss 的两个配置文件。其一,修改 standalone.xml 中接口声明部分和 socket 端口绑定;其二,修改 standalone.conf 里面的 JVM stack 和 address preferences。

    1. standalone.xml,文件路径:$JBOSS-HOME/standalone/configuration

    打开后可看到接口声明部分(interfaces)和 socket 端口绑定部分(socket-binding-group—)初始状态如下。接口声明中 management、public、unsecure 都指定的是 jboss 的本地回环地址,socket 绑定默认接口就是 public,前三个指定的是 management 接口,unsecure 接口未使用。

<interfaces>
        <interface name=”management”>
            <inet-address value=”${jboss.bind.address.management:127.0.0.1}”/>
        </interface>
        <interface name=”public”>
            <inet-address value=”${jboss.bind.address:127.0.0.1}”/>
        </interface>
        <interface name=”unsecure”>
            <inet-address value=”${jboss.bind.address.unsecure:127.0.0.1}”/>
        </interface>
    </interfaces>

    <socket-binding-group name=”standard-sockets” default-interface=”public” port-offset=”${jboss.socket.binding.port-offset:0}”>
        <socket-binding name=”management-native” interface=”management” port=”${jboss.management.native.port:9999}”/>
        <socket-binding name=”management-http” interface=”management” port=”${jboss.management.http.port:9990}”/>
        <socket-binding name=”management-https” interface=”management” port=”${jboss.management.https.port:9443}”/>
        <socket-binding name=”ajp” port=”8009″/>
        <socket-binding name=”http” port=”8080″/>
        <socket-binding name=”https” port=”8443″/>
        <socket-binding name=”osgi-http” interface=”management” port=”8090″/>
        <socket-binding name=”remoting” port=”4447″/>
        <socket-binding name=”txn-recovery-environment” port=”4712″/>
        <socket-binding name=”txn-status-manager” port=”4713″/>
        <outbound-socket-binding name=”mail-smtp”>
            <remote-destination host=”localhost” port=”25″/>
        </outbound-socket-binding>
    </socket-binding-group>

    为满足 JBoss 能够支持 IPv4 和 IPv6 双栈环境,则要将接口的选择条件修改为绑定到通配符状态,即 <any-address/>,而 socket 绑定部分可不做修改,

接口声明部分修改后如下:

<interfaces>
        <interface name=”management”>
            <any-address/>
        </interface>
        <interface name=”public”>
            <any-address/>
        </interface>
        <interface name=”unsecure”>
            <inet-address value=”${jboss.bind.address.unsecure:127.0.0.1}”/>
        </interface>
    </interfaces>

    2. standalone.conf.bat,文件路径:$JBOSS-HOME/bin

    注意这里修改的不是 standalone.conf 文件,因为修改该文件并没有使 IPv6 address 生效,亲测只有修改 standalone.conf.bat 文件才会生效。修改方法和第一部分里面 Stack and address preference 小节介绍一样,就是将 -DJava.net.preferIPv4Stack=true 修改为 -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true 即可,这样 JVM 启动的时候默认的是 IPv6 格式的地址,查看打印输出即可验证正确与否。

Calling “K:\jboss-as-7.1.1.Final\bin\standalone.conf.bat”
===============================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: K:\jboss-as-7.1.1.Final

  JAVA: C:\Program Files (x86)\Java\jdk1.7.0_79\bin\java

  JAVA_OPTS: -XX:+TieredCompilation -Dprogram.name=standalone.bat -Xms64M -Xmx51
2M -XX:MaxPermSize=256M -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.se
rver.gcInterval=3600000 -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Ad
dresses=true -Dorg.jboss.resolver.warning=true -Djboss.modules.system.pkgs=org.j
boss.byteman -Djboss.server.default.config=standalone.xml

===============================================================================

22:39:47,729 信息    [org.jboss.modules] JBoss Modules version 1.1.1.GA
22:39:48,182 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
22:39:48,322 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final “Brontes” sta
rting
22:39:50,572 INFO  [org.xnio] XNIO Version 3.0.3.GA
22:39:50,572 INFO  [org.jboss.as.server] JBAS015888: Creating http management se
rvice using socket-binding (management-http)
22:39:50,604 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
22:39:50,619 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
22:39:50,666 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log han
dlers
22:39:50,682 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Po
ol — 31) JBAS010280: Activating Infinispan subsystem.
22:39:50,729 INFO  [org.jboss.as.naming] (ServerService Thread Pool — 38) JBAS0
11800: Activating Naming Subsystem
22:39:50,744 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool — 26)
JBAS016200: Activating ConfigAdmin Subsystem
22:39:50,776 INFO  [org.jboss.as.connector] (MSC service thread 1-1) JBAS010408:
 Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
22:39:50,776 INFO  [org.jboss.as.security] (ServerService Thread Pool — 44) JBA
S013101: Activating Security Subsystem
22:39:50,807 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-1) JBAS01
5400: Bound mail session [java:jboss/mail/Default]
22:39:50,791 INFO  [org.jboss.as.naming] (MSC service thread 1-8) JBAS011802: St
arting Naming Service
22:39:50,885 INFO  [org.jboss.as.webservices] (ServerService Thread Pool — 48)
JBAS015537: Activating WebServices Extension
22:39:51,010 INFO  [org.jboss.as.osgi] (ServerService Thread Pool — 39) JBAS011
940: Activating OSGi Subsystem
22:39:51,010 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerServic
e Thread Pool — 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Dr
iver (version 1.3)
22:39:51,026 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013100:
Current PicketBox version=4.0.7.Final
22:39:51,385 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC se
rvice thread 1-8) JBoss Web Services – Stack CXF Server 4.0.2.GA
22:39:52,135 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread
 1-4) Starting Coyote HTTP/1.1 on http–0_0_0_0_0_0_0_0-8080
22:39:52,526 INFO  [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100:
Listening on /0:0:0:0:0:0:0:0:4447
22:39:52,526 INFO  [org.jboss.as.remoting] (MSC service thread 1-5) JBAS017100:
Listening on /0:0:0:0:0:0:0:0:9999
22:39:52,526 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread
1-8) JBAS015012: Started FileSystemDeploymentService for directory K:\jboss-as-7
.1.1.Final\standalone\deployments
22:39:52,838 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service
thread 1-8) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
22:39:53,073 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin con
sole listening on http://[0:0:0:0:0:0:0:0]:9990
22:39:53,073 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS
7.1.1.Final “Brontes” started in 6079ms – Started 133 of 209 services (75 servic
es are passive or on-demand)

p.s. 如有错误还恳请大神们批评指正,非常感谢!

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-06/119101.htm

由于实验室项目需要,将 EJB 3.0 的程序部署在 JBoss AS 7.1.1.Final 中,并要求支持 IPv4 与 IPv6。但其默认配置并不支持 IPv6,于是查阅 JBoss Community Documentation,即官方文档,在 5.4.1 Interfaces and ports 节中找到了相关介绍,研究后对 JBoss 进行配置修改,使 JBoss 中 EJB 3.0 的程序能够在 IPv4 和 IPv6 双栈环境下正常运行,包括客户端在 IPv4 环境下获取 Remote 远程接口对象,调用远程对象的方法收发 IPv6 的 udp 报文等。本文不细讲 EJB 程序,只介绍如何配置 JBoss 使其支持 IPv4 和 IPv6 双栈环境。

文章结构

    第一部分——JBoss7.1 官方文档中关于 IPv6 部分的说明

    第二部分——项目中针对 JBoss 配置文件修改的详细介绍

——————————————————————————–

Linux 服务器 JBoss 运行环境搭建步骤和开机自动启动脚本编写运行  http://www.linuxidc.com/Linux/2015-01/111484.htm

RHEL6.5 安装 OpenJDK1.7.0 + JBoss7.1.1 + Maven3.0.4  http://www.linuxidc.com/Linux/2014-04/99854.htm

企业 Java 应用服务器之 JBoss7.1 与 Apache 整合  http://www.linuxidc.com/Linux/2014-03/98495.htm

Linux 环境下以后台运行方式启动 JBoss  http://www.linuxidc.com/Linux/2014-04/99290.htm

——————————————————————————–

 第一部分——JBoss7.1 官方文档中关于 IPv6 部分的说明

5.4.1 Interfaces and ports

Interface declarations

    domain.xml, host.xml 和 standalone.xml 都包含声明接口的部分。当我们看这些在 XML 文件中接口声明时,就会发现接口的选择条件 (selection criteria) 有两种类型: 一种是单独的 XML 元素,接口绑定到通配符地址;另外一种是接口或者地址有一个或者多个特征值需要满足。

    举例说明,首先是一个接口条件选择的例子,每个接口都有特定的 IP 地址:

<interfaces>
  <interface name=”management”>
    <inet-address value=”127.0.0.1″/>
  </interface>
  <interface name=”public”>
    <inet-address value=”127.0.0.1″/>
  </interface>
</interfaces>

    接着是使用通配符的例子:

<interface name=”global”>
  <!– Use the wildcard address –>
  <any-address/>
</interface>

<interface name=”ipv4-global”>
  <!– Use the IPv4 wildcard address –>
  <any-ipv4-address/>
</interface>

<interface name=”ipv6-global”>
  <!– Use the IPv6 wildcard address –>
  <any-ipv6-address/>
</interface>

<interface name=”external”>
  <nic name=”eth0″/>
</interface>

Socket Binding Groups

    JBoss AS 7 中 socket 的配置类似于 interface 的声明,Sockets 用一个逻辑名来声明,可以在整个配置中引用。多个 Sockets 声明可以用一个特定的名字声明成为一个组。这样在配置一个在管理域里的 server group 时可以方便的引用一个特定的 socket binding group。Socket binding group 通过接口逻辑名来引用接口:

<socket-binding-group name=”standard-sockets” default-interface=”public”>
  <socket-binding name=”jndi” port=”1099″/>
  <socket-binding name=”jmx-connector-registry” port=”1090″/>
  <socket-binding name=”jmx-connector-server” port=”1091″/>
  <socket-binding name=”http” port=”8080″/>
  <socket-binding name=”https” port=”8443″/>
  <socket-binding name=”jacorb” port=”3528″/>
  <socket-binding name=”jacorb-ssl” port=”3529″/>
  <socket-binding name=”osgi-http” port=”8090″/>
  <socket-binding name=”remoting” port=”4447″/>
  <socket-binding name=”txn-recovery-environment” port=”4712″/>
  <socket-binding name=”txn-status-manager” port=”4713″/>
  <socket-binding name=”messaging” port=”5445″/>
  <socket-binding name=”messaging-throughput” port=”5455″/>
</socket-binding-group>

一个 socket binding 包含以下信息:
•name – socket 配置的逻辑名,可以在配置的其他任何地方引用。
•port –  这个配置中 socket 要绑定到的基础端口(注意 server 可以通过配置增减所有端口值来覆盖这一配置。)
•interface(可选)– 配置中 socket 要绑定接口的逻辑名(参考上面的接口声明)。如果没有指定,socket binding group 配置元素中的 default-interface 属性值将会被使用。
•multicast-address(可选)– 如果 socket 用于多播,将会使用这个多播地址。
•multicast-port(可选)–  如果 socket 用于多播,将会使用这个多播端口
•fixed-port(可选, 默认是 false)– 如果是 true,  端口值将一直使用这个值,这个值不会被使用增减端口值而覆盖。

IPv4 versus IPv6

    JBoss AS7 supports the use of both IPv4 and IPv6 addresses. By default, AS7 is configured for use in an IPv4 network and so if you are running AS7 in an IPv4 network, no changes are required. If you need to run AS7 in an IPv6 network, the changes required are minimal and involve changing the JVM stack and address preferences, and adjusting any interface IP address values specified in the configuration (standalone.xml or domain.xml).

Stack and address preference

    The system properties java.net.preferIPv4Stack and java.net.preferIPv6Addresses are used to configure the JVM for use with IPv4 or IPv6 addresses. With AS7, in order to run using IPv4 addresses, we need to specify java.net.preferIPv4Stack=true; in order to run the AS7 with IPv6 addresses, we need to specify java.net.preferIPv4Stack=false (the JVM default) and java.net.preferIPv6Addresses=true. The latter ensures that any hostname to IP address conversions always return IPv6 address variants.

    These system properties are conveniently set by the JAVA_OPTS environment variable, defined in the standalone.conf (or domain.conf) file. For example, to change the IP stack preference from its default of IPv4 to IPv6, edit the standalone.conf (or domain.conf) file and change its default IPv4 setting:

if [“x$JAVA_OPTS” = “x”]; then
JAVA_OPTS=” … -Djava.net.preferIPv4Stack=true …”

to an IPv6 suitable setting:

if [“x$JAVA_OPTS” = “x”]; then
JAVA_OPTS=” … -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true …”

IP address literals

    To change the IP address literals referenced in standalone.xml (or domain.xml), first visit the interface declarations and ensure that valid IPv6 addresses are being used as interface values. For example, to change the default configuration in which the loopback interface is used as the primary interface, change from the IPv4 loopback address:

<interfaces>
  <interface name=”management”>
    <inet-address value=”${jboss.bind.address.management:127.0.0.1}”/>
  </interface>
  <interface name=”public”>
    <inet-address value=”${jboss.bind.address:127.0.0.1}”/>
  </interface>
</interfaces>

to the IPv6 loopback address:

<interfaces>
  <interface name=”management”>
    <inet-address value=”${jboss.bind.address.management:[::1]}”/>
  </interface>
  <interface name=”public”>
    <inet-address value=”${jboss.bind.address:[::1]}”/>
  </interface>
</interfaces>

    Note that when embedding IPv6 address literals in the substitution expression, square brackets surrounding the IP address literal are used to avoid ambiguity. This follows the convention for the use of IPv6 literals in URLs.
    Over and above making such changes for the interface definitions, you should also check the rest of your configuration file and adjust IP address literals from IPv4 to IPv6 as required.

——————————————————————————–

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-06/119101p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计17078字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中