weblogic12c一键安装脚本(CentOS 7.4)

#!/bin/sh
## Oracle WebLogic Server 12.2.1.4(12c)
## JDK要求 Expected result: 1.8.0_191+
## Date: 2020-09-29
## Author: Henry.He <75598595@qq.com>
## Describe behind
#本脚本分为2部分
#第一部分在root用户下执行,安装JDK环境以及配置系统环境
#第二部分在非root用户下执行,安装&配置weblogic
#使用方法:$0 part1|part2
#需要提前准备好的文件如下:
#1. jdk-8u121-linux-x64.rpm
#2. fmw_12.2.1.4.0_wls_lite_Disk1_1of1.zip


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(){
    #rpm安装
    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"
    # This user is the default administrator.
    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/    # 进入创建的域目录bin下
    nohup ./startWebLogic.sh &   # 后台启动使用nohup ./startWebLogic.sh &
    #./stopWeblogic.sh    -- 关闭weblogic
    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
}

#<WebLogicServer> <BEA-000365> <Server state changed to RUNNING.> 
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;
}

[ $# -ne 1 ] && error "参数错误" && exit $E_ARGS 
case $1 in
    "part1")
        __part1
        ;;
    "part2")
        __part2
        ;;
    *)
        error "参数错误"
        ;;
esac

echo "---------- script complete ----------"
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值