ansible-playbook 之 一键安装weblogic11

一、目的

  通过ansible实现一键自动安装weblogic11并启用的功能。

二、准备条件

  • jdk安装包
  • weblogic安装包
  • ansiable yaml文件
  • 静默安装weblogic的静默文件silent.xml
  • 自动部署服务的静默文件Domain.py

三、实现过程

3.1 编写yaml文件

文件名:setup_weblogic11

---
- hosts: "{{hostname}}"    未来需要安装服务的远程主机名
  remote_user: "{{user}}"   未来安装所用的用户
  vars:
    - jdk_src: "{{jdk_src}}"     安装需要的java包真实存在的路径
    - weblogic_src: "{{weblogic_src}}"   安装需要的weblogic_src真实存在的路径
    - weblogc_dest:  "/opt/install/weblogic"    指定weblogic放置的位置
    - jdk_dest:  "/usr/local/jdk"       指定jdk上传的位置  
  tasks:
    - name: create workDictory for weblogic     
      file: path=/opt/{{item}} state=directory
      with_items:
      -  ["install","log","server"]
    - name: 拷贝JDK以及weblogic相关软件
      copy:  src={{item.src}} dest={{item.dest}} backup=yes owner=root group=root
      with_items:
        - {'src':"{{jdk_src}}",'dest':"/usr/local/jdk"}
        - {'src':"{{weblogic_src}}",'dest':"/opt/install/wls1036_generic.jar"}
        - {'src':'silent.xml','dest':'/opt/install/silent.xml'}
        - {'src':'Domain.py','dest':'/opt/install/Domain.py'}
    - name: tar sorftware
      shell: cd /usr/local && tar xvf jdk && rm jdk -rf
    - name: write jdk_path to profile
      shell: echo {{item}} >> /etc/profile
      with_items:
        ["#set java environment",
         "JAVA_HOME=/{{/jdk1.7.0_79",
         "JRE_HOME=$JAVA_HOME/jre",
         "PATH=$JAVA_HOME/bin:$PATH",
         "CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jre/lib/rt.jar::$JAVA_HOME/lib/tools.jar",
         "export JAVA_HOME  PATH CLASSPATH",
         ]
    - name: update /etc/profile
      shell:  source /etc/profile
    - name: link java
      file:  src={{item.src}} dest={{item.dest}} state=link mode=751 owner=root  group=root
      with_items:
      -  {'src':'/usr/local/jdk1.7.0_79/bin/javac' ,'dest':'/usr/bin/javac', }
      -  {'src':'/usr/local/jdk1.7.0_79/bin/javah' ,'dest':'/usr/bin/javah' }
      -  {'src':'/usr/local/jdk1.7.0_79/bin/java' ,'dest':'/usr/bin/java' }
      -  {'src':'/usr/local/jdk1.7.0_79/bin/javadoc' ,'dest':'/usr/bin/javadoc' }
    - name: setup weblogic
      shell: java -jar  -Xmx1024m  /opt/install/weblogic.jar -mode=silent -silent_xml=/opt/install/silent.xml && /opt/install/wlserver_10.3/common/bin/wlst.sh /opt/install/geo1Domain.py
      notify:
        - start weblogic
  handlers:
    - name: start weblogic
      shell: cd /opt/ && nohup /opt/install/bea/user_projects/domains/geo1Domain/bin/startWebLogic.sh "&"

3.2 编写silent.xml文件

<bea-installer>
     <input-fields>
       <data-value name="BEAHOME" value="/opt/install/bea" />
       <data-value name="LOCAL_JVMS" value="/opt/install/jdk1.7.0_79" />
       <data-value name="WLS_INSTALL_DIR" value="/ddit/install/wlserver_10.3" />
       <data-value name="OCP_INSTALL_DIR" value="/ddit/install/coherence_3.7" />
       <data-value name="COMPONENT_PATHS" value="WebLogic Server/Core Application Server\
          |WebLogic Server/Administration Console\
          |WebLogic Server/Configuration Wizard and Upgrade Framework\
          |WebLogic Server/Web 2.0 HTTP Pub-Sub Server\
          |WebLogic Server/WebLogic JDBC Drivers\
          |WebLogic Server/Third Party JDBC Drivers\
          |WebLogic Server/WebLogic Server Clients\
          |WebLogic Server/WebLogic Web Server Plugins\
          |WebLogic Server/UDDI and Xquery Support\
          |Oracle Coherence/Coherence Product Files" />
       <data-value name="INSTALL_NODE_MANAGER_SERVICE" value="yes" />
       <data-value name="NODEMGR_PORT" value="5556" />
       <data-value name="INSTALL_SHORTCUT_IN_ALL_USERS_FOLDER" value="no"/>
   </input-fields>
</bea-installer>

3.3 编写自动安装服务的静默文件Domain.py文件

#=======================================================================================
# This is an example of a simple WLST offline configuration script. The script creates
# a geo-redundant WebLogic SIP Server domain using the Geographic Redundancy Site 1 Domain
# template. The script demonstrates how to open a domain template, create and edit
# configuration objects, and write the domain configuration information to the
# specified directory.
#
# The domain consists of an admin server, two replica servers, and two engine server
# representing the primary site in a geo-redundant system.
#
# Please note that some of the values used in this script are subject to change based on
# your WebLogic installation and the template you are using.
#
# Usage:
#      java weblogic.WLST <WLST_script>
#
# Where:
#      <WLST_script> specifies the full path to the WLST script.
#=======================================================================================

#=======================================================================================
# Open a domain template.
#=======================================================================================

readTemplate("/opt/install/wlserver_10.3/common/templates/domains/wls.jar")
addTemplate("/opt/install/wlserver_10.3/common/templates/domains/geo1domain.jar")

#=======================================================================================
# Configure the Administration Server and SSL port.
#
# To enable access by both local and remote processes, you should not set the
# listen address for the server instance (that is, it should be left blank or not set).
# In this case, the server instance will determine the address of the machine and
# listen on it.
#=======================================================================================

cd('Servers/AdminServer')
set('ListenAddress','')
set('ListenPort', 7001)

create('AdminServer','SSL')
cd('SSL/AdminServer')
set('Enabled', 'True')
set('ListenPort', 7002)

#=======================================================================================
# Define the user password for weblogic.
#=======================================================================================

cd('/')
cd('Security/base_domain/User/weblogic')
# Please set password here before using this script, e.g. cmo.setPassword('value')
cmo.setPassword('12345678')
#=======================================================================================
# Write the domain and close the domain template.
#=======================================================================================

setOption('OverwriteDomain', 'true')
writeDomain('/ddit/install/bea/user_projects/domains/Domain')
closeTemplate()

#=======================================================================================
# Exit WLST.
#=======================================================================================

exit()

3.4 将安装包及配置文件放在同一目录下

本次指定的目录是/home/weblogig11

[root@localhost weblogic11]# pwd
/home/weblogic11
[root@localhost weblogic11]#

[root@localhost weblogic11]# tree
.
├── geo1Domain.py
├── jdk-7u79-linux-x64.tar.gz
├── setup_weblogic.yaml
├── silent.xml
└── wls1036_generic.jar

3.5 执行命令

ansible-playbook /home/weblogic11/setup_weblogic.yaml -e "hostname=1.1.1.1,user=root,jdk_src=/home/weblogic11/jdk-7u79-linux-x64.tar.gz weblogic_src=/home/weblogic11/wls1036_generic.jar"

PS:
hostname必须指定在hosts文件中已经指定好的设备组名或者设备地址

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值