Weblogic WLST使用(命令行、调用jython脚本)

文章目录

      • Weblogic WLST使用(命令行、调用jython脚本)
        • 1. 调用脚本wlst.sh 执行相关操作
    • Life Cycle Commands
        • 2. 封装命令到jython脚本中
        • 3. 一个例子

Weblogic WLST使用(命令行、调用jython脚本)

参考文档Fusion Middleware WebLogic Scripting Tool Command Reference

1. 调用脚本wlst.sh 执行相关操作

#需替换成实际路径
cd <MIDDLEWARE_HOME>/oracle_common/common/bin
sh wlst.sh
  • connect 连接管理控制台

    wls:/offline> connect('weblogic','welcome1','t3://localhost:8001') 
    Connecting to weblogic server instance running at t3://localhost:8001 as 
    username weblogic...
    
    Successfully connected to Admin Server 'AdminServer' that belongs to domain
    'mydomain'.
    
    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:/mydomain/serverConfig>
    
  • shutdown、start 重启服务器、集群、主节点

    wls:/mydomain/serverConfig> start('myserver', 'Server', 't3://10.7.54.88:7001) 
    Starting server myserver ...
    Server with name myserver started successfully.
    wls:/mydomain/serverConfig>
    
    wls:/mydomain/serverConfig> shutdown('myserver','Server','true',0, 'ture','true') 
    
  • deploy 部署项目 redeploy、undeploy

    wls:/mydomain/serverConfig/Servers> progress= deploy(appName='businessApp',
    path='c:/myapps/business',createplan='true') 
    

    查看部署结果

    wls:/mydomain/serverConfig/Servers> progress.printStatus() 
    Current Status of your Deployment:
    Deployment command type: deploy
    Deployment State       : completed
    Deployment Message     : null
    wls:/mydomain/serverConfig/Servers>
    
  • disconnect* 断开连接

    wls:/mydomain/serverConfig> disconnect() 
    Disconnected from weblogic server: myserver
    wls:/offline> 
    

    命令参考:

    This command… Enables you to… Use with WLST…
    deploy Deploy an application to a WebLogic Server instance. Online
    distributeApplication Copy the deployment bundle to the specified targets. Online
    getWLDM Return the WebLogic DeploymentManager object. Online
    listApplications List all applications that are currently deployed in the WebLogic domain. Online
    loadApplication Load an application and deployment plan into memory. Online and Offline
    redeploy Redeploy a previously deployed application. Online
    startApplication Start an application, making it available to users. Online
    stopApplication Stop an application, making it unavailable to users. Online
    undeploy Undeploy an application from the specified servers. Online
    updateApplication Update an application configuration using a new deployment plan. Online

    Life Cycle Commands

    This command… Enables you to… Use with WLST…
    migrate Migrate services to a target server within a cluster. Online
    resume Resume a server instance that is suspended or in ADMIN state. Online
    shutdown Gracefully shut down a running server instance or cluster. Online
    start Start a Managed Server instance or a cluster using Node Manager. Online
    startServer Start the Administration Server. Online or Offline
    suspend Suspend a running server. Online
  • nmConnect 连接节点管理器

    wls:/myserver/serverConfig> nmConnect('weblogic', 'welcome1', 'localhost', 
    '5555', 'oamdomain', 'c:/Oracle/Middleware/user_projects/domains/oamdomain','ssl') 
    Connecting to Node Manager Server ... 
    Successfully connected to Node Manager.
    wls:/nm/oamdomain>
    
  • nmDisconnect 断开连接

    wls:/nm/oamdomain> nmDisconnect() 
    Successfully disconnected from Node Manager
    wls:/myserver/serverConfig>
    

    命令参考:

    This command… Enables you to… Use with WLST…
    nm Determine whether WLST is connected to Node Manager. Online
    nmConnect Connect WLST to Node Manager to establish a session. Online or Offline
    nmDisconnect Disconnect WLST from a Node Manager session. Online or Offline
    nmEnroll Enables the Node Manager on the current computer to manage servers in a specified WebLogic domain. Online
    nmGenBootStartupProps Generates the Node Manager property files, boot.properties and startup.properties, for the specified server. Online
    nmKill Kill the specified server instance that was started with Node Manager. Online or Offline
    nmLog Return the Node Manager log. Online or Offline
    nmServerLog Return the server output log of the server that was started with Node Manager. Online or Offline
    nmServerStatus Return the status of the server that was started with Node Manager. Online or Offline
    nmStart Start a server in the current WebLogic domain using Node Manager. Online or Offline
    nmVersion Return the Node Manager version. Online or Offline
    startNodeManager Starts Node Manager on the same computer that is running WLST. Online or Offline
    stopNodeManager Stops Node Manager. Online or Offline

2. 封装命令到jython脚本中

  • 入口脚本runWlst.sh

    #!/bin/bash
    #根据具体情况设置路径
    export WLS_HOME=/cib/weblogic/Oracle/Middleware12C/wlserver
    exprot JAVA_HOME=/cib/weblogic/Oracle/jdk1.8.0_144
    exprot CLASSPATCH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$WLS_HOME/server/lib/weblogic.jar
    
    #调用WLST运行test.py脚本传入参数weblogic用户名、weblogic密码、
    #传参非必须
    java weblogic.WLST test.py weblogic weblogic123
    
  • test.py

    import sys
    if len(sys.argv)==3:
        name=sys.argv[1]
        password=sys.argv[2]
        #地址换成实际地址例如:http://10.7.54.88:7001
        nmConnect(name, password, '10.7.54.88', '5556', 'mydomain', '/weblogic/Oracle/Middleware/user_projects/domains/mydomain', 'ssl')
        #查看server状态
        nmServerStatus('server1')
        #退出nodemanager连接
        nmDisconnect()
    
  • 执行方式

    sh runWlst.sh
    

3. 一个例子

​ 重启服务、重新部署

test.py 需要传入四个参数 (nmNamenmPasswordadminNameadminPassword

import sys

def redeploy():
    #连接管理节点
    connect(adminName, adminPassword, adminUrl)
    
    #停止受管服务器
    for i in rang(len(serverNames)):
        shutdown(serverNames[i], 'Server', 'true', 0, 'true', 'true')
        
    #启动受管服务器
     for i in rang(len(serverNames)):
     	start(serverNames[i], 'Server', adminUrl)
        
    #重新部署 projectName为需要重新部署的应用名称
    progress = redploy(‘projectName’)
    appStatus = progress.getState()
    print "redeploy status >>> " + str(appStatus)
    
    #断开管理节点连接
    disconnect()

#通过连接节点管理器控制受管服务器启停,需要连接各自受管服务器自己的节点管理器
def restartNodeManger():
    for i in range(len(ips)):
        #连接节点管理器
        nmConnect(nmName, nmPassword, ips[i], port, "epes_domain", domainPath)
        #停止受管服务器
        nmKill(serverNames[i])
        #启动受管服务器
        nmStart(serverNames[i])
        #查看受管服务器状态
        serverStatus = nmServerStatus(serverNames[i])
        #断开节点管理器连接
        nmDisconnect()
        
if len(sys.argv) == 5
	nmName = sys.argv[1]
    nmPassword = sys.argv[2]
    adminName = sys.argv[3]
    adminPassword = sys.argv[4]
    
    ips = ["10.4.54.88", "10.7.54.89"]
    adminUrl = "t3://10.7.54.88:7001"
    serverNames = ["server1", "server2"]
    port = "5556"
    domainPath = "/weblogic/Oracle/MiddleWare12C/user_project/domains/my_domain"
    
    #节点管理器启停受管服务器
    #reStartServer()
    
    #重新部署
    redeploy()

你可能感兴趣的:(Weblogic,WLST,Linux)