本文重点:
- WLST在线模式配置现有的domains。
- WLST离线模式配置现有的domains。
1、WLST在线模式配置现有的domains
由于和一个活动的domain进行交互,所有的在线更改必须由weblogic变更管理的进程来做控制。
例1:wlst脚本创建一个受管服务器
connect("username", "password", "0.0.0.0:port) # 连接一个运行中的实例 edit() # 进入可更改的树 startEdit() # 开启一个start session,获取一个配置锁 svr = cmo.createServer("managedServer") # 创建一个受管服务器 svr.setListenPort(8001) # 设置受管服务器端口 svr.setListenAddress("my-address") # 设置监听地址 save() # 保存更改,类似控制台中点击保存按钮 activate(block="true") # 激活所有更改,类似控制台中应用更改按钮,block参数代表是否等待activate操作完成才进入下一步操作,true代表等待。
# get the server mbean to target it tBean = getMBean("Servers/managedServer") # 判断是否创建成功 if tBean != None: print "Found our target"
disconnect() # 断开连接 exit() # 退出脚本 |
例2:修改至生产模式
wls:/offline> connect('weblogic', '!QAZ2wsx', '127.0.0.1:7001') Connecting to t3://127.0.0.1:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'base_domains'.
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_domains/serverConfig> edit() Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit().
For more help, use help(edit)
wls:/base_domains/edit> startEdit() Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. wls:/base_domains/edit !> cmo.setProductionModeEnabled(false) wls:/base_domains/edit !> activate() Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed.
The following non-dynamic attribute(s) have been changed on MBeans that require server re-start: MBean Changed : com.bea:Name=AdminServer,Type=WebServerLog,Server=AdminServer,WebServer=AdminServer Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=Server-0,Type=WebServerLog,Server=Server-0,WebServer=Server-0 Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=AdminServer,Type=Log,Server=AdminServer Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=AdminServer,Type=DataSourceLogFile,DataSource=AdminServer,Server=AdminServer Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=base_domains,Type=Log Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=base_domains,Type=Domain Attributes changed : ProductionModeEnabled
MBean Changed : com.bea:Name=Server-0,Type=Log,Server=Server-0 Attributes changed : RotateLogOnStartup
MBean Changed : com.bea:Name=Server-0,Type=DataSourceLogFile,DataSource=Server-0,Server=Server-0 Attributes changed : RotateLogOnStartup
Activation completed wls:/base_domains/edit> exit()
Exiting WebLogic Scripting Tool. |
例3:跟踪配置更改
wls:/offline> connect('weblogic', '!QAZ2wsx', '127.0.0.1:7001') Connecting to t3://127.0.0.1:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'base_domains'.
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_domains/serverConfig> edit() Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit().
For more help, use help(edit)
wls:/base_domains/edit> startEdit() Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. wls:/base_domains/edit !> cmo.createServer('managed2') [MBeanServerInvocationHandler]com.bea:Name=managed2,Type=Server wls:/base_domains/edit !> cd('Servers/managed2') wls:/base_domains/edit/Servers/managed2 !> cmo.setListenPort(7702) wls:/base_domains/edit/Servers/managed2 !> showChanges() # 查看未提交更改
All changes that are made but not yet activated are:
MBean Changed : com.bea:Name=base_domains,Type=Domain Operation Invoked : create Attribute Modified : Servers Attributes Old Value : null Attributes New Value : managed2 Server Restart Required : false
MBean Changed : com.bea:Name=managed2,Type=Server Operation Invoked : modify Attribute Modified : ListenPort Attributes Old Value : null Attributes New Value : 7702 Server Restart Required : false
wls:/base_domains/edit/Servers/managed2 !> save() Saving all your changes ... Saved all your changes successfully. wls:/base_domains/edit/Servers/managed2 !> activate() Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed |
例4:另两个重要的命令undo和cancelEdit
undo:可以反转没有保存或者没有激活的更改。
cancelEdit:直接退出edit(),会反转没有保存或者没有激活的更改,还会释放编辑锁。
更多的属性操作和更改:
上一节中描述的标准change-management命令是用于调用configurationManagerMBean中操作的便捷命令。 除了这些操作之外,configurationManagerMBean还包含描述编辑会话的属性和操作。
有关详细信息,请参阅Oracle WebLogic Server MBean Reference中的"configurationManagerMBean"。
要访问此MBean,请使用WLST getConfigManager命令。
示例中的WLST联机脚本以管理员身份将WLST连接到服务器实例,检查进行更改的当前编辑器是否是特定的运算符,然后取消配置编辑。 该脚本还会清除所有已完成的激活任务。
- WLST离线模式配置现有的domains(本文略,详见:03-07_创建域自定义模版)