史上最靠谱的Websphere Liberty 配置,完全可用的支持DB2应用

来源:互联网 发布:稳定性最好的单片机 编辑:程序博客网 时间:2024/06/03 19:53

为什么写这个,主要是最新的一个项目,用到了was liberty,但是整个网路上,相关配置信息较少,而且可实践得不多,查官方文档又太慢了,最后得力于N年前的项目实战,辛苦的找到了这个配置文件,记录下来,以便未来使用,WAS liberty的好处,主要可以归结为3点

1,配置简单;2, 更改配置不需要重新启动服务,tomcat是需要的。3, 多应用部署效率高,稳定性比Tomcat要好不少。

使用Docker,在docker资源库中,你能轻易的发现WAS Liberty 提供的仅用于开发环境的镜像,下载下来启动一个容器,命令如下:

$docker run -d -p 9080:9080 -p 9443:9443 <image id> /bin/bash

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
440817ee2598        websphere-liberty   "/opt/ibm/docker/d..."   25 hours ago        Up 21 hours         0.0.0.0:9080->9080/tcp, 0.0.0.0:9443->9443/tcp   nostalgic_feynman

启动后的容器后,你需要做几件事情来完成部署:

1. 要做的是将你的应用war包上传到容器中的/opt/ibm/wlp/usr/servers/defaultServer/apps中

2. 拷贝DBMS Driver jars(db2jcc_license_cu.jar, db2jcc4.jar) 到 /opt/ibm/wlp/usr/shared/resources 目录中

3. 在440817ee2598:/opt/ibm/wlp/usr/servers/defaultServer 下有个server.xml文件,你需要的是通过docker cp 命令将其下载到本地进行编辑,编辑如下:

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

    <!-- Enable features -->
    <featureManager>
         <feature>javaee-7.0</feature>
         <feature>jndi-1.0</feature>
    </featureManager>

    <!-- This template enables security. To get the full use of all the capabilities, a keystore and user registry are required. -->
    
    <!-- For the keystore, default keys are generated and stored in a keystore. To provide the keystore password, generate an
         encoded password using bin/securityUtility encode and add it below in the password attribute of the keyStore element.
         Then uncomment the keyStore element. -->
    <!--
    <keyStore password=""/>
    -->
    
    <!--For a user registry configuration, configure your user registry. For example, configure a basic user registry using the
        basicRegistry element. Specify your own user name below in the name attribute of the user element. For the password,
        generate an encoded password using bin/securityUtility encode and add it in the password attribute of the user element.
        Then uncomment the user element. -->
    <basicRegistry id="basic" realm="BasicRealm">
        <!-- <user name="yourUserName" password="" />  -->
    </basicRegistry>
    
    <!-- To allow access to this server from a remote client host="*" has been added to the following element -->
    <httpEndpoint id="defaultHttpEndpoint"
                  host="*"
                  httpPort="9080"
                  httpsPort="9443" />
                  
    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>
    
    <applicationMonitor dropins="dropins"  updateTrigger="mbean"/>
    <application context-root="/iba" location="iba-web.war" id="iba" name="iba" type="war">
        <classloader commonLibraryRef="DB2DriverLib"/>
    </application>
    
    <application context-root="/ibaid" location="iba-prelogin.war" id="ibaid" name="ibaid" type="war"/>
    
    
    <library id="DB2DriverLib">
    <fileset dir="${shared.resource.dir}" includes="db2jcc_license_cu.jar, db2jcc.jar"/>
    </library>

    <dataSource id="jdbc/iba_dev" jndiName="jdbc/iba_dev" type="javax.sql.DataSource" transactional="true">
      <jdbcDriver libraryRef="DB2DriverLib"/>
         <connectionManager maxPoolSize="50" minPoolSize="5" connectionTimeout="10s"/>
         <properties databaseName="IBADB"
                  driverType="4"
                  serverName="127.0.0.1"
                  portNumber="50000"
                  user="wbaadmin"
                  password="wbaadmin"/>
   </dataSource>
</server>

编辑完成后,保存,并用docker cp 命令上传到容器中,这时候,你可能需要重启Liberty 服务:

切换到/opt/ibm/docker/目录下,你能够看到docker-server的一个服务

./docker-server stop 后,你需要重新启动这个容器,通过使用docker start <容器 id>后,WAS Liberty 其实也自动启动了。可以通过ps -ef 命令来看进程。

这样就完成了部署应用。最后访问 http://localhost:9080/iba 或者https://localhost:9443/iba来尝试。




原创粉丝点击