使用tomcat和mariadb在docker中加载数据在第一次加载时失败

时间:2016-07-14 08:19:50

标签: moqui

我部署了moqui和matel到docker环境,我使用docker-compose来设置两个docker comainter,tomcat和mariadb,并将它们链接在一起。

数据源conf

<entity-facade crypt-pass="MoquiDefaultPassword:CHANGEME">
    <datasource group-name="transactional" database-conf-name="mysql" schema-name="">
        <inline-jdbc>
            <xa-properties user="moqui" password="moqui" pinGlobalTxToPhysicalConnection="true" serverName="192.168.1.237" port="3400" databaseName="CJZCDefault" autoReconnectForPools="true"
                useUnicode="true" encoding="UTF-8"/>
        </inline-jdbc>
    </datasource>

    <datasource group-name="tenantcommon" database-conf-name="mysql" schema-name="">
        <inline-jdbc>
            <xa-properties user="moqui" password="moqui" pinGlobalTxToPhysicalConnection="true" serverName="192.168.1.237" port="3400" databaseName="CJZCDefault" autoReconnectForPools="true"
                useUnicode="true" encoding="UTF-8"/>
        </inline-jdbc>
    </datasource>
</entity-facade>

启动tomcat docker容器时,

run java -jar moqui-2.0.0.war -load 

首先加载数据,然后用

启动tomcat
catalina.sh run

第一次数据加载失败时,详细日志在下面,但第二次数据加载成功由tomcat触发。

如果没有显式运行war包加载,则在tomcat触发它时失败,并且数据库中没有初始化数据。

在使用docker mariadb的tomcat(不是在docker中)环境中运行完全正常。

也许我错了一些环境。如果有人遇到同样的问题,那么深入挖掘可能是值得的。

Creating network "thirdparty_default" with the default driver
Creating thirdparty_db-qa_1
Creating thirdparty_server-qa_1
[cjzcAdmin@HZ-CJZC-SF-web01 third-party]$ sudo docker logs -f thirdparty_server-qa_1
Using temporary directory: /usr/local/tomcat/webapps/ROOT/execwartmp
Determined runtime from existing runtime directory: runtime
Canonicalized runtimePath: /usr/local/tomcat/webapps/ROOT/runtime
Loading data with args [{load=}]
15:42:39.490  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Initializing Moqui ExecutionContextFactoryImpl
 - runtime directory: /usr/local/tomcat/webapps/ROOT/runtime
 - runtime config:    /usr/local/tomcat/webapps/ROOT/runtime/conf/MoquiProductionConf.xml
15:42:39.575  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component tools              at file:/usr/local/tomcat/webapps/ROOT/runtime/base-component/tools
15:42:39.575  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component webroot            at file:/usr/local/tomcat/webapps/ROOT/runtime/base-component/webroot
15:42:39.585  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component mantle-udm         at file:/usr/local/tomcat/webapps/ROOT/runtime/component/mantle-udm
15:42:39.598  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component mantle-usl         at file:/usr/local/tomcat/webapps/ROOT/runtime/component/mantle-usl
15:42:39.598  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component moqui-zh_CN-addon  at file:/usr/local/tomcat/webapps/ROOT/runtime/component/moqui-zh_CN-addon
15:42:39.600  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added component zc-3plservices     at file:/usr/local/tomcat/webapps/ROOT/runtime/component/zc-3plservices
15:42:39.600  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Components after depends-on sort: [tools, webroot, mantle-udm, mantle-usl, moqui-zh_CN-addon, zc-3plservices]
15:42:39.621  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Merging MoquiConf.xml file from component zc-3plservices
15:42:39.648  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Merging runtime configuration at /usr/local/tomcat/webapps/ROOT/runtime/conf/MoquiProductionConf.xml
15:42:40.102  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Initializing worker ThreadPoolExecutor: queue limit 65535, pool-core 4, pool-max 16, pool-alive 60s
15:42:40.151  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Added JARs from component zc-3plservices: [zc-3plservices-0.0.1.jar]
15:42:40.192  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Not loading disabled ToolFactory with class: org.moqui.impl.tools.JackrabbitRunToolFactory
15:42:40.204  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Loading ToolFactory with class: org.moqui.jcache.MCacheToolFactory
15:42:40.217  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Loading ToolFactory with class: org.moqui.impl.tools.H2ServerToolFactory
15:42:40.253  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Cache Facade initialized
15:42:40.675  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Resource Facade initialized
15:42:40.698  WARN         main                      b.t.Configuration Cannot get the unique server ID for this JVM ('bitronix.tm.serverId'). Make sure it is configured and you use only US-ASCII characters. Will use IP address instead (unsafe for production usage!).
15:42:40.889  INFO         main .moqui.i.c.ExecutionContextFactoryImpl Transaction Facade initialized
Error loading or running Moqui.loadData with args [{load=}]: java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at MoquiStart.main(MoquiStart.java:114)
Caused by: java.util.ServiceConfigurationError: org.moqui.context.ExecutionContextFactory: Provider org.moqui.impl.context.ExecutionContextFactoryImpl could not be instantiated
    at java.util.ServiceLoader.fail(ServiceLoader.java:232)
    at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.moqui.Moqui.loadData(Moqui.java:79)
    ... 5 more
