创建weblogic的server和cluster

ip="10.20.0.2"
nwport=8001
wwport=9001 nwlist=[
('wtdsrwnw','Cluster_dsrwnw',8111),
('wtjscxnw','Cluster_jscxnw',8151),
('wtmhnw','Cluster_mhnw',8801),
('wttyrznw','Cluster_tyrznw',8701),
('wtwsjsnw','Cluster_wsjsnw',8501),
('wtwssbnw','Cluster_wssbnw',8101),
('wtwsznw','Cluster_wsznw',8401)
] wwlist=[
('wtmhww','Cluster_mhww',9801),
('wtwsjsww','Cluster_wsjsww',9501),
('wtwssbww','Cluster_wssbww',9101),
('wtwszww','Cluster_wszww',9401)
] def create_servers(port,serverlist):
connect('weblogic','aaaaaa', 't3://%s:%s' %(ip,port))
edit()
startEdit()
for server in serverlist:
cd('/')
cmo.createServer('%s' %server[0])
cd('/Servers/%s' %server[0])
cmo.setListenAddress('%s' %ip)
cmo.setListenPort(server[2]) cd('/')
cmo.createCluster('%s' %server[1]) cd('/Clusters/%s' %server[1])
cmo.setClusterMessagingMode('unicast')
cmo.setClusterBroadcastChannel('') cd('/Servers/%s' %server[0])
cmo.setCluster(getMBean('/Clusters/%s' %server[1])) save()
activate(block="true")
import sys

def create_server(ip,port,server_name,server_port,server_cluster):
connect('weblogic','aaaaa', 't3://%s:%s' %(ip,port))
edit()
startEdit()
cd('/')
server_flag = getMBean('/Servers/%s' %server_name)
if not server_flag:
cmo.createServer('%s' %server_name)
cd('/Servers/%s' %server_name)
cmo.setListenAddress('%s' %ip)
cmo.setListenPort(int(server_port)) cd('/')
cluster_flag= getMBean('/Clusters/%s' %server_cluster)
if not cluster_flag:
cmo.createCluster('%s' %server_cluster) cd('/Clusters/%s' %server_cluster)
cmo.setClusterMessagingMode('unicast')
cmo.setClusterBroadcastChannel('') cd('/Servers/%s' %server_name)
cmo.setCluster(getMBean('/Clusters/%s' %server_cluster)) save()
activate(block="true") create_server(ip=sys.argv[1],port=sys.argv[2],server_name=sys.argv[3],server_port=sys.argv[4],server_cluster=sys.argv[5])

创建jms服务器

ip="10.199.137.124"
nwport=8001
wwport=9001 nwjms_list=[('JMSServer-mhnw','wtmhnw'),('JMSServer-wsznw01','wtwsznw')]
wwjms_list=[('JMSServer-mhww','wtmhww')] def create_jms(port,jmslist):
connect('weblogic','aaaaaa', 't3://%s:%s' %(ip,port))
edit()
startEdit() for jms in jms_list:
cd('/')
cmo.createJMSServer('%s' %jms[0])
cd('/Deployments/%s' %jms[0])
set('Targets',jarray.array([ObjectName('com.bea:Name=%s,Type=Server' %jms[1])], ObjectName)) save()
activate(block="true")
import sys

def create_server(ip,port,jmsname,jmstarget):
connect('weblogic', 'aaaaa', 't3://%s:%s' % (ip, port))
edit()
startEdit()
flag= getMBean('/Deployments/%s' %jmsname)
if not flag:
cmo.createJMSServer('%s' % jmsname)
cd('/Deployments/%s' % jmsname)
set('Targets', jarray.array([ObjectName('com.bea:Name=%s,Type=Server' % jmstarget)], ObjectName))
save()
activate(block="true") create_server(ip=sys.argv[1],port=sys.argv[2],jmsname=sys.argv[3],jmstarget=sys.argv[4])

创建jms模块

