WebLogic是美國Oracle公司出品的一個application server確切的說是一個基於JAVAEE架構的中間件。BEA WebLogic是用於開發、集成、部署和管理大型分佈式Web應用、網絡應用和數據庫應用的Java應用服務器。是商業市場上基本的Java(J2EE)應用服務器軟件(application server)之中的一個,是世界上第一個成功商業化的J2EE應用服務器。眼下weblogic在世界application server市場上佔有最大的份額。其它還有象IBM的websphere,免費的tomcat、resin等中間件。java
與 tomcat 不一樣。Weblogic 是一個商業軟件。需要有受權才幹使用,只是 Oracle 公司受權開發人員可以在開發模式下使用 Weblogic ,如需要在生產環境中使用 Weblogic 需要 Oracle 公司的正規受權才幹夠。Weblogic 的安裝介質下載也需要到 Oracle 的官方站點下載,因此不大可能在 Dockerhub 上找到合適法律受權的鏡像。node
Weblogic 域web
是做爲單元進行管理的一組相關的 WebLogic Server 資源。docker
一個域包括一個或多個 WebLogic Server 實例,這些實例可以是羣集實例、非羣集實例,或者是羣集與非羣集實例的組合。一個域可以包括多個羣集。shell
域還包括部署在域中的應用程序組件、此域中的這些應用程序組件和服務器實例所需的資源和服務。應用程序和服務器實例使用的資源和服務演示樣例包括計算機定義、可選網絡通道、鏈接器和啓動類。數據庫
Administration Serverubuntu
Domain 中包括一個特殊的 WebLogic 服務器實例。叫作 Administration Server,這是咱們配置、管理Domain中所有資源的核心。瀏覽器
Managed Servertomcat
一般。咱們稱加入Domain中的其它實例爲 Managed Server,所有的Web應用、EJB、Web Services和其它資源都部署在這些服務器上。bash
一個典型的 Weblogic 部署應該是這種:
假設要使用常規的administrator +node的方式部署,就需要在 run.sh 腳本中分別寫出administartor server和node server的啓動腳本.
這樣作的長處是:
缺點是:
筆者推薦將應用程序安裝在 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 端口
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"]
#!/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 鏡像。
使用本章推薦的方式部署 weblogic 和 tomcat 的典型拓撲例如如下圖所看到的(圖中,weblogic 和 tomcat 容器可以相互替換):
不少其它內容。歡迎關注 www.dockerpool.com