JBoss入门

 很多内容摘自

https://www.jianshu.com/p/4baaf549436b

1.安装目录

安装完Jboss后得目录结构

目录功能
appclient/ 包含应用程序客户容器的配置细节。
bin/ 包含 Red Hat 企业版 Linux 和微软 Windows 上 JBoss EAP 的启动脚本。
docs/ 许可证文件、schema 和示例。
domain/ 配置文件、部署内容和 JBoss EAP 6 以受管域运行时使用的可写入区域。
modules/ 当有服务请求时 JBoss EAP 6 动态加载的模块。
standalone/ 配置文件、部署内容和 JBoss EAP 6 以独立服务器运行时使用的可写入区域。
welcome-content/ 包含默认安装里 8080 端口上的 Welcome 应用程序使用的内容。
jboss-modules.jar 加载模块的引导机制。

Domains中的结构

 

名称目的
configuration/ 用于受管域的配置文件。这些文件是通过管理控制台和 CLI 进行修改的,不能直接进行编辑。
data/ 关于已部署服务的信息。服务是用管理控制台或管理 CLI,而不是通过部署扫描器来部署的。因此,请不要手动在这个目录里放入文件。
log/ 包含运行在本地实例上的主机和进程控制器的运行时日志文件。
servers/ 包含某个域里的每个服务器实例的 data/、log/ 和 tmp/ 目录,其中包含的数据和顶层的 domain/
tmp/ 包含临时数据,如针对受管域检验本地用户的管理 CLI 使用的共享密钥机制相关的文件。

standalone/ 里的目录

名称目的
configuration/ 用于独立服务器的配置文件。这些文件是通过管理控制台和 CLI 进行修改的,不能直接进行编辑。
deployments/ 关于已部署服务的信息。独立服务器包含一个部署扫描器,您可以在这个目录里放入要部署的归档文件。然而,我们推荐的方法是用管理控制台或管理 CLI 来管理部署。
lib/ 附属于独立服务器模式的外部库。默认为空。
tmp/ 包含临时数据,如针对服务器检验本地用户的管理 CLI 使用的共享密钥机制相关的文件。

2.基本概念

  • jboss-eap-7.1有两种运行模式,standalone单机模式 和 domain集群模式。
  • jboss启动服务器时,默认读取的配置文件是${JBOSS_HOME}/standalone/configuration/standalone.xml。也可以指定读取其他配置文件,命令是./standalone.sh --server-config=standalone-custom.xml
  • jboss-cli(command line interface),是jboss的命令行管理工具。执行${JBOSS_HOME}/bin/jboss-cli.sh即可进入。通过命令行实现部署卸载应用、配置系统设置和执行管理任务的功能。使用该工具修改系统配置时,最终也会作用到standalone.xml中。
  • Management Console,管理控制台。是jboss提供的web管理系统,地址在http://localhost:9990/console/App.html, 所有的操作均可通过jboss-cli实现。

3.standalone.xml配置

修改监听地址

<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>

缺省绑定本机,可以修改成具体的ip,如果修改成0.0.0.0则绑定所有的ip

  • 端口配置
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <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:9993}"/>
        <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
        <socket-binding name="http" port="${jboss.http.port:8080}"/>
        <socket-binding name="https" port="${jboss.https.port:8443}"/>
        <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>

基于协议修改不同的端口

  • 数据源配置
 <subsystem xmlns="urn:jboss:domain:datasources:5.0">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

其中driver的libray目录主要需要看module模块,上面例子放在

E:eap7modulessystemlayersasecomh2databaseh2main 路径下。同时此目录下需要放置module.xml文件,格式如下:

<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2010, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->

<module xmlns="urn:jboss:module:1.5" name="com.h2database.h2">
    <properties>
        <property name="jboss.api" value="unsupported"/>
    </properties>


    <resources>
        <resource-root path="h2-1.4.193.redhat-2.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>
  • undertow配置
<subsystem xmlns="urn:jboss:domain:undertow:4.0">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <filter-ref name="server-header"/>
            <filter-ref name="x-powered-by-header"/>
            <http-invoker security-realm="ApplicationRealm"/>
        </host>
            </server>
    <servlet-container name="default">
        ………… ………… …………
    </servlet-container>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
        ………… ………… …………
    </filters>
</subsystem>

修改后配置为

<subsystem xmlns="urn:jboss:domain:undertow:4.0">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true" url-charset="GBK" decode-url="false"/>
        <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <!-- <location name="/" handler="welcome-content"/> -->
            <filter-ref name="server-header"/>
            <filter-ref name="x-powered-by-header"/>
            <http-invoker security-realm="ApplicationRealm"/>
            <filter-ref name="request-dumper"/>
            <access-log pattern="combined" directory="${jboss.home.dir}/standalone/log"/>
        </host>
            </server>
    <servlet-container name="default" default-encoding="GBK" use-listener-encoding="true">
        ………… ………… …………
    </servlet-container>
    <!-- <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers> -->
    <filters>
        ………… ………… …………
        <filter name="request-dumper" class-name="io.undertow.server.handlers.RequestDumpingHandler" module="io.undertow.core"/>
    </filters>
</subsystem>
  • 修改http请求设置:在http-listener标签中,增加了url-charset和decode-url。其中url-charset默认使用的UTF-8,可以根据需要修改。decode-url指是否使用字符集解码url和参数,默认为true。设为false则交由后续代码进行解码处理。http-listener的详细配置属性点击这里
  • 修改容器默认字符集:在servlet-container标签中,default-encoding设置所有应用的字符集(默认为utf-8),use-listener-encoding指是否使用listener定义的编码。servlet-container的详细配置属性点击这里
  • 移除Jboss默认欢迎页面:配置文件中注释的部分,就是jboss默认欢迎页面的配置。直接注释就是将其移除,也可以将默认地址映射到某个应用上。
  • 开启http访问日志:在host标签下增加access-log这一标签,即可将http请求的信息记在日志中,便于调试。directory是日志存放的目录,默认文件名为access_log.log。pattern是要日志中记录的信息,预定义了common和combined两种模式,combined的信息丰富一些。自定义的输出模式详见此处
  • 输出http请求和响应的信息:在filters标签下增加名为request-dumper的filter,在host标签下增加命名一致的filter-ref,就能在jboss日志中输出每一个http请求的request和response信息,便于调试。
  • 应用部署
 <subsystem xmlns="urn:jboss:domain:deployment-scanner:2.0">
            <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" runtime-failure-causes-rollback="${jboss.deployment.scanner.rollback.on.failure:false}"/>
        </subsystem>

全自动模式

在默认配置下,将war包上传至${JBOSS_HOME}/standalone/deployments,服务器会在启动时和每5000毫秒间隔,检查deployments下的文件变化,部署应用。

半自动模式

增加属性 auto-deploy-zipped="false"
上传应用myApp.war至deployments文件夹后,在deployments文件夹下新建一个文件,命名为myApp.war.dodeploy,服务器检测到这个文件后,则会开始执行部署。

手动模式

增加属性scan-enabled="false"
此模式是官方推荐的生产环境部署应用方式,无需将应用上传至deployments文件夹下。首先保证myApp.war在服务器上,假设其路径为/usr/me/myApp.war
启动服务器,并使用./jboss-cli.sh --connect命令进入命令行管理界面。执行命令deploy /usr/me/myApp.war部署应用。取消部署时,在命令行管理界面执行 undeploy myApp.war
应用的数据会在${JBOSS_HOME}/standalone/data/content下,并且standalone.xml最下方会出现deployments标签,显示已经部署的应用。



 
原文地址:https://www.cnblogs.com/ericnie/p/9706428.html