search
HomeDatabaseMysql TutorialOracle安装(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




Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function