ip="10.199.137.124"
nwport=8001
wwport=9001 nwjsmodule_list=[
{"name":"JmsModule-mhnw","resources":[
{"resourcename":"jms/connFactMhnw","type":"connectFactory"},
{"resourcename":"jms/queueMhnwEmail","type":"queue"},
{"resourcename":"jms/queueMhnwOperateLog","type":"queue"},
{"resourcename":"jms/queueMhnwSms","type":"queue"},
{"resourcename":"jms/queueMhnwZcm","type":"queue"}
],
"targets":["wtmhnw"]},
{
"name":"SystemModule-wsz","resources":[
{"resourcename": "jms/connFactNsqd", "type": "connectFactory"},
{"resourcename": "jms/queueMakeNsqd", "type": "queue"},
{"resourcename": "jms/queueNsqdEmail", "type": "queue"}
],
"targets":["wtwsznw"]
}
] wwjsmodule_list=[
{"name": "JmsModule-mhww", "resources": [
{"resourcename": "jms/connFactMhww", "type": "connectFactory"},
{"resourcename": "jms/queueMhwwEmail", "type": "queue"},
{"resourcename": " jms/queueMhwwSms", "type": "queue"}
]
}
] def create_jmsmodule(port,jsmodule_list):
connect('weblogic', 'aaaaa', 't3://%s:%s' %(ip,port))
edit()
startEdit()
for jsmodule in jsmodule_list:
cd('/')
cmo.createJMSSystemResource('%s' %jsmodule["name"])
cd('/SystemResources/%s' %jsmodule["name"])
taglist = []
for tag in jsmodule["targets"]:
taglist.append(ObjectName('com.bea:Name=%s,Type=Server' % tag))
set('Targets', jarray.array(taglist, ObjectName))
for resource in jsmodule["resources"]:
cd('/JMSSystemResources/%s/JMSResource/%s' % (jsmodule["name"],jsmodule["name"]))
if resource["type"]=="connectFactory":
cmo.createConnectionFactory('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setJNDIName('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/SecurityParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setAttachJMSXUserId(false)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/ClientParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setClientIdPolicy('Restricted')
cmo.setSubscriptionSharingPolicy('Exclusive')
cmo.setMessagesMaximum(10)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/TransactionParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setXAConnectionFactoryEnabled(true)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setDefaultTargetingEnabled(true)
else:
cmo.createUniformDistributedQueue('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/UniformDistributedQueues/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setJNDIName('%s' %resource["resourcename"])
cmo.setDefaultTargetingEnabled(true) save()
activate(block="true")
import os

def create_jmsmodule(ip,port,filename):
f = open(filename, "r")
re = f.read()
jsmodule = eval(re)
f.close() connect('weblogic', 'aaaaa', 't3://%s:%s' %(ip,port))
edit()
startEdit()
flag = getMBean("/SystemResources/%s" %jsmodule["name"])
if not flag:
cd('/')
cmo.createJMSSystemResource('%s' %jsmodule["name"])
cd('/SystemResources/%s' %jsmodule["name"])
taglist = []
for tag in jsmodule["targets"]:
taglist.append(ObjectName('com.bea:Name=%s,Type=Server' % tag))
set('Targets', jarray.array(taglist, ObjectName))
for resource in jsmodule["resources"]:
cd('/JMSSystemResources/%s/JMSResource/%s' % (jsmodule["name"],jsmodule["name"]))
if resource["type"]=="connectFactory":
cmo.createConnectionFactory('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setJNDIName('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/SecurityParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setAttachJMSXUserId(false)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/ClientParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setClientIdPolicy('Restricted')
cmo.setSubscriptionSharingPolicy('Exclusive')
cmo.setMessagesMaximum(10)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s/TransactionParams/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"],resource["resourcename"]))
cmo.setXAConnectionFactoryEnabled(true)
cd('/JMSSystemResources/%s/JMSResource/%s/ConnectionFactories/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setDefaultTargetingEnabled(true)
else:
cmo.createUniformDistributedQueue('%s' %resource["resourcename"])
cd('/JMSSystemResources/%s/JMSResource/%s/UniformDistributedQueues/%s' %(jsmodule["name"],jsmodule["name"],resource["resourcename"]))
cmo.setJNDIName('%s' %resource["resourcename"])
cmo.setDefaultTargetingEnabled(true) save()
activate(block="true") create_jmsmodule(ip=sys.argv[1],port=sys.argv[2],filename=sys.argv[3])

创建JDBC

ip="10.199.137.124"
nwport=8001
wwport=9001 nwjdbclist=[{"name":"jdbc/authcDataSource","ip":"10.199.137.123","dbname":"eee","dbuser":"aaaa","dbpasswd":"aaa","targets":["wttyrznw"]},
{"name":"jdbc/gscxDataSource","ip":"10.199.129.45","dbname":"eee","dbuser":"bbb","dbpasswd":"aaa","targets":["wtmhnw","wtwsjsnw","wtwssbnw"]},
{"name":"jdbc/gt3cxDataSource","ip":"10.199.129.45","dbname":"eee","dbuser":"aaa","dbpasswd":"bbbb","targets":["wtjscxnw"]},
{"name":"jdbc/jobNwDataSource","ip":"10.199.137.123","dbname":"eeee","dbuser":"aaa","dbpasswd":"aaaaa","targets":["wtdsrwnw"]},
{"name":"jdbc/NwgyDataSource","ip":"10.199.137.123","dbname":"eee","dbuser":"aaaa","dbpasswd":"bbb","targets":["wtdsrwnw","wtmhnw","wtwsjsnw","wtwssbnw","wtwsznw"]},
{"name":"jdbc/NwnsqdDataSource","ip":"10.199.137.123","dbname":"eeee","dbuser":"aaa","dbpasswd":"bbb","targets":["wtwsznw"]},
{"name":"jdbc/userbindDataSource","ip":"10.199.137.123","dbname":"rrrr","dbuser":"rrrr","dbpasswd":"","targets":["wtmhnw"]},
{"name":"jdbc/userDataSource","ip":"10.199.137.123","dbname":"tttt","dbuser":"","dbpasswd":"","targets":["wtmhnw","wtwsjsnw","wtwssbnw"]},
{"name":"jdbc/WsjsnwDataSource","ip":"10.199.137.123","dbname":"eeeee","dbuser":"eeee","dbpasswd":"wwww","targets":["wtwsjsnw"]},
{"name":"jdbc/WssbnwDataSource","ip":"10.199.137.123","dbname":"","dbuser":"","dbpasswd":"","targets":["wtwssbnw"]}
] def create_jdbc(port,jdbclist):
connect('weblogic', 'aaaaaa', 't3://%s:%s' % (ip,port))
edit()
startEdit()
for jdbc in jdbclist:
cd('/')
cmo.createJDBCSystemResource('%s' %jdbc['name']) cd('/JDBCSystemResources/%s/JDBCResource/%s' %(jdbc["name"],jdbc["name"]))
cmo.setName('%s' %jdbc["name"]) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDataSourceParams/%s' %(jdbc["name"],jdbc["name"],jdbc["name"]))
set('JNDINames',jarray.array([String('%s' %jdbc["name"])], String)) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s' %(jdbc["name"],jdbc["name"],jdbc["name"]))
cmo.setUrl('jdbc:oracle:thin:@%s:1521:%s' %(jdbc["ip"],jdbc["dbname"]))
cmo.setDriverName('oracle.jdbc.OracleDriver')
set('Password', '%s' %jdbc["dbpasswd"]) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s/Properties/%s' %(jdbc["name"],jdbc["name"],jdbc["name"],jdbc["name"]))
cmo.createProperty('user') cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s/Properties/%s/Properties/user' %(jdbc["name"],jdbc["name"],jdbc["name"],jdbc["name"]))
cmo.setValue('%s' %jdbc["dbuser"]) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDataSourceParams/%s' %(jdbc["name"],jdbc["name"],jdbc["name"]))
cmo.setGlobalTransactionsProtocol('OnePhaseCommit') cd('/SystemResources/%s' %(jdbc["name"]))
taglist=[]
for tag in jdbc["targets"]:
taglist.append(ObjectName('com.bea:Name=%s,Type=Server' %tag))
set('Targets',jarray.array(taglist,ObjectName)) save()
activate(block="true")
import sys

def create_jdbc(ip,port,jdbcname,jdbcip,jdbcdb,jdbcuser,jdbcpass,jdbctarget):
connect('weblogic', 'aaaaa', 't3://%s:%s' % (ip,port))
edit()
startEdit()
cd('/')
flag = getMBean("/JDBCSystemResources/%s/JDBCResource/%s" %(jdbcname,jdbcname))
if not flag:
cmo.createJDBCSystemResource('%s' %jdbcname)
cd('/JDBCSystemResources/%s/JDBCResource/%s' %(jdbcname,jdbcname))
cmo.setName('%s' %jdbcname) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDataSourceParams/%s' %(jdbcname,jdbcname,jdbcname))
set('JNDINames',jarray.array([String('%s' %jdbcname)], String)) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s' %(jdbcname,jdbcname,jdbcname))
cmo.setUrl('jdbc:oracle:thin:@%s:1521:%s' %(jdbcip,jdbcdb))
cmo.setDriverName('oracle.jdbc.OracleDriver')
set('Password', '%s' %jdbcpass) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s/Properties/%s' %(jdbcname,jdbcname,jdbcname,jdbcname))
cmo.createProperty('user') cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s/Properties/%s/Properties/user' %(jdbcname,jdbcname,jdbcname,jdbcname))
cmo.setValue('%s' %jdbcuser) cd('/JDBCSystemResources/%s/JDBCResource/%s/JDBCDataSourceParams/%s' %(jdbcname,jdbcname,jdbcname))
cmo.setGlobalTransactionsProtocol('OnePhaseCommit') cd('/SystemResources/%s' %(jdbcname))
taglist=jdbctarget.split(",")
relist=[]
for tag in taglist:
relist.append(ObjectName('com.bea:Name=%s,Type=Server' % tag))
set('Targets',jarray.array(relist,ObjectName)) save()
activate(block="true") create_jdbc(ip=sys.argv[1],port=sys.argv[2],jdbcname=sys.argv[3],jdbcip=sys.argv[4],jdbcdb=sys.argv[5],jdbcuser=sys.argv[6],jdbcpass=sys.argv[7],jdbctarget=sys.argv[8])

部署web app

ip="10.199.137.124"
nwport=8001
wwport=9001 nwappdir="/weblogic/user_projects/domains/wtnwgl_domain/app/"
wwappdir="/weblogic/user_projects/domains/wtwwgl_domain/app/" nwapplist=[
("dzswj-authentication-platform.war","wttyrznw"),
("dzswj-user-manager-platform.war","wtmhnw"),
("gt3cx-app-nw-web.war","wtjscxnw"),
("scheduler-nw-web.war","wtdsrwnw"),
("wsjs-app-nw-web.war","wtwsjsnw"),
("wssb-app-nw-web.war","wtwssbnw"),
("wsz-nw-web.war","wtwsznw")
] wwapplist=[
("dzswj-portals-web.war","wtmhww"),
("wsjs-app-ww-web.war","wtwsjsww"),
("wssb-app-ww-web.war","wtwssbww"),
("wsz-ww-web.war","wtwszww")
] def deploy_app(port,applist,wardir):
connect('weblogic', '', 't3://%s:%s' %(ip,port))
for app in applist:
print '******'+app[0]
edit()
startEdit()
cd("/")
deploy(appName="%s" %app[0],path=wardir+app[0],targets=app[1])
startApplication("%s" %app[0])
save()
activate()

调用wlst脚本

5.创建servers
sh /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh servers.py 6.创建jms服务器
sh /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh jmsserver.py 7.创建jms模块
sh /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh jmsmodule.py 8.创建jdbc
sh /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh jdbc.py 9.部署web app
sh /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh deploy_apps.py

shell对接收的参数列表进行分别处理

#!/bin/bash

DOMAIN_HOME=/weblogic/user_projects/domains
echo $@
let length=$#-
index= applist=()
meta=()
for arg in $@;do
if [[ index -ge length ]];then
meta[${#meta[*]}]=$arg
fi
if [[ index -lt length ]]; then
applist[${#applist[*]}]=$arg
fi
let index++
done echo ${applist[*]}
echo ${meta[*]} for app in ${applist};do
cd $DOMAIN_HOME/$app"_domain"/bin/
chmod +x *.sh
nohup ./startManagedWebLogic.sh $DOMAIN ${meta[]}:${meta[]} >& &
sleep
echo $app"启动完成"
done 调用格式如下
./startapp.sh app1 app2 app3 10.20.0.2

shell对数组的合并和切分

#!/bin/bash

declare -A wtnw
declare -A wtww #wtnw 和wtww 必须先declare否则不能正常合并
wtnw=( [wtdsrwnw]="" [wtjscxnw]="" [wtmhnw]="" [wtnwgl]="" [wttyrznw]="" [wtwsjsnw]="" [wtwssbnw]="" [wtwsznw]="" ) wtww=( [wtwwgl]="" [wtmhww]="" [wtwsjsww]="" [wtwssbww]="" [wtwszww]="" ) #domainport不要先定义必须要直接赋值初始化
domainport=( ${!wtnw[*]} ${!wtww[*]} )
echo ${domainport[*]} echo "合并普通数组"
array2=('','','')
array4=('','','')
array5=($array2,$array4)
echo ${array5[*]} echo "输出数组元素"
for i in ${domainport[*]};do
echo $i
done echo "输出数组索引"
for i in ${!domainport[*]};do
echo $i
done

根据用户操作自动生成wlst脚本

weblogic使用wlst脚本实现自动部署-LMLPHP

weblogic使用wlst脚本实现自动部署-LMLPHP

05-11 20:26