Caused by: bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named DEFAULT_transactional_DS
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:90)
    at org.moqui.impl.context.TransactionInternalBitronix.getDataSource(TransactionInternalBitronix.groovy:130)
    at org.moqui.impl.entity.EntityDatasourceFactoryImpl.init(EntityDatasourceFactoryImpl.groovy:82)
    at org.moqui.impl.entity.EntityFacadeImpl.initAllDatasources(EntityFacadeImpl.groovy:191)
    at org.moqui.impl.entity.EntityFacadeImpl.<init>(EntityFacadeImpl.groovy:120)
    at org.moqui.impl.context.ExecutionContextFactoryImpl.initEntityFacade(ExecutionContextFactoryImpl.groovy:687)
    at org.moqui.impl.context.ExecutionContextFactoryImpl.<init>(ExecutionContextFactoryImpl.groovy:196)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: Class [com.mysql.jdbc.jdbc2.optional.MysqlXADataSource] not found
    at MoquiStart$StartClassLoader.loadClass(MoquiStart.java:496)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at bitronix.tm.utils.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:80)
    at bitronix.tm.resource.common.XAFactoryHelper.createXAFactory(XAFactoryHelper.java:42)
    at bitronix.tm.resource.common.XAPool.<init>(XAPool.java:94)
    at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:99)
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:86)
    ... 20 more
========== Shutting down Moqui Executable (closing jars, etc) ==========
14-Jul-2016 15:42:44.446 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.36
14-Jul-2016 15:42:44.447 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 9 2016 13:55:50 UTC
14-Jul-2016 15:42:44.448 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.36.0
14-Jul-2016 15:42:44.448 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
14-Jul-2016 15:42:44.448 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-327.22.2.el7.x86_64
14-Jul-2016 15:42:44.448 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
14-Jul-2016 15:42:44.448 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
14-Jul-2016 15:42:44.452 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_91-8u91-b14-1~bpo8+1-b14
14-Jul-2016 15:42:44.452 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
14-Jul-2016 15:42:44.452 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/usr/local/tomcat/endorsed
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
14-Jul-2016 15:42:44.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
14-Jul-2016 15:42:44.454 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent An older version 1.1.32 of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of 1.1.33
14-Jul-2016 15:42:44.454 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.1.32 using APR version 1.5.1.
14-Jul-2016 15:42:44.454 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
14-Jul-2016 15:42:44.548 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.1k 8 Jan 2015)
14-Jul-2016 15:42:44.734 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
14-Jul-2016 15:42:44.761 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
14-Jul-2016 15:42:44.769 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1219 ms
14-Jul-2016 15:42:44.811 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
14-Jul-2016 15:42:44.811 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.36
14-Jul-2016 15:42:44.893 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/ROOT.war
14-Jul-2016 15:42:48.139 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
15:42:49.948  INFO -startStop-1       o.moqui.i.w.MoquiContextListener Loading Webapp 'webroot' (Moqui Root Webapp) on ROOT, located at: /usr/local/tomcat/webapps/ROOT/
15:42:50.314  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Initializing Moqui ExecutionContextFactoryImpl
 - runtime directory: /usr/local/tomcat/webapps/ROOT/runtime
 - runtime config:    /usr/local/tomcat/webapps/ROOT/runtime/conf/MoquiDevConf.xml
