一键准备Oracle安装

在Linux下安装Oracle软件以前,有至关工做须要准备,包括创建用户、配置内核参数、配置资源限制参数、配置Oracle用户环境等,十分繁琐。即使十分熟悉,也须要花费必定的精力来准备。说白了,作这些事情有点相似于低水平重复建设,虽没有多大技术含量,却又不得不作。如今将这些准备工做作成脚本,这样能够近乎实现一键准备Oracle安装。node

说明:c++

1> 该脚本的执行方式为sh Oracle_Setup_Prepare.sh orcl /u01,两个参数说明见脚本解释部分。数据库

2> 该脚本中涉及到一个文本文件Package_list,是Oracle安装依赖包的列表。具体内容以下文所示。bash

3> 该脚本主要针对于单实例数据库安装。session

4> 安装信息可参考生成的output.log文件oracle

脚本内容以下:app

[oracle@node3 ~]$ cat Oracle_Setup_Prepare.sh ui

复制代码
#!/bin/bash
############################################
###功能:Preparation for Oracle Installation
###参数:SID BASE
###其中,sid指的是ORACLE_SID
###BASE指的是ORACLE_BASE的一级目录,如ORACLE_BASE=/u01/app/oracle,则BASE为/u01
############################################

#检查参数个数是否正确
if [ $# -ne 2 ];then
   echo "$0 SID BASE"
   exit
fi

SID="$1"
BASE="$2"

#主机名绑定
IP=`ifconfig |awk -F'[: ]+' 'NR==2{print $4'}`
HOST=`hostname`
sed -i '$a'$IP' '$HOST'' /etc/hosts

#Checking the Package Requirements
#将须要安装的表的列表贴在Package_list文件中
awk -F'-[0-9]' '{print $1}' Package_list |awk '{print $1}' |uniq |xargs yum install -y > output.log 2>&1

#Creating Required Operating System Groups and Users
groupadd -g 800 oinstall
groupadd -g 801 dba
groupadd -g 802 oper
useradd -g oinstall -G dba,oper oracle
echo oracle | passwd --stdin oracle >> output.log 2>&1

#Configure Kernal Parameters
sed -i '$a\fs.aio-max-nr = 1048576' /etc/sysctl.conf
sed -i '$a\fs.file-max = 6815744' /etc/sysctl.conf
sed -i '$a\kernel.shmall = 2097152' /etc/sysctl.conf
sed -i '$a\kernel.shmmax = 536870912' /etc/sysctl.conf
sed -i '$a\kernel.shmmni = 4096' /etc/sysctl.conf
sed -i '$a\kernel.sem = 250 32000 100 128' /etc/sysctl.conf
sed -i '$a\net.ipv4.ip_local_port_range = 9000 65500' /etc/sysctl.conf
sed -i '$a\net.core.rmem_default = 262144' /etc/sysctl.conf
sed -i '$a\net.core.rmem_max = 4194304' /etc/sysctl.conf
sed -i '$a\net.core.wmem_default = 262144' /etc/sysctl.conf
sed -i '$a\net.core.wmem_max = 1048586' /etc/sysctl.conf
sysctl -p >> output.log 2>&1

#Configure Resource Limits
sed -i '$a\oracle           soft    nproc   2047' /etc/security/limits.conf
sed -i '$a\oracle           hard    nproc   16384' /etc/security/limits.conf
sed -i '$a\oracle           soft    nofile  1024' /etc/security/limits.conf
sed -i '$a\oracle           hard    nofile  65536' /etc/security/limits.conf

#Add the following line to the /etc/pam.d/login file, if it does not already exist:
sed -i '$a\session    required     pam_limits.so' /etc/pam.d/login

#Add the following line to the /etc/profile
sed -i '$a\if [[ $USER = "oracle" ]]; then' /etc/profile
sed -i '$a\     if [[ $SHELL = "/bin/ksh" ]]; then' /etc/profile
sed -i '$a\             ulimit -p 16384' /etc/profile
sed -i '$a\             ulimit -n 65536' /etc/profile
sed -i '$a\     else' /etc/profile
sed -i '$a\             ulimit -u 16384 -n 65536' /etc/profile
sed -i '$a\     fi' /etc/profile
sed -i '$a\fi' /etc/profile
source /etc/profile

#Configuring the oracle User's Environment
sed -i '$a\export ORACLE_SID='$SID'' /home/oracle/.bash_profile
sed -i '$a\export ORACLE_BASE='$BASE'/app/oracle' /home/oracle/.bash_profile
sed -i '$a\export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.1/db_1' /home/oracle/.bash_profile
sed -i '$a\export PATH=$ORACLE_HOME/bin:$PATH' /home/oracle/.bash_profile
source /home/oracle/.bash_profile

#Creating Required Directories
mkdir -p $ORACLE_HOME
chown -R oracle.oinstall $BASE/app
chmod -R 775 $BASE/app

echo "Preparation For Oracle Installation Is Over!"
复制代码

Package_list内容以下:spa

[oracle@node3 ~]$ cat Package_list unix

复制代码
binutils-2.17.50.0.6
compat-libstdc++-33-3.2.3
compat-libstdc++-33-3.2.3 (32 bit)
elfutils-libelf-0.125
elfutils-libelf-devel-0.125
gcc-4.1.2
gcc-c++-4.1.2
glibc-2.5-24
glibc-2.5-24 (32 bit)
glibc-common-2.5
glibc-devel-2.5
glibc-devel-2.5 (32 bit)
glibc-headers-2.5
ksh-20060214
libaio-0.3.106
libaio-0.3.106 (32 bit)
libaio-devel-0.3.106
libaio-devel-0.3.106 (32 bit)
libgcc-4.1.2
libgcc-4.1.2 (32 bit)
libstdc++-4.1.2
libstdc++-4.1.2 (32 bit)
libstdc++-devel 4.1.2
make-3.81
sysstat-7.0.2
unixODBC-2.2.11
unixODBC-2.2.11 (32 bit)
unixODBC-devel-2.2.11
unixODBC-devel-2.2.11 (32 bit)
复制代码

 PS: 既然sed每次都是在最后一行追加,其实,用echo "***" >> filename便可实现。

相关文章
相关标签/搜索