Oracle安装(2)通过SHELL脚本快速安装Oracle11gR2软件
经常在手上要搭建一堆测试环境,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之类,要注释掉或直接在上面更改例子中的参数为Oracle安装说明上的例子,实际中要以服务器实际配置为准. 如果不能准确确定具体值,在Oracle安装向导的第9步,对有误的参数向导也会给出参考值.
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 ""
3.2 配置后使环境变量即时生效
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.
