Weblogic
Weblogic 简单介绍以及其在 Docker 环境下的特殊应用
WebLogic是美国Oracle公司出品的一个application server确切的说是一个基于JAVAEE架构的中间件。BEA WebLogic是用于开发、集成、部署和管理大型分布式Web应用、网络应用和数据库应用的Java应用服务器。是商业市场上基本的Java(J2EE)应用服务器软件(application server)之中的一个,是世界上第一个成功商业化的J2EE应用服务器。眼下weblogic在世界application server市场上占有最大的份额。其它还有象IBM的websphere,免费的tomcat、resin等中间件。
与 tomcat 不同。Weblogic 是一个商业软件。须要有授权才干使用,只是 Oracle 公司授权开发人员能够在开发模式下使用 Weblogic ,如须要在生产环境中使用 Weblogic 须要 Oracle 公司的正规授权才干够。Weblogic 的安装介质下载也须要到 Oracle 的官方站点下载,所以不大可能在 Dockerhub 上找到合适法律授权的镜像。
Weblogic 域
是作为单元进行管理的一组相关的 WebLogic Server 资源。
一个域包括一个或多个 WebLogic Server 实例,这些实例能够是群集实例、非群集实例,或者是群集与非群集实例的组合。一个域能够包括多个群集。
域还包括部署在域中的应用程序组件、此域中的这些应用程序组件和服务器实例所需的资源和服务。应用程序和服务器实例使用的资源和服务演示样例包括计算机定义、可选网络通道、连接器和启动类。
Administration Server
Domain 中包括一个特殊的 WebLogic 服务器实例。叫做 Administration Server,这是我们配置、管理Domain中全部资源的核心。
Managed Server
通常。我们称加入Domain中的其它实例为 Managed Server,全部的Web应用、EJB、Web Services和其它资源都部署在这些服务器上。
一个典型的 Weblogic 部署应该是这种:
假设要使用常规的administrator +node的方式部署,就须要在 run.sh 脚本中分别写出administartor server和node server的启动脚本.
这样做的长处是:
- 能够使用 weblogic 的集群,同步等概念 部署一个集群应用程序,仅仅须要安装一次应用到集群上就可以
缺点是:
- docker 配置复杂了
- 没办法自己主动扩展集群的计算容量,如需加入节点,须要在 administrator 上先创建节点。然后再配置新的容器 run.sh 启动脚本,然后再启动容器
笔者推荐将应用程序安装在 adminiserver 上面,须要扩展的时候。启动多个 adminiserver 节点就可以,将 adminiserver 当作 Manged server 使用。它的长处和缺点和传统的部署方法恰恰相反。
使用 docker commit
方式来创建操作复杂的镜像
以下以 Weblogic 12.11\jdk 1.6\ubuntu14.04 为样例创建一个带 weblogic 服务的镜像。
由于 Weblogic 的安装、部署方式较为复杂,我们将先通过 docker run -ti
进入容器完毕我们大部分操作,然后 docker commit
这个容器为一个镜像,最后再使用 Dockerfile 来完毕我们的 Weblogic 镜像创建。
以下是 shell 部分的操作:
#创建并进入 weblogic 文件夹
$ mkdir weblogic_jdk1.6
$ cd weblogic_jdk1.6/
#从其它主机上传 jdk 和 weblogic 安装文件到该文件夹下,并创建 Dockerfile 和 run.sh 脚本
$ touch Dockerfile run.sh
$ ls
Dockerfile jdk run.sh wls1211_generic.jar
#使用 -v -d -P 參数执行我们的 sshd_dockerfile 镜像,若对这些參数的含义及使用方法还不熟悉的读者能够參考前面的參数介绍章节
$ sudo docker run -v ./wls1211_generic.jar:/wls1211_generic.jar -v ./jdk:/jdk -d -P sshd:dockerfile
#Docker 返回错误,告诉我们 -v 挂载的卷必须是绝对路径
2014/10/28 00:47:03 Error response from daemon: Cannot start container 8e2e95a1f2dc04290dd32aaa2aa231ac52f810876b2039011aec9d0b0c2a3bef: cannot bind mount volume: ./wls1211_generic.jar volume paths must be absolute.
#此处的 `XXX` 是笔者操作系统的用户名。读者可依据自己机器的详细情况来输入命令
$ sudo docker run -d -v /home/dwj/weblogic_jdk1.6/wls1211_generic.jar:/wls1211_generic.jar -v /home/dwj/weblogic_jdk1.6/jdk:/jdk -P sshd:dockerfile
185546d00925d80c5bfa01320feb8939c838fa10429acc648f8850efb8a1e968
#查看容器的 ssh 端口映射情况
dwj@ubuntu:~/weblogic_jdk1.6$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
185546d00925 sshd:dockerfile "/run.sh" 2 seconds ago Up 1 seconds 0.0.0.0:49159->22/tcp happy_ritchie
> ssh 192.168.1.134 -p 49159
The authenticity of host '[192.168.1.134]:49159 ([192.168.1.134]:49159)' can't be established.
ECDSA key fingerprint is d1:59:f1:09:3b:09:79:6d:19:16:f4:fd:39:1b:be:27.
Are you sure you want to continue connecting (yes/no)?
yes Warning: Permanently added '
[192.168.1.134]:49159' (ECDSA) to the list of known hosts. Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.2.0-37-generic x86_64) * Documentation: https://help.ubuntu.com/ The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. # root@185546d00925:~#cd / root@185546d00925:/# ls -lh total 997M drwxr-xr-x 2 root root 4.0K Jul 17 03:38 bin drwxr-xr-x 2 root root 4.0K Apr 10 2014 boot drwxr-xr-x 4 root root 340 Oct 28 07:53 dev drwxr-xr-x 83 root root 4.0K Oct 28 07:53 etc drwxr-xr-x 2 root root 4.0K Apr 10 2014 home drwxr-xr-x 8 1000 1000 4.0K Oct 28 07:43 jdk drwxr-xr-x 14 root root 4.0K Oct 27 03:01 lib drwxr-xr-x 2 root root 4.0K Jul 17 03:34 lib64 drwxr-xr-x 2 root root 4.0K Jul 17 03:34 media drwxr-xr-x 2 root root 4.0K Apr 10 2014 mnt drwxr-xr-x 2 root root 4.0K Jul 17 03:34 opt dr-xr-xr-x 253 root root 0 Oct 28 07:53 proc drwx------ 5 root root 4.0K Oct 28 07:55 root drwxr-xr-x 8 root root 4.0K Oct 28 07:55 run -rwxr-xr-x 1 root root 30 Oct 27 02:51 run.sh drwxr-xr-x 2 root root 4.0K Jul 21 21:47 sbin drwxr-xr-x 2 root root 4.0K Jul 17 03:34 srv dr-xr-xr-x 13 root root 0 Oct 28 07:53 sys drwxrwxrwt 3 root root 4.0K Oct 28 07:56 tmp drwxr-xr-x 16 root root 4.0K Oct 27 03:01 usr drwxr-xr-x 19 root root 4.0K Oct 28 07:55 var -rw------- 1 1000 1000 997M Oct 28 07:39 wls1211_generic.jar root@185546d00925:/# ./jdk/bin/java -jar wls1211_generic.jar -mode=console Extracting 0%....................................................................................................100% <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Welcome: -------- This installer will guide you through the installation of WebLogic 12.1.1.0. Type "Next" or enter to proceed to the next prompt. If you want to change data entered previously, type "Previous". You may quit the installer at any time by typing "Exit". Enter [Exit][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Choose Middleware Home Directory: --------------------------------- "Middleware Home" = [Enter new value or use default "/root/Oracle/Middleware"] Enter new Middleware Home OR [Exit][Previous][Next]> /opt/Middleware <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Choose Middleware Home Directory: --------------------------------- "Middleware Home" = [/opt/Middleware] Use above value or select another option: 1 - Enter new Middleware Home 2 - Change to default [/root/Oracle/Middleware] Enter option number to select OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Register for Security Updates: ------------------------------ Provide your email address for security updates and to initiate configuration manager. 1|Email:[] 2|Support Password:[] 3|Receive Security Update:[Yes] Enter index number to select OR [Exit][Previous][Next]> 3 <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Register for Security Updates: ------------------------------ Provide your email address for security updates and to initiate configuration manager. "Receive Security Update:" = [Enter new value or use default "yes"] Enter [Yes][No]? no <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Register for Security Updates: ------------------------------ Provide your email address for security updates and to initiate configuration manager. "Receive Security Update:" = [Enter new value or use default "yes"] ** Do you wish to bypass initiation of the configuration manager and ** remain uninformed of critical security issues in your configuration? Enter [Yes][No]?
yes <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Register for Security Updates: ------------------------------ Provide your email address for security updates and to initiate configuration manager. 1|Email:[] 2|Support Password:[] 3|Receive Security Update:[No] Enter index number to select OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Register for Security Updates: ------------------------------ Provide your email address for security updates and to initiate configuration manager. 1|Email:[] 2|Support Password:[] 3|Receive Security Update:[No] Enter index number to select OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Choose Install Type: -------------------- Select the type of installation you wish to perform. ->1|Typical | Install the following product(s) and component(s): | - WebLogic Server | - Oracle Coherence 2|Custom | Choose software products and components to install and perform optional |configuration. Enter index number to select OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> JDK Selection (Any * indicates Oracle Supplied VM): --------------------------------------------------- JDK(s) chosen will be installed. Defaults will be used in script string-substitution if installed. 1|Add Local Jdk 2|/jdk[x] *Estimated size of installation: 589.7 MB Enter 1 to add or >= 2 to toggle selection OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Choose Product Installation Directories: ---------------------------------------- Middleware Home Directory: [/opt/Middleware] Product Installation Directories: 1|WebLogic Server: [/opt/Middleware/wlserver_12.1] 2|Oracle Coherence: [/opt/Middleware/coherence_3.7] Enter index number to select OR [Exit][Previous][Next]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> The following Products and JDKs will be installed: -------------------------------------------------- WebLogic Platform 12.1.1.0 |_____WebLogic Server | |_____Core Application Server | |_____Administration Console | |_____Configuration Wizard and Upgrade Framework | |_____Web 2.0 HTTP Pub-Sub Server | |_____WebLogic SCA | |_____WebLogic JDBC Drivers | |_____Third Party JDBC Drivers | |_____WebLogic Server Clients | |_____Xquery Support | |_____Evaluation Database |_____Oracle Coherence |_____Coherence Product Files *Estimated size of installation: 589.9 MB Enter [Exit][Previous][Next]> Oct 28, 2014 7:59:44 AM java.util.prefs.FileSystemPreferences$2 run INFO: Created user preferences directory. <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Installing files.. 0% 25% 50% 75% 100% [------------|------------|------------|------------] [***************************************************] Performing String Substitutions... <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Configuring OCM... 0% 25% 50% 75% 100% [------------|------------|------------|------------] [***************************************************] <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Installing Patches... 0% 25% 50% 75% 100% [------------|------------|------------|------------] [***************************************************] Creating Domains... <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Installation Complete Congratulations! Installation is complete. Press [Enter] to continue or type [Exit]> <-------------------- Oracle Installer - WebLogic 12.1.1.0 -------------------> Clean up process in progress ... root@185546d00925:/# cd /opt/Middleware/wlserver_12.1/common/bin/ root@185546d00925:/opt/Middleware/wlserver_12.1/common/bin# ./config.sh -mode=console <------------------- Fusion Middleware Configuration Wizard ------------------> Welcome: -------- Choose between creating and extending a domain. Based on your selection, the Configuration Wizard guides you through the steps to generate a new or extend an existing domain. ->1|Create a new WebLogic domain | Create a WebLogic domain in your projects directory. 2|Extend an existing WebLogic domain | Use this option to add new components to an existing domain and modify |configuration settings. Enter index number to select OR [Exit][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Select Domain Source: --------------------- Select the source from which the domain will be created. You can create the domain by selecting from the required components or by selecting from a list of existing domain templates. ->1|Choose Weblogic Platform components | You can choose the Weblogic component(s) that you want supported in |your domain. 2|Choose custom template | Choose this option if you want to use an existing template. This |could be a custom created template using the Template Builder. Enter index number to select OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Application Template Selection: ------------------------------- Available Templates |_____Basic WebLogic Server Domain - 12.1.1.0 [wlserver_12.1]x |_____Basic WebLogic SIP Server Domain - 12.1.1.0 [wlserver_12.1] [2] |_____WebLogic Advanced Web Services for JAX-RPC Extension - 12.1.1.0 [wlserver_12.1] [3] |_____WebLogic Advanced Web Services for JAX-WS Extension - 12.1.1.0 [wlserver_12.1] [4] Enter number exactly as it appears in brackets to toggle selection OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Edit Domain Information: ------------------------ | Name | Value | _|________|_____________| 1| *Name: | base_domain | Enter value for "Name" OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Select the target domain directory for this domain: --------------------------------------------------- "Target Location" = [Enter new value or use default "/opt/Middleware/user_projects/domains"] Enter new Target Location OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Configure Administrator User Name and Password: ----------------------------------------------- Create a user to be assigned to the Administrator role. This user is the default administrator used to start development mode servers. | Name | Value | _|_________________________|_________________________________________| 1| *Name: | weblogic | 2| *User password: | | 3| *Confirm user password: | | 4| Description: | This user is the default administrator. | Use above value or select another option: 1 - Modify "Name" 2 - Modify "User password" 3 - Modify "Confirm user password" 4 - Modify "Description" Enter option number to select OR [Exit][Previous][Next]> 3 <------------------- Fusion Middleware Configuration Wizard ------------------> Configure Administrator User Name and Password: ----------------------------------------------- Create a user to be assigned to the Administrator role. This user is the default administrator used to start development mode servers. "*Confirm user password:" = [] Enter new *Confirm user password: OR [Exit][Reset][Accept]> weblogic_test <------------------- Fusion Middleware Configuration Wizard ------------------> Configure Administrator User Name and Password: ----------------------------------------------- Create a user to be assigned to the Administrator role. This user is the default administrator used to start development mode servers. | Name | Value | _|_________________________|_________________________________________| 1| *Name: | weblogic | 2| *User password: | | 3| *Confirm user password: | ************* | 4| Description: | This user is the default administrator. | Use above value or select another option: 1 - Modify "Name" 2 - Modify "User password" 3 - Modify "Confirm user password" 4 - Modify "Description" 5 - Discard Changes Enter option number to select OR [Exit][Previous][Next]> 2 <------------------- Fusion Middleware Configuration Wizard ------------------> Configure Administrator User Name and Password: ----------------------------------------------- Create a user to be assigned to the Administrator role. This user is the default administrator used to start development mode servers. "*User password:" = [] Enter new *User password: OR [Exit][Reset][Accept]> weblogic_test <------------------- Fusion Middleware Configuration Wizard ------------------> Configure Administrator User Name and Password: ----------------------------------------------- Create a user to be assigned to the Administrator role. This user is the default administrator used to start development mode servers. | Name | Value | _|_________________________|_________________________________________| 1| *Name: | weblogic | 2| *User password: | ************* | 3| *Confirm user password: | ************* | 4| Description: | This user is the default administrator. | Use above value or select another option: 1 - Modify "Name" 2 - Modify "User password" 3 - Modify "Confirm user password" 4 - Modify "Description" 5 - Discard Changes Enter option number to select OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Domain Mode Configuration: -------------------------- Enable Development or Production Mode for this domain. ->1|Development Mode 2|Production Mode Enter index number to select OR [Exit][Previous][Next]> 2 <------------------- Fusion Middleware Configuration Wizard ------------------> Java SDK Selection: ------------------- ->1|Sun SDK 1.6.0_43 @ /jdk 2|Other Java SDK Enter index number to select OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Select Optional Configuration: ------------------------------ 1|Administration Server [ ] 2|Managed Servers, Clusters and Machines [ ] 3|RDBMS Security Store [ ] Enter index number to select OR [Exit][Previous][Next]> 1 <------------------- Fusion Middleware Configuration Wizard ------------------> Select Optional Configuration: ------------------------------ 1|Administration Server [x] 2|Managed Servers, Clusters and Machines [ ] 3|RDBMS Security Store [ ] Enter index number to select OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Configure the Administration Server: ------------------------------------ Each WebLogic Server domain must have one Administration Server. The Administration Server is used to perform administrative tasks. | Name | Value | _|__________________|_____________________| 1| *Name: | AdminServer | 2| *Listen address: | All Local Addresses | 3| Listen port: | 7001 | 4| SSL listen port: | N/A | 5| SSL enabled: | false | Use above value or select another option: 1 - Modify "Name" 2 - Modify "Listen address" 3 - Modify "Listen port" 4 - Modify "SSL enabled" Enter option number to select OR [Exit][Previous][Next]> <------------------- Fusion Middleware Configuration Wizard ------------------> Creating Domain... 0% 25% 50% 75% 100% [------------|------------|------------|------------] [***************************************************] **** Domain Created Successfully! **** #改动 weblogic 的一些环境变量 root@185546d00925:/opt/Middleware/user_projects/domains/base_domain# vi bin/setDomainEnv.sh #使用username与password启动一次 webogic 之后。会在/opt/Middleware/user_projects/domains/base_domain 生成一个 server 的文件夹 #进入这个 AdminServer 创建security/boot.properties 文件,内容例如以下: username=weblogic password=password #这样 再次启动 weblogic 时。就不须要思路密码了。
root@185546d00925:/opt/Middleware/user_projects/domains/base_domain# ./startWebLogic.sh . . JAVA Memory arguments: -Xms256m -Xmx512m -XX:MaxPermSize=256m . WLS Start Mode=Production #省去启动过程 .... <Oct 28, 2014 8:13:52 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 172.17.0.13:7001 for protocols iiop, t3, ldap, snmp, http.> <Oct 28, 2014 8:13:52 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.> <Oct 28, 2014 8:13:52 AM UTC> <Warning> <Server> <BEA-002611> <The hostname "localhost", maps to multiple IP addresses: 127.0.0.1, 0:0:0:0:0:0:0:1.> <Oct 28, 2014 8:13:52 AM UTC> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 0:0:0:0:0:0:0:1:7001 for protocols iiop, t3, ldap, snmp, http.> <Oct 28, 2014 8:13:52 AM UTC> <Notice> <WebLogicServer> <BEA-000329> <Started the WebLogic Server Administration Server "AdminServer" for domain "base_domain" running in production mode.> <Oct 28, 2014 8:13:52 AM UTC> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.> <Oct 28, 2014 8:13:52 AM UTC> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.> #能够看到weblogic 启动成功,并监听本地的 7001 端口
Dockerfile
FROM weblogic_1
#设置继承自我们创建的 weblogic_1 镜像
MAINTAINER waitfish from dockerpool.com(dwj_zz@163.com)
#以下是一些创建者的基本信息
#环境变量设置。全部操作都是非交互式的
ENV DEBIAN_FRONTEND noninteractive
RUN echo "Asia/Shanghai" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata
#注意这里要更改系统的时区设置,由于在 web 应用中常常会用到时区这个系统变量,默认的 ubuntu 会让你的应用程序发生不可思议的效果哦
COPY jdk /jdk
COPY run.sh /run.sh
RUN chmod +x /run.sh
EXPOSE 7001
CMD ["/run.sh"]
run.sh
#!/bin/bash
/user/sbin/sshd -D &
/opt/Middleware/user_projects/domains/base_domain/startWebLogic.sh
创建镜像及測试
$ sudo docker build -t weblogic:jdk1.6 .
Sending build context to Docker daemon 1.256 GB
Sending build context to Docker daemon
Step 0 : FROM weblogic_1
---> 6b73c466305f
Step 1 : MAINTAINER waitfish from dockerpool.com(dwj_zz@163.com)
---> Using cache
---> c93c4f458baa
Step 2 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> 18fef76dc41b
Step 3 : RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
---> Using cache
---> d307ba8bd052
Step 4 : COPY jdk /jdk
---> Using cache
---> a54ffaa93184
Step 5 : COPY run.sh /run.sh
---> a21b0ccb0b07
Removing intermediate container eabf04e467dd
Step 6 : RUN chmod +x /run.sh
---> Running in 4231d8062f5b
---> f46358aac2e3
Removing intermediate container 4231d8062f5b
Step 7 : EXPOSE 7001
---> Running in d17c80a9ea5b
---> 8bc8dd5c8caa
Removing intermediate container d17c80a9ea5b
Step 8 : CMD /run.sh
---> Running in 45de5ac8883a
---> d904fe4f91f9
Removing intermediate container 45de5ac8883a
Successfully built d904fe4f91f9
$ sudo docker run -d -P weblogic:jdk1.6
6c08f5b110affaec256e48b925a1914991c931a8c581f4817fbc5d538e7af2e6
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c08f5b110af weblogic:jdk1.6 "/run.sh" 15 seconds ago Up 14 seconds 0.0.0.0:49163->22/tcp, 0.0.0.0:49164->7001/tcp
使用浏览器登陆 weblogic 控制台
架构师在控制台设置完启动程序、数据源等參数之后,能够重使用以上步骤创建合适项目执行的 weblogic 镜像。
tomcat/weblogic 集群部署
使用本章推荐的方式部署 weblogic 和 tomcat 的典型拓扑例如以下图所看到的(图中,weblogic 和 tomcat 容器能够相互替换):
很多其它内容。欢迎关注 www.dockerpool.com