weblogic 腳本建立Managed Server (受管服務器)

說明

weblogic安裝目錄下有一個建立Managed Server的腳本,腳本位於/u01/app/Oracle/Middleware/oracle_common/common/bin/config.sh下,但腳本會啓動一個GUI界面程序,在Linux下須要安裝圖形界面程序,很是不方便。wlst(WebLogic Scripting Tools,WebLogic)是一個用來管理和配置weblogic的CLI命令行工具,能夠運行Jython腳本,本文介紹如何經過該工具建立Managed Server。html

WLST介紹

wlst位於/u01/app/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh目錄下,其中/u01/app/Oracle/Middleware/wlserver_10.3目錄爲$WEBLOGIC_HOME,因此嚴謹的講,是安裝在$WEBLOGIC_HOME/common/bin/wlst.sh下。直接執行該腳本便可運行wlst工具。java

$ cd /u01/app/Oracle/Middleware/wlserver_10.3/common/bin/
$ ./wlst.sh

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline> connect('weblogic','weblogic1','t3://localhost:7001')
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'base_domain'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

wls:/base_domain/serverConfig> cd('/')
wls:/base_domain/serverConfig> ls()
dr--   AdminConsole
dr--   AppDeployments
dr--   BridgeDestinations
dr--   Clusters
dr--   CoherenceClusterSystemResources
dr--   CoherenceServers
....

wlst有offline(離線)online(在線)兩種模式,經過connect命令能夠從offline進入online,wlst按照Linux目錄形式對weblogic資源進行管理,甚至連操做的命令都和Linux高度類似,好比cd是切換到指定資源路徑下,ls()是列出該目錄下全部資源。如要了解更多關於wlst的內容,能夠查看官方文檔node

wlst腳本

本腳本原做者爲Tim Hall,本文這裏稍做修改,如下爲腳本代碼python

create_managed_server.pyweb

#!/usr/bin/python
# Author : Tim Hall
# Modified : Jianfeng.Zheng
# Save Script as : create_managed_server.py

import time
import getopt
import sys
import re

# Get location of the properties file.
properties = ''
try:
   opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="])
except getopt.GetoptError:
   print 'create_managed_server.py -p <path-to-properties-file>'
   sys.exit(2)
for opt, arg in opts:
   if opt == '-h':
      print 'create_managed_server.py -p <path-to-properties-file>'
      sys.exit()
   elif opt in ("-p", "--properties"):
      properties = arg
print 'properties=', properties

# Load the properties from the properties file.
from java.io import FileInputStream
 
propInputStream = FileInputStream(properties)
configProps = Properties()
configProps.load(propInputStream)

# Set all variables from values in properties file.
adminUsername=configProps.get("admin.username")
adminPassword=configProps.get("admin.password")
adminURL=configProps.get("admin.url")
msName=configProps.get("ms.name")
msAddress=configProps.get("ms.address")
msPort=configProps.get("ms.port")
msMachine=configProps.get("ms.machine")

# Display the variable values.
print 'adminUsername=', adminUsername
print 'adminPassword=', adminPassword
print 'adminURL=', adminURL
print 'msName=', msName
print 'msAddress=', msAddress
print 'msPort=', msPort
print 'msMachine=', msMachine

# Connect to the AdminServer.
connect(adminUsername, adminPassword, adminURL)

edit()
startEdit()

# Create the managed Server.
cd('/')
cmo.createServer(msName)
cd('/Servers/' + msName)
cmo.setListenAddress(msAddress)
cmo.setListenPort(int(msPort))


# Associated with a node manager.
cd('/Servers/' + msName)
cmo.setMachine(getMBean('/Machines/' + msMachine))

save()
activate()

disconnect()
exit()

properties文件

腳本所需參數經過properties文件傳入,如下是properties文件shell

api-api-managed-server.properties api

# AdminServer connection details.
admin.username=weblogic
admin.password=weblogic1
admin.url=t3://10.1.11.71:7001

ms.name=api-server
ms.address=0.0.0.0
ms.port=7002
ms.machine=api-server-machine

admin.username: weblogic管理員用戶名
admin.password: weblogic管理員密碼
admiin.url: weblogic控制檯地址須要加上t3協議字段
ms.name: managed server名稱,能夠自定義
ms.address: managed server監聽地址
ms.port: managed server監聽端口號
ms.machine: managed server關聯的計算機名稱bash

ms.machine須要提早建立好,能夠在weblogic控制檯頁面http://localhost:7001/console/console.portal?_nfpb=true&_pageLabel=CoreMachineMachineTablePage建立服務器

運行

create_managed_server.pyapi-api-managed-server.properties文件上傳到服務器,這裏上傳到目錄~/shelloracle

$ cd /u01/app/Oracle/Middleware/user_projects/domains/base_domain/bin
$ . ./setDomainEnv.sh
$ java weblogic.WLST ~/shell/create_managed_server.py -p ~/shell/api-managed-server.properties

ps:. ./setDomainEnv.sh第一個點(.)不能省略

執行完畢後登陸console查看結果。

參考

相關文章
相關標籤/搜索