#!/bin/sh
E_ARGS= 67
E_FILENOTFOUND= 127
SLEEPTIME= 10
RPM_FILE= "jdk-8u121-linux-x64.rpm"
tips( ) {
echo -e "\n\033[34;1m>>> $1 \033[0m"
}
error( ) {
echo -e "\033[31;1m$1 \033[0m"
}
exec_failed( ) {
if [ $? -ne 0 ] ; then
error $1
exit $E_ARGS
fi
}
is_file_exists( ) {
if [ ! -f $1 ] ; then
error "File $1 is not exists!"
exit $E_FILENOTFOUND
fi
}
jdk_ins( ) {
tips "安装java...."
is_file_exists $RPM_FILE
rpm -ivh ${RPM_FILE}
exec_failed "安装JDK出现错误!"
echo "
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$JAVA_HOME /bin:$PATH
export CLASSPATH=.:$JAVA_HOME /lib/dt.jar:$JAVA_HOME /lib/tools.jar
" >> /etc/profile
. /etc/profile
sed -i 's#securerandom.source=file:/dev/random#securerandom.source=file:/dev/./random#' $JAVA_HOME /jre/lib/security/java.security
echo -e "\n\n完成。。。。。" && sleep $SLEEPTIME
}
create_user( ) {
tips "创建weblogic用户和组,默认创建weblogic组"
groupadd weblogic > /dev/bull 2> & 1
read -p "请输入要创建的用户名:" uname
useradd -g weblogic -m $uname
echo "123456" | passwd $uname --stdin
error "用户名:$uname 初始密码:123456"
echo -e "\n\n完成。。。。。"
}
function init_orainst( ) {
tips "创建初始化文件oraInst.loc"
cat > oraInst.loc<< EOF
inventory_loc=$HOME /oraInventory
inst_group=weblogic
EOF
cat $HOME /oraInst.loc && echo -e "\n\n完成。。。。。"
}
function init_wls( ) {
tips "创建响应文件wls.rsp"
cat > wls.rsp<< EOF
[ENGINE]
#DO NOT CHANGE THIS.
Response File Version=1.0.0.0.0
[GENERIC]
#The oracle home location. This can be an existing Oracle Home or a new Oracle Home
ORACLE_HOME=$ORACLE_HOME
#Set this variable value to the Installation Type selected. e.g. WebLogic Server, Coherence, Complete with Examples.
INSTALL_TYPE=WebLogic Server
#Provide the My Oracle Support Username. If you wish to ignore Oracle Configuration Manager configuration provide empty string for user name.
MYORACLESUPPORT_USERNAME=
#Provide the My Oracle Support Password
MYORACLESUPPORT_PASSWORD=<SECURE VALUE>
#Set this to true if you wish to decline the security updates. Setting this to true and providing empty string for My Oracle Support username will ignore the Oracle Configuration Manager configuration
DECLINE_SECURITY_UPDATES=true
#Set this to true if My Oracle Support Password is specified
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
#Provide the Proxy Host
PROXY_HOST=
#Provide the Proxy Port
PROXY_PORT=
#Provide the Proxy Username
PROXY_USER=
#Provide the Proxy Password
PROXY_PWD=<SECURE VALUE>
#Type String (URL format) Indicates the OCM Repeater URL which should be of the format [scheme[Http/Https]]://[repeater host]:[repeater port]
COLLECTOR_SUPPORTHUB_URL=
EOF
cat $HOME /wls.rsp | grep -v "^#\|^$"
echo -e "\n\n完成。。。。。"
}
function inst_wl( ) {
tips "安装weblogic12c(12.2.1.4)"
read -p "上传fmw_12.2.1.4.0_wls_lite_Disk1_1of1.zip到脚本目录后继续...."
is_file_exists fmw_12.2.1.4.0_wls_lite_Disk1_1of1.zip
tips "软件包存在,正在解压...."
unzip fmw_12.2.1.4.0_wls_lite_Disk1_1of1.zip
is_file_exists fmw_12.2.1.4.0_wls_lite_generic.jar
tips "安装文件存在,正在安装...."
java -jar fmw_12.2.1.4.0_wls_lite_generic.jar -silent -responseFile $HOME /wls.rsp -invPtrLoc $HOME /oraInst.loc
exec_failed "weblogic安装失败"
echo -e "\n\n完成。。。。。"
}
function create_domain( ) {
tips "静默创建域创建domain"
echo "系统默认管理weblogic服务的用户名为: weblogic"
read -p "请设置管理员账户的密码[如weblogic123]: " PASSWORD
USERNAME= weblogic
[ -z $PASSWORD ] && PASSWORD= weblogic123
export MW_HOME= $HOME /weblogic12c
export JAVA_HOME= /usr/java/jdk1.8.0_121
cat > create_domain.py<< EOF
readTemplate('$MW_HOME /wlserver/common/templates/wls/wls.jar')
cd('Servers/AdminServer')
set('ListenPort',7001)
cd('/')
cd('Security/base_domain/User/weblogic')
#set admin user to weblogic
cmo.setName('weblogic')
#set password
cmo.setPassword('weblogic123')
setOption('ServerStartMode','prod')
setOption('OverwriteDomain','true')
#set domain path
writeDomain('$MW_HOME /domain')
closeTemplate()
exit()
EOF
cat > create_domain.rsp<< EOF
read template from "$MW_HOME /wlserver/common/templates/wls/wls.jar";
set JavaHome "$JAVA_HOME ";
set ServerStartMode "prod";
find Server "AdminServer" as AdminServer;
set AdminServer.ListenAddress "";
set AdminServer.ListenPort "7001";
set AdminServer.SSL.Enabled "true";
set AdminServer.SSL.ListenPort "7002";
//We can directly create a new managed server.
create Server "base" as BASE;
set BASE.ListenAddress "";
set BASE.ListenPort "8003";
//set BASE.SSL.Enabled "true";
//set BASE.SSL.ListenPort "8004″;
//Create Machine
create Machine "base" as Machinename;
//use templates default weblogic user
find User "$USERNAME " as u1;
set u1.password "$PASSWORD ";
write domain to "$MW_HOME /domain";
EOF
$MW_HOME /wlserver/common/bin/config.sh -mode= silent -silent_script= create_domain.rsp -logfile= create_domain.log
if [ $? -ne 0 ] ; then
error "创建域失败,请检查日志create_domain.log"
exit 1
else
mkdir -p $MW_HOME /domain/servers/AdminServer/security/
cat > $MW_HOME /domain/servers/AdminServer/security/boot.properties<< EOF
username=$USERNAME
password=$PASSWORD
EOF
fi
echo -e "\n\n创建域完成。。。。。"
error "管理员账号:[$USERNAME ] , 密码:[$PASSWORD ]"
}
function start_wl( ) {
tips "正在启动weblogic,请稍后 ...."
cd $MW_HOME /domain/bin/
nohup ./startWebLogic.sh &
n= 1
while true
do
sleep $SLEEPTIME
if test -n "` cat nohup.out | grep 'Server state changed to RUNNING' ` "
then
echo -e "\n\nweblogic启动成功,测试访问 http://IP:7001/console 或者 https://IP:7002/console"
break ;
else
n= ` expr $n + 1`
if [ $n -eq 5 ] ; then
error "weblogic启动失败,请查看日志[$PWD /nohup.out]获取详细信息!"
break ;
else
continue ;
fi
fi
done
}
export -f jdk_ins
export -f create_user
function __part1( ) {
tips "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 本部分实施以下变更:
# 1.安装JDK并配置环境变量
# 2.创建安装运行weblogic的用户
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
jdk_ins;
create_user;
tips "第一部分已经安装完成,请切换到[$uname ]用户并复制此脚本到$uname 家目录下继续执行第二部分: $0 part2"
}
export -f init_orainst
export -f init_wls
export -f inst_wl
export -f create_domain
export -f start_wl
function __part2( ) {
tips "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 本部分实施以下变更:
# 1.生成安装需要的初始化文件和响应文件,ORACLE_HOME=$HOME /weblogic12c
# 2.静默安装weblogic并创建域domain
# 3.启动运行weblogic,访问测试 http://IP:7001/console
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
cd $HOME && read -p "阅读清楚后按Enter键继续...."
ORACLE_HOME= $HOME /weblogic12c
init_orainst;
init_wls;
inst_wl;
create_domain;
start_wl;
}
[ $
case $1 in
"part1" )
__part1
; ;
"part2" )
__part2
; ;
*)
error "参数错误"
; ;
esac
echo "---------- script complete ----------"