经常在手上要搭建一堆测试环境,oracle软件装来装去的,重复步骤做得很烦。解决这种问题,用虚拟机克隆是一种方法。我这里用脚本搞定一些重复性的动作也是一种方法。我分四个脚本来做。 一。检查服务器配置及是否缺少必须的包。 二。脚本化自动化配置系统参
经常在手上要搭建一堆测试环境,oracle软件装来装去的,重复步骤做得很烦。解决这种问题,用虚拟机克隆是一种方法。我这里用脚本搞定一些重复性的动作也是一种方法。我分四个脚本来做。
一。检查服务器配置及是否缺少必须的包。
二。脚本化自动化配置系统参数,并提供undo功能。
三。脚本化配置全局和oracle用户的环境变量。
四。通过脚本静黙安装oracle软件
自动化脚本能省我不少事,中间只有很少一些步骤需要手工操作。 脚本内容仅供参考,还是要以官方指南和实际环境为准。
环境: 仅针对 oracle 11gr2 for linux 平台
一。 检查服务器配置及是否缺少必须的包
##############################author:xiongchuanliang#create date:2012-12-25#desc:#############################oracle 11g#####################################################################################to determine the distribution and version of linux installed.cat /proc/version#to determine whether the required kernel is installed.uname -r#on linux x86-64# at least 4 gb of ram grep memtotal /proc/meinfo#to determine the size of the configured swap space,enter the following command: grep swaptotal /proc/meminfo#####################################################################################checking the software requirements#####################################################################################package requirementsrpm -q --qf '%{name}-%{version}-%{release} (%{arch})\n' binutils \compat-libstdc++-33 \elfutils-libelf \elfutils-libelf-devel \gcc \gcc-c++ \glibc \glibc-common \glibc-devel \glibc-headers \ksh \libaio \libaio-devel \libgcc \libstdc++ \libstdc++-devel \make \sysstat \unixodbc \unixodbc-devel#yum install unixodbc#yum install unixodbc-devel#####################################################################################to determine if the oracle inventory group exitgrep oinstall /etc/group#to determine whether the orainstall.loc file exists.cat /etc/orainst.loc####################################################################################
上面部份列出操作系统环境,中间是检查包,后面通过检查文件看是否有装过,用cat如果存在,能列出文件内容。
二。脚本化自动化配置系统参数,并提供undo功能。
2.1 脚本分三部份
a. 用于创建安装oracle的相关组和用户
b.用于创建软件安装目录,并授权
c.用于配置相关的系统参数,并在最后显示其内容以供检查
#! /bin/sh##############################author:xiongchuanliang#create date:2012-12-25#desc: oracle 11g for linux##################################################################date=`date +%y+%m+%d`mkdir /bak#creating required operating system groups and usersgroupadd -g 507 oinstallgroupadd -g 502 dbagroupadd -g 503 opergroupadd -g 504 asmadmingroupadd -g 505 asmopergroupadd -g 506 asmdbauseradd -g oinstall -g dba,asmdba,oper -d /home/oracle oracleuseradd -g oinstall -g asmadmin,asmdba,asmoper,oper,dba gridid oracleid gridpasswd oraclepasswd grid######################################mkdir -p /u01/app/gridmkdir -p /u01/app/crs_basemkdir -p /u01/app/crs_homemkdir -p /u01/app/oracle/product/11.2.0/db_1chown -r oracle:oinstall /u01/app/oraclechown -r grid:oinstall /u01/app/crs*chown -r grid:oinstall /u01/app/gridmkdir -p /u01/app/orainventorychown -r grid:oinstall /u01/app/orainventorychmod -r 775 /u01/ls -al /u01#######################################checkresource limits for the oracle software installation usersyes|cp /etc/security/limits.conf /bak/bak_limits.conf#installation owner resource limit recommended rangesecho #xcl ${date} >> /etc/security/limits.confecho oracle soft nproc 2047 >> /etc/security/limits.confecho oracle hard nproc 16384 >> /etc/security/limits.confecho oracle soft nofile 1024 >> /etc/security/limits.confecho oracle hard nofile 65536 >> /etc/security/limits.conf############aioyes|cp /proc/sys/fs/aio-max-nr /bak/aio-max-nrecho > /proc/sys/fs/aio-max-nr 1048576############configuring kernel parameters for linuxyes|cp /etc/sysctl.conf /bak/sysctl.confecho ########### >> /etc/sysctl.confecho #xcl ${date} >> /etc/sysctl.confecho fs.aio-max-nr = 1048576 >> /etc/sysctl.confecho fs.file-max = 6815744 >> /etc/sysctl.confecho kernel.shmall = 2097152 >> /etc/sysctl.confecho kernel.shmmax = 536870912 >> /etc/sysctl.confecho kernel.shmmni = 4096 >> /etc/sysctl.confecho kernel.sem = 250 32000 100 128 >> /etc/sysctl.confecho net.ipv4.ip_local_port_range = 1024 65000 >> /etc/sysctl.confecho net.core.rmem_default=262144 >> /etc/sysctl.confecho net.core.rmem_max=262144 >> /etc/sysctl.confecho net.core.wmem_default=262144 >> /etc/sysctl.confecho net.core.wmem_max=262144 >> /etc/sysctl.conf/sbin/sysctl -p###########cp /etc/pam.d/login /bak/login#64bitecho #xcl ${date} >> /etc/pam.d/loginecho session required /lib/security/pam_limits.so >> /etc/pam.d/loginecho session required pam_limits.so >> /etc/pam.d/login#32bit#session required pam_limits.so#######################################limitscat /etc/security/limits.conf#aiocat /proc/sys/fs/aio-max-nr#pam_limits.socat /etc/pam.d/login#displaying and changing kernel parameter valuescat /etc/sysctl.conf######################################
注意:
/etc/sysctl.conf 文件中已有的参数,如kernel.shmmax和kernel.shmmni之类,要注释掉或直接在上面更改
例子中的参数为oracle安装说明上的例子,实际中要以服务器实际配置为准. 如果不能准确确定具体值,在oracle安装向导的第9步,对有误的参数向导也会给出参考值.
2.2 除了上面脚本自动处理的部份,还有一部份我没写到脚本中去,是需要手工操作的。
#给host加上ip 主机名,em会用到cat /etc/hostshosts:xx.xx.xx.xx erpdbserver.com erpdbserver#设置本机主机名,要和/etc/hosts中设置的主机名对应/etc/sysconfig/networkhostname=erpdbserver#手工决定是否操作#禁用网络时间服务service ntpd stopchkconfig ntpd off#永久关闭防火墙vi /etc/selinux/configselinux=disabledservice iptables stopchkconfig iptables off
2.2 针对上面的脚本,如果发现有误,因为上面脚本在更改相关文件时,都有做备份,可以利用下面的脚本更改回来.
脚本内容主要是删除用户和组,并将备份还原回去。
#! /bin/sh##############################author:xiongchuanliang#create date:2012-12-25#desc: oracle 11g for linux##################################################################yes|cp /bak/bak_limits.conf /etc/security/limits.confyes|cp /bak/aio-max-nr /proc/sys/fs/aio-max-nryes|cp /bak/sysctl.conf /etc/sysctl.conf/sbin/sysctl -pyes|cp /bak/login /etc/pam.d/login######################################userdel oinstalluserdel dbauserdel operuserdel asmadminuserdel asmoperuserdel asmdbagroupdel dbagroupdel opergroupdel asmadmingroupdel asmopergroupdel asmdba#######################################limitscat /etc/security/limits.conf#aiocat /proc/sys/fs/aio-max-nr#pam_limits.socat /etc/pam.d/login#displaying and changing kernel parameter valuescat /etc/sysctl.conf#selinux=disabledcat /etc/selinux/configls /home######################################
三。脚本化配置全局和oracle用户的环境变量。
3.1配置环境变量的脚本
将脚本中的相关变量更改成所需后运行即可。有精力的改成应答式也很容易。
#! /bin/sh##############################author:xiongchuanliang#create date:2012-12-25#desc: user specific environment and startup programs############################date=`date +%y-%m-%d`env_etc_profile=/etc/profileenv_profile=/home/oracle/.bash_profile######################################env_oracle_hostname=erpdbserverenv_oracle_owner=oracleenv_oracle_base=/u01/app/oracleenv_oracle_home=/product/11.2.0/db_1env_oracle_unqname=xcldbenv_oracle_sid=xcldb#american_america.al32utf8env_nls_lang=ammerican_america.zhs16gbk######################################yes|cp ${env_etc_profile} ${env_etc_profile}_bakyes|cp ${env_profile} ${env_profile}_bak######################################echo >> ${env_etc_profile}echo ########################### >> ${env_etc_profile}echo ###xcl ${date} >> ${env_etc_profile}echo if [ \$user = \oracle\ ]; then >> ${env_etc_profile}echo if [ \$shell = \/bin/ksh\ ]; then >> ${env_etc_profile}echo ulimit -p 16384 >> ${env_etc_profile}echo ulimit -n 65536 >> ${env_etc_profile}echo else >> ${env_etc_profile}echo ulimit -u 16384 -n 65536 >> ${env_etc_profile}echo fi >> ${env_etc_profile}echo fi >> ${env_etc_profile}echo ########################### >> ${env_etc_profile}######################################echo ########################### >> ${env_profile}echo ###xcl ${date} >> ${env_profile}echo tmp=/tmp >> ${env_profile}echo tmpdir=\$tmp >> ${env_profile}echo export tmp tmpdir >> ${env_profile}echo >> ${env_profile}#export oracle_hostname=${env_oracle_hostname} >> ${env_profile}echo oracle_owner=${env_oracle_owner} >> ${env_profile}echo oracle_base=${env_oracle_base} >> ${env_profile}echo oracle_home=\$oracle_base${env_oracle_home} >> ${env_profile}echo oracle_unqname=${env_oracle_unqname} >> ${env_profile}echo oracle_sid=${env_oracle_sid} >> ${env_profile}echo export oracle_owner oracle_base oracle_home oracle_unqname oracle_sid >> ${env_profile}echo >> ${env_profile}echo classpath=\$oracle_home/jre:\$oracle_home/jlib:\$oracle_home/rdbms/jlib >> ${env_profile}echo ld_library_path=\$oracle_home/lib:/lib:/usr/lib:/usr/local/lib >> ${env_profile}echo export classpath ld_library_path >> ${env_profile}echo >> ${env_profile}echo oracle_term=xterm >> ${env_profile}#export oracle_term=vt100echo nls_lang=${env_nls_lang} >> ${env_profile}echo tns_admin=\$oracle_home/network/admin >> ${env_profile}#echo sqlpath=~/mydba/sql:\$oracle_home/sqlplus/admin >> ${env_profile}#echo export oracle_term nls_lang tns_admin sqlpath >> ${env_profile}echo export oracle_term nls_lang tns_admin >> ${env_profile}echo >> ${env_profile}echo path=\$oracle_home/bin:/usr/local/bin:/bin:/usr/sbin:/usr/bin:\$path >> ${env_profile}echo export path >> ${env_profile}echo >> ${env_profile}#echo ps1='\`whoami\`@\`hostname -s\`' [\$pwd] >> ${env_profile}#echo export ps1 >> ${env_profile}echo ps1='[\`whoami\`@\`hostname -s\`] :' >> ${env_profile}echo >> ${env_profile}echo umask 022 >> ${env_profile}echo ########################### >> ${env_profile}echo
3.2 配置后使环境变量即时生效 source /home/oracle/.bash_profile
四。通过脚本静黙安装oracle软件
静默安装前,准备后安装有响应文件,设置好参数。
a. 响应文件:
oracle.install.responsefileversion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0oracle.install.option=install_db_swonlyoracle_hostname=xclora.localdomainunix_group_name=oinstallinventory_location=/u01/app/orainventoryselected_languages=en,zh_cn,zh_tworacle_home=/u01/app/oracle/product/11.2.0/db_1oracle_base=/u01/app/oracleoracle.install.db.installedition=eeoracle.install.db.iscustominstall=trueoracle.install.db.customcomponents=oracle.rdbms.partitioning:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0oracle.install.db.dba_group=dbaoracle.install.db.oper_group=operoracle.install.db.config.starterdb.type=general_purposeoracle.install.db.config.starterdb.memorylimit=oracle.install.db.config.starterdb.memoryoption=falseoracle.install.db.config.starterdb.installexampleschemas=falseoracle.install.db.config.starterdb.enablesecuritysettings=trueoracle.install.db.config.starterdb.control=db_controloracle.install.db.config.starterdb.dbcontrol.enableemailnotification=falsesecurity_updates_via_myoraclesupport=falsedecline_security_updates=true
b. 运行oracle安装命令,等待安装完成即可。
在静默安装前,先手工创建orainst.loc文件
vi /etc/orainst.loc
inventory_loc=/u01/app/orainventory
inst_group=oinstall
不然会报下面的错误
[oracle@xclora] :severe:oui-10182:the effective user id does not match the owner of the file, or the process is not the super-user; the system indicates that super-user privilege is required.
[fatal] [ins-10008] session initialization failed
cause: an unexpected error occured while initializing the session.
action: contact oracle support services or refer logs
summary:
执行安装:
./runinstaller -silent -ignoresysprereqs -force -ignoreprereq -responsefile /home/oracle/oracle_install.rsp
c. 如果不少包,且配置参数正确的话,安装命令最后会出现一个提示,让你在另一个会话,用root用户运行脚本。
出现的提示,把脚本在另一会话中用root用户执行即可完成整个数据库
软件的最后安装。
[oracle@xclora] :the following configuration scripts need to be executed as the root user. #!/bin/sh #root scripts to run/u01/app/oracle/product/11.2.0/db_1/root.shto execute the configuration scripts: 1. open a terminal window 2. log in as root 3. run the scripts 4. return to this window and hit enter key to continue
至此,通过4个脚本,即可完成了数据库软件的安装工作。脚本没加交互功能,但足以应付我平常安装用了。
mail: xcl_168@aliyun.com
blog: http://blog.csdn.net/xcl168
