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


        由于实验室项目需要,将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配置文件修改的详细介绍


     第一部分——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.


     第二部分——项目中针对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.Finalinstandalone.conf.bat"
    ===============================================================================
    
      JBoss Bootstrap Environment
    
      JBOSS_HOME: K:jboss-as-7.1.1.Final
    
      JAVA: C:Program Files (x86)Javajdk1.7.0_79injava
    
      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.Finalstandalonedeployments
    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. 如有错误还恳请大神们批评指正,非常感谢!

  • 相关阅读:
    Myeclipse如何使用自带git工具向远程仓库提交代码
    myEclipse配置java版本(环境、项目、编译)
    新搭建项目时需要修改的内容
    干锅土豆
    SpringMVC MongoDB之“基本文档查询(Query、BasicQuery)”
    史上最全web.xml配置文件元素详解
    Web.xml配置详解之context-param
    史上最全的maven的pom.xml文件详解
    MongoDB 进阶模式设计
    备忘整理
  • 原文地址:https://www.cnblogs.com/nightowc/p/4589875.html
Copyright © 2020-2023  润新知