手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2015-06-20] 来源:Linux社区  作者:nightowc [字体: ]

由于实验室项目需要,将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

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款