15:42:50.376  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component tools              at file:/usr/local/tomcat/webapps/ROOT/runtime/base-component/tools
15:42:50.376  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component webroot            at file:/usr/local/tomcat/webapps/ROOT/runtime/base-component/webroot
15:42:50.378  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component mantle-udm         at file:/usr/local/tomcat/webapps/ROOT/runtime/component/mantle-udm
15:42:50.383  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component mantle-usl         at file:/usr/local/tomcat/webapps/ROOT/runtime/component/mantle-usl
15:42:50.383  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component moqui-zh_CN-addon  at file:/usr/local/tomcat/webapps/ROOT/runtime/component/moqui-zh_CN-addon
15:42:50.384  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added component zc-3plservices     at file:/usr/local/tomcat/webapps/ROOT/runtime/component/zc-3plservices
15:42:50.385  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Components after depends-on sort: [tools, webroot, mantle-udm, mantle-usl, moqui-zh_CN-addon, zc-3plservices]
15:42:50.405  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Merging MoquiConf.xml file from component zc-3plservices
15:42:50.430  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Merging runtime configuration at /usr/local/tomcat/webapps/ROOT/runtime/conf/MoquiDevConf.xml
15:42:50.955  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Initializing worker ThreadPoolExecutor: queue limit 65535, pool-core 4, pool-max 16, pool-alive 60s
15:42:50.994  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Added JARs from component zc-3plservices: [zc-3plservices-0.0.1.jar]
15:42:51.008  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Not loading disabled ToolFactory with class: org.moqui.impl.tools.JackrabbitRunToolFactory
15:42:51.013  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Loading ToolFactory with class: org.moqui.jcache.MCacheToolFactory
15:42:51.021  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Loading ToolFactory with class: org.moqui.impl.tools.H2ServerToolFactory
15:42:51.036  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Cache Facade initialized
15:42:51.443  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Resource Facade initialized
15:42:51.535  WARN -startStop-1                      b.t.Configuration Cannot get the unique server ID for this JVM ('bitronix.tm.serverId'). Make sure it is configured and you use only US-ASCII characters. Will use IP address instead (unsafe for production usage!).
15:42:51.853  WARN -startStop-1                      b.t.j.DiskJournal active log file is unclean, did you call BitronixTransactionManager.shutdown() at the end of the last run?
15:42:51.884  INFO -startStop-1 .moqui.i.c.ExecutionContextFactoryImpl Transaction Facade initialized
15:42:52.929  INFO -startStop-1           o.moqui.i.e.EntityFacadeImpl Loaded 12 Entity ECA rules from 3 .eecas.xml files
15:42:52.944  INFO -startStop-1                    o.m.i.e.EntityCache Entity Cache initialized, distributed cache invalidate enabled: false

1 个答案:

答案 0 :(得分:0)

我正在运行Moqui,部署在Apache Tomcat服务器上,连接到PostgreSQL。应用程序和数据库服务器都位于不同的容器中情况略有不同,但类似于发表一些笔记。

数据库驱动程序

我在错误堆栈跟踪中注意到的第一件事是,(可能)连接到数据库时出现问题。

  

未找到类[com.mysql.jdbc.jdbc2.optional.MysqlXADataSource]

检查驱动程序是否连接到数据库。正如我写的,我正在使用PostgreSQL,我安装的第一件事是PostgreSQL JDBC驱动程序。然后我将驱动程序的JAR文件复制到moqui / runtime / lib目录中,以便应用程序可以在运行时使用它,在我的例子中如下:

2016-07-14 14:51:12,335 INFO org.mortbay.log: Stopped HttpServer2$SelectChannelConnectorWithSafeStartup@UT190320.shis.uth.tmc.edu:50070
2016-07-14 14:51:12,436 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: Stopping NameNode metrics system...
2016-07-14 14:51:12,436 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system stopped.
2016-07-14 14:51:12,436 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system shutdown complete.
2016-07-14 14:51:12,436 FATAL org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode.
java.io.IOException: 
File system image contains an old layout version -55.
An upgrade to version -59 is required.
Please restart NameNode with the "-rollingUpgrade started" option if a rolling upgrade is already started; or restart NameNode with the "-upgrade" option to start a new upgrade.
    at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:232)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:1006)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:736)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:553)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:609)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:776)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:760)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1466)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1534)
2016-07-14 14:51:12,439 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1

关联容器

对我有用的是使用Docker的Link功能。数据库服务器的容器名称只是 pg 。这是在输出的最后一列中运行后一个命令后看到的名称:

cp /var/tmp/postgresql-9.2-1002.jdbc4.jar /opt/vi/moqui/runtime/lib

运行应用程序服务器的容器时,使用link参数在这两个容器之间建立链接,在我的情况下:

docker ps -a

--link参数表示 pg 容器(可从docker主机获得)在新创建的容器中以相同的名称(pg)可用。

在MoquiConf文件中,将IP地址(192.168.1.237)替换为 pg (您可以用不同的名称命名,当然,我只是关注我的情况)。您可以检查是否可以通过简单的ping命令从应用程序服务器(新创建的)容器内部连接到(容器)数据库服务器(使用您的逻辑名称)。

docker run -it --name srv05 --link pg:pg -p 443:8443 -p 80:8080 tomcat:8.5

有关链接容器的更多信息,请查看以下内容:https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

希望它有所帮助。