Home Database Mysql Tutorial Oracle安装(2)通过SHELL脚本快速安装Oracle11gR2软件

Oracle安装(2)通过SHELL脚本快速安装Oracle11gR2软件

Jun 07, 2016 pm 03:31 PM
oracle shell Install fast Script pass

经常在手上要搭建一堆测试环境,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
####################################################################################
Copy after login

  上面部份列出操作系统环境,中间是检查包,后面通过检查文件看是否有装过,用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
######################################
Copy after login

      注意:

          /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
Copy after login


 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
######################################
Copy after login

三。脚本化配置全局和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 ""
Copy after login

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
Copy after login

 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
Copy after login

   至此,通过4个脚本,即可完成了数据库软件的安装工作。脚本没加交互功能,但足以应付我平常安装用了。


MAIL: xcl_168@aliyun.com

BLOG: http://blog.csdn.net/xcl168




Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to import oracle database How to import oracle database Apr 11, 2025 pm 08:06 PM

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

How to create a table in oracle How to create a table in oracle Apr 11, 2025 pm 08:00 PM

Creating an Oracle table involves the following steps: Use the CREATE TABLE syntax to specify table names, column names, data types, constraints, and default values. The table name should be concise and descriptive, and should not exceed 30 characters. The column name should be descriptive, and the data type specifies the data type stored in the column. The NOT NULL constraint ensures that null values ​​are not allowed in the column, and the DEFAULT clause specifies the default values ​​for the column. PRIMARY KEY Constraints to identify the unique record of the table. FOREIGN KEY constraint specifies that the column in the table refers to the primary key in another table. See the creation of the sample table students, which contains primary keys, unique constraints, and default values.

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to add table fields to oracle How to add table fields to oracle Apr 11, 2025 pm 07:30 PM

Use the ALTER TABLE statement, the specific syntax is as follows: ALTER TABLE table_name ADD column_name data_type [constraint-clause]. Where: table_name is the table name, column_name is the field name, data_type is the data type, and constraint-clause is an optional constraint. Example: ALTER TABLE employees ADD email VARCHAR2(100) Add an email field to the employees table.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

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.

How to solve garbled code in oracle How to solve garbled code in oracle Apr 11, 2025 pm 10:09 PM

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.

How to re-query oracle How to re-query oracle Apr 11, 2025 pm 07:33 PM

Oracle provides multiple deduplication query methods: The DISTINCT keyword returns a unique value for each column. The GROUP BY clause groups the results and returns a non-repetitive value for each group. The UNIQUE keyword is used to create an index containing only unique rows, and querying the index will automatically deduplicate. The ROW_NUMBER() function assigns unique numbers and filters out results that contain only line 1. The MIN() or MAX() function returns non-repetitive values ​​of a numeric column. The INTERSECT operator returns the common values ​​of the two result sets (no duplicates).

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

See all articles