自动化安装DB2的一点尝试
目标:实现一行命令安装DB2到本地机器或者远程机器
方法一: 完全借助Expect, 模拟人工输入,并对安装过程中需要进行输入或选择的过程进行检测,并输入对应的结果。
原理: 借助Expect脚本,顾名思义,Expect就是期待出现的某个东西出现后,对它作出响应。它被设计来做一些脚本与机器的交互操作,代替人手多次输入。Expect是基于Tcl/tk库的,语法跟tcl脚本语言如出一辙。
set timeout -1spawn $env(SHELL)match_max 100000expect -exact “*leontan@ubuntu:~\$ “
# Login 登录远程机器send — “telnet 10.20.3.188\r”expect “*login: “send — “root\r”expect -exact “root\rroot’s Password: “send — “root\r”expect “# “send — “cd /patch/ese\r”expect “# “
#Install 安装send — “./db2_install”expect -exact “db2_install”send — “\r”expect -exact “\r\rDefault directory for installation of products – /opt/IBM/db2/V9.7\r***********************************************************\rDo you want to choose a different directory to install \[yes/no\] ?\r”send — “no\r”expect -exact “no\r\r\rSpecify one of the following keywords to install DB2 products.\r ESE \r CLIENT \r RTCL \r\rEnter \”help\” to redisplay product names.\rEnter \”quit\” to exit.\r***********************************************************\r”send — “ESE CLIENT RTCL\r” #在需要进行输入的时候自动输入interact # return the shell to user #安装,并把shell操作权还给用户,以便查看出错信息及结果
expect eof
方法二,借助DB2安装程序的response file机制 原理(摘自IBM DB2安装与配置补充手册):与DB2安装向导不同,DB2响应文件安装允许您安装DB2而无需任何用户输入。响应文件安装是由DB2安装程序使用用户生成的响应文件来执行的。响应文件是一个包含安装和配置信息的ASCII文本文件。在交互式安装期间,必须输入安装和配置数据,但是借助响应文件,安装可以在无需任何人工干预的情况下继续。
步骤: 1. 要先有一个已经手工安装好的了机器 2. 使用db2/V9.7/bin/db2rspgn –h 创建response file, 一般会有3个,db2ese.rsp, db2client.rsp,db2rtcl.rsp 3. 另外的机器安装时分别执行 (我没找到可以一条命令同时使用这三个response file的…) ./db2setup –r db2ese.rsp ./db2setup –r db2client.rsp ./db2setup –r db2rtcl.rsp
这样,只要使用一个bash脚本分别执行这三条命令即可完成安装,避免了在命令执行过程中要人工作出响应。脚本文件(就三句话):# more Install_db2.sh#!/bin/shecho “Install ESE, Client, RTCL”
echo “Install ESE”./db2setup -r db2ese.rsp
echo “Install Client”./db2setup -r db2client.rsp
echo “Install Run time”./db2setup -r db2rtcl.rsp
执行情况# ./Install_db2.shInstall ESE, Client, RTCLInstall ESEDBI1191I db2setup is installing and configuring DB2 according to the response file provided. Please wait.
A minor error occurred while installing “DB2 Enterprise Server Edition ” onthis computer. Some features may not function correctly.
For more information see the DB2 installation log at “/tmp/db2setup.log”.Install ClientDBI1191I db2setup is installing and configuring DB2 according to the response file provided. Please wait.
The execution completed successfully.
For more information see the DB2 installation log at “/tmp/db2setup.log”.Install Run timeDBI1191I db2setup is installing and configuring DB2 according to the response file provided. Please wait.
The execution completed successfully.
For more information see the DB2 installation log at “/tmp/db2setup.log”.
对于方法一,需要把一些配置信息抽出来放到一个配置文件中,如远程机器的IP,连接方式,介质路径,安装路径等。
可以考虑再增加自动使用Ftp下载安装介质的步骤。
以上只是初步实现一些基本步骤,离实用性还有段距离,大家帮忙看看有什么错误的地方或有没有其他更方便的办法吧,感觉要实现类似功能的要点一是可靠,二是通用性好。