时间:2021-07-01 10:21:17 帮助过:42人阅读
经常在手上要搭建一堆测试环境,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 Requirements rpm -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 exit grep 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 Users groupadd -g 507 oinstall groupadd -g 502 dba groupadd -g 503 oper groupadd -g 504 asmadmin groupadd -g 505 asmoper groupadd -g 506 asmdba useradd -g oinstall -G dba,asmdba,oper -d /home/oracle oracle useradd -g oinstall -G asmadmin,asmdba,asmoper,oper,dba grid id oracle id grid passwd oracle passwd grid ###################################### mkdir -p /u01/app/grid mkdir -p /u01/app/crs_base mkdir -p /u01/app/crs_home mkdir -p /u01/app/oracle/product/11.2.0/db_1 chown -R oracle:oinstall /u01/app/oracle chown -R grid:oinstall /u01/app/crs* chown -R grid:oinstall /u01/app/grid mkdir -p /u01/app/oraInventory chown -R grid:oinstall /u01/app/oraInventory chmod -R 775 /u01/ ls -al /u01 ###################################### #CheckResource Limits for the Oracle Software Installation Users yes|cp /etc/security/limits.conf /bak/bak_limits.conf #Installation Owner Resource Limit Recommended Ranges echo "#xcl "${DATE} >> /etc/security/limits.conf echo "oracle soft nproc 2047" >> /etc/security/limits.conf echo "oracle hard nproc 16384" >> /etc/security/limits.conf echo "oracle soft nofile 1024" >> /etc/security/limits.conf echo "oracle hard nofile 65536" >> /etc/security/limits.conf ########### #aio yes|cp /proc/sys/fs/aio-max-nr /bak/aio-max-nr echo > /proc/sys/fs/aio-max-nr 1048576 ########### #Configuring Kernel Parameters for Linux yes|cp /etc/sysctl.conf /bak/sysctl.conf echo " ########### " >> /etc/sysctl.conf echo "#xcl "${DATE} >> /etc/sysctl.conf echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf echo "fs.file-max = 6815744" >> /etc/sysctl.conf echo "kernel.shmall = 2097152" >> /etc/sysctl.conf echo "kernel.shmmax = 536870912" >> /etc/sysctl.conf echo "kernel.shmmni = 4096" >> /etc/sysctl.conf echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf echo "net.ipv4.ip_local_port_range = 1024 65000" >> /etc/sysctl.conf echo "net.core.rmem_default=262144" >> /etc/sysctl.conf echo "net.core.rmem_max=262144" >> /etc/sysctl.conf echo "net.core.wmem_default=262144" >> /etc/sysctl.conf echo "net.core.wmem_max=262144" >> /etc/sysctl.conf /sbin/sysctl -p ########### cp /etc/pam.d/login /bak/login #64bit echo "#xcl "${DATE} >> /etc/pam.d/login echo "session required /lib/security/pam_limits.so" >> /etc/pam.d/login echo "session required pam_limits.so" >> /etc/pam.d/login #32bit #session required pam_limits.so ###################################### #Limits cat /etc/security/limits.conf #AIO cat /proc/sys/fs/aio-max-nr #pam_limits.so cat /etc/pam.d/login #Displaying and Changing Kernel Parameter Values cat /etc/sysctl.conf ######################################
注意:
/etc/sysctl.conf 文件中已有的参数,如kernel.shmmax和kernel.shmmni之类,要注释掉或直接在上面更改
2.2 除了上面脚本自动处理的部份,还有一部份我没写到脚本中去,是需要手工操作的。
#给host加上ip 主机名,em会用到 cat /etc/hosts hosts: xx.xx.xx.xx erpdbserver.com erpdbserver #设置本机主机名,要和/etc/hosts中设置的主机名对应 /etc/sysconfig/network HOSTNAME=erpdbserver #手工决定是否操作 #禁用网络时间服务 service ntpd stop chkconfig ntpd off #永久关闭防火墙 vi /etc/selinux/config SELINUX=disabled service iptables stop chkconfig 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.conf yes|cp /bak/aio-max-nr /proc/sys/fs/aio-max-nr yes|cp /bak/sysctl.conf /etc/sysctl.conf /sbin/sysctl -p yes|cp /bak/login /etc/pam.d/login ###################################### userdel oinstall userdel dba userdel oper userdel asmadmin userdel asmoper userdel asmdba groupdel dba groupdel oper groupdel asmadmin groupdel asmoper groupdel asmdba ###################################### #Limits cat /etc/security/limits.conf #AIO cat /proc/sys/fs/aio-max-nr #pam_limits.so cat /etc/pam.d/login #Displaying and Changing Kernel Parameter Values cat /etc/sysctl.conf #SELINUX=disabled cat /etc/selinux/config ls /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/profile" env_profile="/home/oracle/.bash_profile" ###################################### env_ORACLE_HOSTNAME="erpdbserver" env_ORACLE_OWNER="oracle" env_ORACLE_BASE="/u01/app/oracle" env_ORACLE_HOME="/product/11.2.0/db_1" env_ORACLE_UNQNAME="xcldb" env_ORACLE_SID="xcldb" #AMERICAN_AMERICA.AL32UTF8 env_NLS_LANG="AMMERICAN_AMERICA.ZHS16GBK" ###################################### yes|cp ${env_etc_profile} ${env_etc_profile}"_bak" yes|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=vt100 echo "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 ""
source /home/oracle/.bash_profile
四。通过脚本静黙安装Oracle软件
静默安装前,准备后安装有响应文件,设置好参数。
a. 响应文件:
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=xclora.localdomain UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/u01/app/oraInventory SELECTED_LANGUAGES=en,zh_CN,zh_TW ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ORACLE_BASE=/u01/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=true oracle.install.db.customComponents=oracle.rdbms.partitioning:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0 oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oper oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.memoryLimit= oracle.install.db.config.starterdb.memoryOption=false oracle.install.db.config.starterdb.installExampleSchemas=false oracle.install.db.config.starterdb.enableSecuritySettings=true oracle.install.db.config.starterdb.control=DB_CONTROL oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false SECURITY_UPDATES_VIA_MYORACLESUPPORT=false DECLINE_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.sh To 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