Oracle 11g 快速搭建脚本

一、root用户

1、安装前准备

mv /home/vsftpd/linux.x64_11gR2_database_*  /tmp && cd /tmp
unzip linux.x64_11gR2_database_1of2.zip &&  unzip linux.x64_11gR2_database_2of2.zip
echo "centos" > /etc/hostanme
echo "192.168.10.13 centos"  >> /etc/hosts
yum install yum install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
id oracle

2、编辑etc/sysctl.conf

在/etc/sysctl.conf末尾添加,并执行sysctl -p生效

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

3、编辑/etc/security/limits.conf

在 /etc/security/limits.conf末尾添加

oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    nofile          1024
oracle           hard    nofile          65536
oracle           soft    stack           10240

4、在/etc/pam.d/login末尾添加

session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so

5、在/etc/profile中添加

if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
   ulimit -p 16384
   ulimit -n 65536
  else
   ulimit -u 16384 -n 65536
  fi
fi

6、创建安装目录

mkdir -p /ibmp_data/oracle/product/11.2.0
mkdir /ibmp_data/oracle/oradata
mkdir /ibmp_data/oracle/inventory
mkdir /ibmp_data/oracle/fast_recovery_area
chown -R oracle:oinstall /ibmp_data/oracle
chmod -R 775 /ibmp_data/oracle

二、 oracle用户安装

su - oracle
vim .bash_profile

添加以下内容,并执行source .bash_profile生效
ORACLE_BASE=/ibmp_data/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

1、配置安装参数

cp -R /tmp/database/response/ .
sed -i "s%oracle.install.option=%oracle.install.option=INSTALL_DB_SWONLY%g" /home/oracle/response/db_install.rsp
sed -i "s%ORACLE_HOSTNAME=%ORACLE_HOSTNAME=centos%g"  /home/oracle/response/db_install.rsp
sed -i "s%UNIX_GROUP_NAME=%UNIX_GROUP_NAME=oinstall%g" /home/oracle/response/db_install.rsp
sed -i "s%INVENTORY_LOCATION=%INVENTORY_LOCATION=/ibmp_data/oracle/inventory%g" /home/oracle/response/db_install.rsp
sed -i "s%SELECTED_LANGUAGES=%SELECTED_LANGUAGES=en,zh_CN%g"  /home/oracle/response/db_install.rsp
sed -i "s%ORACLE_HOME=%ORACLE_HOME=/ibmp_data/oracle/product/11.2.0%g"   /home/oracle/response/db_install.rsp
sed -i "s%ORACLE_BASE=%ORACLE_BASE=/ibmp_data/oracle%g"  /home/oracle/response/db_install.rsp
sed -i "s%oracle.install.db.InstallEdition=%oracle.install.db.InstallEdition=EE%g"  /home/oracle/response/db_install.rsp
sed -i "s%oracle.install.db.isCustomInstall=false%oracle.install.db.isCustomInstall=true%g"  /home/oracle/response/db_install.rsp
sed -i "s%oracle.install.db.DBA_GROUP=%oracle.install.db.DBA_GROUP=dba%g"  /home/oracle/response/db_install.rsp
sed -i "s%oracle.install.db.OPER_GROUP=%oracle.install.db.OPER_GROUP=dba%g"  /home/oracle/response/db_install.rsp
sed -i "s%DECLINE_SECURITY_UPDATES=%DECLINE_SECURITY_UPDATES=true%g"  /home/oracle/response/db_install.rsp

2、静默安装

cd /tmp/database/ && ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq

3、安装结束在root下执行

[root@Centos ~]# sh /ibmp_data/oracle/inventory/orainstRoot.sh
[root@Centos ~]# sh /ibmp_data/oracle/product/11.2.0/root.sh

4、oracle用户下配置监听

netca /silent /responsefile /home/oracle/response/netca.rsp

三、静默模式建库

vim /home/oracle/response/dbca.rsp修改如下内容

GDBNAME = "orcl"            //数据库名
SID = "orcl"                //sid
SYSPASSWORD = "ibmp"   
SYSTEMPASSWORD = "ibmp"
SYSMANPASSWORD = "ibmp"
DBSNMPPASSWORD = "ibmp"
DATAFILEDESTINATION =/ibmp_data/oracle/oradata
RECOVERYAREADESTINATION= /ibmp_data/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"   //物理内存的80%
dbca -silent -responseFile /home/oracle/response/dbca.rsp

四、开机自启动

1)第一步:写启动关闭数据库脚本

  • 修改 /ibmp_data/oracle/product/11.2.0/bin/dbstart、vim /ibmp_data/oracle/product/11.2.0/bin/dbshut:
    将ORACLE_HOME_LISTNER=\(1修改为ORACLE_HOME_LISTNER=\)ORACLE_HOME
  • 修改/etc/oratab
    将orcl:/ibmp_data/oracle/product/11.2.0:N中最后的N改为Y
    测试脚本

    2)添加开机启动脚本
    1在root用户下添加开机启动脚本 /etc/rc.d/init.d/oracle
#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/ibmp_data/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
      echo $0 already running.
      exit 1
    fi
    echo -n $"Starting Oracle Database:"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
    touch $LOCKFILE
    ;;
'stop')
    if [ ! -f $LOCKFILE ]; then
      echo $0 already stopping.
      exit 1
    fi
    echo -n $"Stopping Oracle Database:"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    rm -f $LOCKFILE
    ;;
'restart')
    $0 stop
    $0 start
    ;;
'status')
    if [ -f $LOCKFILE ]; then
      echo $0 started.
      else
      echo $0 stopped.
    fi
    ;;
*)
    echo "Usage: $0 [start|stop|status]"
    exit 1
esac
exit 0

3)授权脚本

chmod 755 /etc/init.d/oracle
chkconfig oracle on
service oracle start/stop/restart         //可用于日常关闭和启动数据库

猜你喜欢

转载自www.cnblogs.com/reaperhero/p/10258426.html