CentOS5u11 Oracle 10g 静默安装手工建库统一配置方案

时间:2022-12-18 08:42:28

环境相关:

OS:CentOS release 5.11
IP:192.168.77.10
MEM:16G
DISK:50G

1. 简单说明

本篇博文实际就是在用的生产环境上的CentOS5系统oracle10g静默安装的方案
本博文包括oracle的软件静默安装、软件升级、打PSU、手工建库、归档备份策略配置
如果是虚拟机装库,因为虚拟机的内存配额可以调整,因此SWAP的划分未必一定是足够的,因此需要调整
如果是实体机装库,实体机的物理内存一般是确定的,因此SWAP的划分一般是合理的,除非物理内存做升级
官方文档地址:https://docs.oracle.com/cd/B19306_01/install.102/b15667/pre_install.htm
主机资源需求:

至少1G物理内存
SWAP大小配置需求:
      512M MEM      2倍MEM的SWAP
     1G~2G MEM    1.5倍MEM的SWAP
     2G~8G MEM      1倍MEM的SWAP
    大于8G MEM   0.75倍MEM的SWAP
/tmp 可用空间大于400M
至少 1.5G~3.5G 数据库软件安装目录空间
至少 1.2G 数据文件存储目录空间

2. 主机克隆,基础环境部署

1° 参照《CentOS5实验机模板搭建部署》
克隆一台实验机,调整内存为16G,并进一步配置主机名和hosts文件:

hostname oracle10g
sed -i "s/^HOSTNAME=.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts
sed -i 's/release 5./release 4./g' /etc/redhat-release
# 需要修改Oracle软件安装时识别系统版本的配置文件
# Oracle10g是支持在CentOS5上安装的,这个问题满满的都是Oracle的恶意

2° 调整SWAP配置:
克隆实验机后,将内存调整为16G,但是模板机的SWAP划分为4G,并不满足Oracle推荐的SWAP划分方案
SWAP的划分建议是:

现在内存资源和硬盘资源并不紧张,如果是小内存的虚拟机,直接将SWAP设置为内存两倍
比如8G的虚拟机内存,直接设置SWAP为16G,甚至20G亦可,因为磁盘策略一般是动态分配的
如果内存大于16G,直接将SWAP设置为16G也是可以的,Oracle并不会报错或者报警告信息
即便是有SWAP空间不足的警告信息,也是可以忽略的,因为如果物理内存瓶颈,SWAP只是延缓了宕机的时间而已
也就是说SWAP空间不足的警告信息,只是一个警告信息,内存瓶颈造成的问题SWAP是无法解决的

调整虚拟机SWAP空间大小的操作如下:

虚拟机关机,新增一块20G的虚拟机磁盘,开机配置
grep -v Filename /proc/swaps |awk '{print "SWAP: "$1,$3/1024/1024" GB"}'
# SWAP: /dev/sda2 4.0983 GB
# 查看当前的SWAP分区所在位置和容量

fdisk -l /dev/sdb
# 查看增加的新磁盘,是一个20G没有任何分区的磁盘
echo -e 'n\np\n1\n\n\nwq\n' |fdisk /dev/sdb
# 非交互式分区,将sdb分成一个主分区,占用所有的空间
mkswap /dev/sdb1
# 格式化分区,格式化成SWAP分区

swapoff /dev/sda2
swapon /dev/sdb1
# 卸载掉原来的SWAP分区,挂载新的SWAP分区
grep -v Filename /proc/swaps |awk '{print "SWAP: "$1,$3/1024/1024" GB"}'
# 查看SWAP分区信息,确认新的SWAP挂载没问题

sed -i 's/.*swap.*/# &/g' /etc/fstab
echo -e '/dev/sdb1\tswap\tswap\tdefaults\t0 0'>>/etc/fstab
# 需要修改fstab,注释掉原SWAP开机挂载,配置新SWAP开机挂载

init 6
grep -v Filename /proc/swaps |awk '{print "SWAP: "$1,$3/1024/1024" GB"}'
# 重启虚拟机测试

3° 系统软件包安装:

#静默安装所需的系统包:
yum -y install bc.x86_64 bind-utils.x86_64 compat-db.x86_64 compat-gcc-34.x86_64 \
compat-gcc-34-c++.x86_64 compat-libstdc++-33.i386 compat-libstdc++-33.x86_64 \
elfutils-libelf-devel.i386 elfutils-libelf-devel.x86_64 gcc.x86_64 gcc-c++.x86_64 \
gdb.x86_64 glibc-devel.i386 glibc-devel.x86_64 glibc-headers.x86_64 irqbalance.x86_64 \
ksh.x86_64 libaio.i386 libaio.x86_64 libaio-devel.i386 libaio-devel.x86_64 libICE.i386 \
libSM.i386 libstdc++.i386 libstdc++-devel.x86_64 libXp.i386 libXt.i386 \
libXtst.i386 make.x86_64 sysstat.x86_64 unixODBC-devel.i386 unixODBC-devel.x86_64 \
unixODBC-libs.i386 unixODBC-libs.x86_64 xorg-x11-utils.x86_64 xorg-x11-xinit.x86_64

# yum -y install unixODBC64-devel.i386 unixODBC64-devel.x86_64
# 如果是OEL,可以装上这两个包

yum -y install kernel.x86_64 kernel-headers.x86_64
# yum -y install kernel-uek.x86_64 kernel-uek-headers.x86_64
# 如果是OEL,则安装uek的kernel包,所谓的uek就是Unbreakable Enterprise Kernel
# 就是那只穿了铁马甲的企鹅,Unbreakable 说的跟真的一样

# 系统并没有安装图形化组件,图形安装时,还需要的系统包:
yum -y groupinstall "X Window System"
#安装图形组件

4° 内核参数调整和用户资源限额配置:
内核参数调整可以参见《CentOS5u11 Oracle 10g 安装部署的内核参数设置简析》
内核参数调整:

echo 'fs.aio-max-nr = 3145728'>>/etc/sysctl.conf
# 如果物理内存大于64G,则打开使用
# echo 'kernel.shmmax = 137438953472'>>/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
sysctl -p

用户资源限额:

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
echo 'session required pam_limits.so'>>/etc/pam.d/login
cat >>/etc/profile<<EOF
if [ \$USER = "oracle" ]; then
  if [ \$SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
  else
    ulimit -u 16384 -n 65536
  fi
fi
EOF

5° Oracle用户创建配置和安装目录创建配置:
用户创建

groupadd -g 1000 oinstall
groupadd -g 1001 dba
useradd -g oinstall -G dba -u 1000 oracle
USERPASS='oracle'
echo "$USERPASS"|passwd --stdin oracle
# oracle的用户密码就是oracle,可以更改,对oracle库的安装和使用没有影响

用户配置

SID=orcl
NLS=UTF8
# 实例名为orcl,字符集为UTF8,根据需求更改设置
cat >>/home/oracle/.bash_profile<<EOF
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=\$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=$SID; export ORACLE_SID
PATH=/usr/sbin:\$PATH; export PATH
PATH=\$ORACLE_HOME/bin:\$PATH; export PATH
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib; export CLASSPATH
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.$NLS
EOF

安装目录配置

# 如果是生产环境,数据库文件目录、备份文件目录和归档文件目录需要考虑挂载另外的存储或者专门的数据盘
mkdir -p /u01/app/oracle/product/10.2.0/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01
# 软件安装目录
mkdir /oradata
chown -R oracle: /oradata # 数据库文件目录 mkdir -p /backup
chown -R oracle:oinstall /backup
# 备份文件目录
mkdir -p /arch
chown -R oracle:oinstall /arch
# 归档文件目录

3. Oracle10.2.0.1软件静默安装

主机已经做了很多变动和配置,建议重启一次主机,

reboot
# 重启主机

chown oracle: /tmp/10201_database_linux_x86_64.cpio.gz
su - oracle
cd /tmp/
gunzip 10201_database_linux_x86_64.cpio.gz
cpio -idcmv<10201_database_linux_x86_64.cpio
rm -rf 10201_database_linux_x86_64.cpio
# 解压数据库安装介质

# 创建软件静默安装需要的应答文件
cd /tmp/database/
cat>>/tmp/install_10g.rsp<<EOF
RESPONSEFILE_VERSION=2.2.1.0.0
UNIX_GROUP_NAME="oinstall"
FROM_LOCATION="/tmp/database/stage/products.xml"
FROM_LOCATION_CD_LABEL=<Value Unspecified>
ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1"
ORACLE_HOME_NAME="OraDb10g_home1"
SHOW_WELCOME_PAGE=true
SHOW_CUSTOM_TREE_PAGE=true
SHOW_COMPONENT_LOCATIONS_PAGE=true
SHOW_SUMMARY_PAGE=true
SHOW_INSTALL_PROGRESS_PAGE=true
SHOW_REQUIRED_CONFIG_TOOL_PAGE=true
SHOW_CONFIG_TOOL_PAGE=true
SHOW_RELEASE_NOTES=true
SHOW_ROOTSH_CONFIRMATION=true
SHOW_END_SESSION_PAGE=true
SHOW_EXIT_CONFIRMATION=true
NEXT_SESSION=false
NEXT_SESSION_ON_FAIL=true
NEXT_SESSION_RESPONSE=<Value Unspecified>
DEINSTALL_LIST={"oracle.server","10.2.0.1.0"}
SHOW_DEINSTALL_CONFIRMATION=true
SHOW_DEINSTALL_PROGRESS=true
CLUSTER_NODES={}
ACCEPT_LICENSE_AGREEMENT=false
TOPLEVEL_COMPONENT={"oracle.server","10.2.0.1.0"}
SHOW_SPLASH_SCREEN=true
SELECTED_LANGUAGES={"en"}
COMPONENT_LANGUAGES={"en"}
INSTALL_TYPE="Enterprise Edition"
sl_superAdminPasswds=<Value Unspecified>
sl_dlgASMCfgSelectableDisks={}
s_superAdminSamePasswd=<Value Unspecified>
s_globalDBName="orcl"
s_dlgASMCfgRedundancyValue="2 (Norm)"
s_dlgASMCfgNewDisksSize="0"
s_dlgASMCfgExistingFreeSpace="0"
s_dlgASMCfgDiskGroupName="DATA"
s_dlgASMCfgDiskDiscoveryString=""
s_dlgASMCfgAdditionalSpaceNeeded=" MB"
s_dbSelectedUsesASM=""
s_dbSIDSelectedForUpgrade=""
s_dbRetChar=""
s_dbOHSelectedForUpgrade=""
s_ASMSYSPassword=<Value Unspecified>
n_performUpgrade=0
n_dlgASMCfgRedundancySelected=2
n_dbType=1
n_dbSelection=0
b_useSamePassword=false
b_useFileSystemForRecovery=false
b_receiveEmailNotification=false
b_loadExampleSchemas=false
b_enableAutoBackup=false
b_dlgASMShowCandidateDisks=true
b_centrallyManageASMInstance=true
sl_dlgASMDskGrpSelectedGroup={" "," "," "," "}
s_dlgRBOUsername=""
s_dlgEMCentralAgentSelected="No Agents Found"
b_useDBControl=true
s_superAdminSamePasswdAgain=<Value Unspecified>
s_dlgEMSMTPServer=""
s_dlgEMEmailAddress=""
s_dlgRBORecoveryLocation="/u01/app/oracle/product/10.2.0/db_1/flash_recovery_area/"
n_upgradeDB=1
n_configurationOption=3
sl_upgradableSIDBInstances={}
n_upgradeASM=0
sl_dlgASMCfgDiskSelections={}
s_ASMSYSPasswordAgain=<Value Unspecified>
n_dbStorageType=0
s_rawDeviceMapFileLocation=""
sl_upgradableRACDBInstances={}
s_dlgRBOPassword=<Value Unspecified>
b_stateOfUpgradeDBCheckbox=false
s_dbSid="orcl"
b_dbSelectedUsesASM=false
sl_superAdminPasswdsAgain=<Value Unspecified>
s_mountPoint="/u01/app/oracle/product/10.2.0/db_1/oradata/"
b_stateOfUpgradeASMCheckbox=false
oracle.assistants.server:OPTIONAL_CONFIG_TOOLS="{}"
oracle.has.common:OPTIONAL_CONFIG_TOOLS="{}"
oracle.network.client:OPTIONAL_CONFIG_TOOLS="{}"
oracle.sqlplus.isqlplus:OPTIONAL_CONFIG_TOOLS="{}"
oracle.sysman.console.db:OPTIONAL_CONFIG_TOOLS="{}"
varSelect=1
s_nameForOPERGrp="dba"
s_nameForDBAGrp="dba"
EOF

./runInstaller -force  -silent -responseFile /tmp/install_10g.rsp
# 传入应答文件,静默安装软件
# 如果没有修改 redhat-release 则需要使用参数 -ignoreSysPrereqs

# 根据提示,可以找到静默安装的日志文件目录:
# /u01/app/oracle/oraInventory/logs/

# 静默安装的屏幕信息分析:
# ...
# ...
# ...
# Installation in progress (Sat Apr 21 11:38:00 CST 2018)
# ............................................................... 14% Done.
# ............................................................... 28% Done.
# ............................................................... 42% Done.
# ............................................................... 56% Done.
# ............................................................... 70% Done.
# ................ 74% Done.
# Install successful
# ...
# Setup in progress (Sat Apr 21 11:39:50 CST 2018)
# .................. 100% Done.
# Setup successful
# End of install phases.(Sat Apr 21 11:39:51 CST 2018)
# 表示库软件安装成功

# WARNING:A new inventory has been created in this session. However, it has not yet been registered as the central inventory of this system.
# To register the new inventory please run the script '/u01/app/oracle/oraInventory/orainstRoot.sh' with root privileges. 
# If you do not register the inventory, you may not be able to update or patch the products you installed.
# 该警告信息是指,一个新的inventory被创建,但是并没有注册到该系统的central inventory中
# 如果不进行注册的化,无法对安装的产品(也就是数据库软件)进行升级或者打补丁
# 注册方法是:使用root权限执行脚本 /u01/app/oracle/oraInventory/orainstRoot.sh

# The following configuration scripts 
# /u01/app/oracle/product/10.2.0/db_1/root.sh
# need to be executed as root for configuring the system. If you skip the execution of the configuration tools, the configuration will not be complete and the product wont function properly. In order to get the product to function properly, you will be required to execute the scripts and the configuration tools after exiting the OUI.
# 还有一个需要使用root权限执行的配置脚本 /u01/app/oracle/product/10.2.0/db_1/root.sh

# The installation of Oracle Database 10g was successful.
# Please check '/u01/app/oracle/oraInventory/logs/silentInstall2018-04-21_11-37-51AM.log' for more details.
# 软件安装完成,相应的安装细节日志是 /u01/app/oracle/oraInventory/logs/silentInstall2018-04-21_11-37-51AM.log

# 使用root权限执行俩脚本:
su -
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/10.2.0/db_1/root.sh
# 数据库软件静默安装就完成了

4. 数据库软件静默升级,安装最后的PSU补丁

数据库软件静默升级:

chown oracle: /tmp/p8202632_10205_Linux-x86-64.zip
su - oracle
cd /tmp
unzip p8202632_10205_Linux-x86-64.zip
rm -rf /tmp/p8202632_10205_Linux-x86-64.zip
# 解压数据库软件升级介质

# 创建软件静默升级需要的应答文件
cd /tmp/Disk1/
cat >>/tmp/Disk1/response/update_10g.rsp<<EOF
RESPONSEFILE_VERSION=2.2.1.0.0
UNIX_GROUP_NAME="oinstall"
FROM_LOCATION="../stage/products.xml"
ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1"
ORACLE_HOME_NAME="OraDb10g_home1"
TOPLEVEL_COMPONENT={"oracle.patchset.db","10.2.0.5.0"}
SHOW_SPLASH_SCREEN=false
SHOW_WELCOME_PAGE=false
SHOW_COMPONENT_LOCATIONS_PAGE=false
SHOW_CUSTOM_TREE_PAGE=false
SHOW_SUMMARY_PAGE=false
SHOW_INSTALL_PROGRESS_PAGE=true
SHOW_REQUIRED_CONFIG_TOOL_PAGE=false
SHOW_OPTIONAL_CONFIG_TOOL_PAGE=false
SHOW_CONFIG_TOOL_PAGE=false
SHOW_XML_PREREQ_PAGE=false
SHOW_RELEASE_NOTES=false
SHOW_END_OF_INSTALL_MSGS=true
SHOW_ROOTSH_CONFIRMATION=true
SHOW_END_SESSION_PAGE=false
SHOW_EXIT_CONFIRMATION=false
NEXT_SESSION=false
NEXT_SESSION_ON_FAIL=false
SHOW_DEINSTALL_CONFIRMATION=false
SHOW_DEINSTALL_PROGRESS=false
ACCEPT_LICENSE_AGREEMENT=true
RESTART_SYSTEM= false
COMPONENT_LANGUAGES={"en"}
DECLINE_SECURITY_UPDATES=true
EOF

./runInstaller -force -silent -responseFile /tmp/Disk1/response/update_10g.rsp
# 传入应答文件,静默升级软件

# 静默安装的屏幕信息分析:
# ...
# ...
# ...
# Deinstall in progress (Saturday, April 21, 2018 11:55:50 AM CST)
# ............................................................... 0% Done.
# ............................................................... 14% Done.
# ............................................................... 28% Done.
# ............................................................... 42% Done.
# ............................................................... 56% Done.
# ............................................................... 70% Done.
# ............................................................... 85% Done.
# ... 100% Done.
# Deinstall successful
# 
# Installation in progress (Saturday, April 21, 2018 11:55:50 AM CST)
# ............................................................... 14% Done.
# ............................................................... 28% Done.
# ............................................................... 42% Done.
# ............................................................... 56% Done.
# ............................................................... 70% Done.
# ............................................................... 85% Done.
# ............. 88% Done.
# Install successful
#
# Setup in progress (Saturday, April 21, 2018 11:56:47 AM CST)
# ........... 100% Done.
# Setup successful
# 从信息可以看出,所谓的升级实际上是卸载然后再次安装新版本软件的过程
# 但是Oracle10g必须要先安装10.2.0.1然后升级10.2.0.5,而不能直接安装10.2.0.5 ...

# End of install phases.(Saturday, April 21, 2018 11:56:49 AM CST)
# WARNING:
# The following configuration scripts need to be executed as the "root" user.
# #!/bin/sh
# #Root script to run
# /u01/app/oracle/product/10.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
# 依然是警告信息,需要使用root执行脚本,此处只有一个需要执行的配置脚本
# 原因是原来的inventory已经注册,升级是从该注册的inventory之上升级,无需再次注册

# The installation of Oracle Database 10g Release 2 Patch Set 4 was successful.
# Please check '/u01/app/oracle/oraInventory/logs/silentInstall2018-04-21_11-55-41AM.log' for more details.
# 软件安装完成,相应的安装细节日志是 /u01/app/oracle/oraInventory/logs/silentInstall2018-04-21_11-55-41AM.log

su -
/u01/app/oracle/product/10.2.0/db_1/root.sh
# 执行脚本
# 数据库软件静默升级就完成了

安装PSU,因为Oracle10g已经停止支持了,已经没有相应的更新补丁了,安装最后的PSU:

chown oracle: /tmp/p6880880_102000_Linux-x86-64.zip
chown oracle: /tmp/p20299014_10205_Linux-x86-64.zip

su - oracle
cd /tmp
unzip p6880880_102000_Linux-x86-64.zip
cp -av OPatch/* $ORACLE_HOME/OPatch/
$ORACLE_HOME/OPatch/opatch version
# OPatch Version: 10.2.0.5.1
# 升级之后的OPatch版本
cd /tmp
rm -rf /tmp/p6880880_102000_Linux-x86-64.zip
rm -rf /tmp/OPatch/

unzip p20299014_10205_Linux-x86-64.zip
cd 20299014
$ORACLE_HOME/OPatch/opatch apply
# Email address/User Name: 
# 直接回车
# Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]:
# 输入Y 回车
# Is the local system ready for patching? [y|n]
# 输入y 回车

# Verifying the update...
# Inventory check OK: Patch ID 20299014 is registered in Oracle Home inventory with proper meta-data.
# Files check OK: Files from Patch ID 20299014 are present in Oracle Home.
# Execution of 'sh /tmp/20299014/custom/scripts/post -apply 20299014 ':
# Return Code = 0
# The local system has been patched and can be restarted.
# OPatch succeeded.
# 看到如上信息,表示PSU安装成功

cd /tmp
rm -rf /tmp/p20299014_10205_Linux-x86-64.zip
rm -rf /tmp/20299014/

5. 手工建库

实例相关设定:

su - oracle
SID=orcl
NLS=UTF8
# 实例名为orcl,字符集为UTF8,根据需求更改设置
SGA=$(grep 'MemTotal' /proc/meminfo |awk '{printf ("%d\n",$2*1024*0.8*0.8)}')
PGA=$(grep 'MemTotal' /proc/meminfo |awk '{printf ("%d\n",$2*1024*0.8*0.2)}')
# 配置MEM的80%分配给Oracle实例
# 配置SGA为其中的80%,配置PGA为其中的20%
DBPASS=oracle
# 配置数据库账号密码为oracle,即sys密码为oracle

配置监听:

cat >$ORACLE_HOME/network/admin/listener.ora<<EOF
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ${SID})
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = ${SID})
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)
      (HOST = $(hostname -i))(PORT = 1521))
  )
EOF
lsnrctl start

配置init.ora:

cat >/home/oracle/init.ora<<EOF
db_block_size=8192
# 数据块8K
db_file_multiblock_read_count=16
open_cursors=300
db_domain=""
db_name=${SID}
background_dump_dest=/u01/app/oracle/admin/${SID}/bdump
core_dump_dest=/u01/app/oracle/admin/${SID}/cdump
user_dump_dest=/u01/app/oracle/admin/${SID}/udump
control_files=("/oradata/${SID}/control01.ctl", "/oradata/${SID}/control02.ctl", "/oradata/${SID}/control03.ctl")
# db_recovery_file_dest=/u01/app/oracle/flash_recovery_area
# db_recovery_file_dest_size=2147483648
# 闪回区不创建
job_queue_processes=100
compatible=10.2.0.5.0
processes=1500
# 进程总数1500
sga_target=$SGA
audit_file_dest=/u01/app/oracle/admin/${SID}/adump
remote_login_passwordfile=EXCLUSIVE
pga_aggregate_target=$PGA
undo_management=AUTO
undo_tablespace=UNDOTBS1
EOF

创建实例运行目录和库文件存放目录:

mkdir -pv /u01/app/oracle/admin/${SID}/{adump,bdump,cdump,dpdump,pfile,udump}
mkdir -pv /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/dbca/${SID}
mkdir -pv /oradata/${SID}/
chown oracle: -R /oradata/

库注册:

ORACLE_SID=${SID}; export ORACLE_SID
echo "${SID}:/u01/app/oracle/product/10.2.0/db_1:N">>/etc/oratab
# 如果库信息没有写入oratab文件,则该库无法被dbca删除

手工建库:

/u01/app/oracle/product/10.2.0/db_1/bin/sqlplus /nolog<<EOF
host /u01/app/oracle/product/10.2.0/db_1/bin/orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/orapw${SID} password=${DBPASS} force=y
-- 创建密码文件
connect "SYS"/"${DBPASS}" as SYSDBA
set echo on
spool /home/oracle/CreateDB.log
-- 建库的日志
startup nomount pfile="/home/oracle/init.ora";
-- nomount实例
CREATE DATABASE "${SID}"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
DATAFILE '/oradata/${SID}/system01.dbf' SIZE 300M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/oradata/${SID}/sysaux01.dbf' SIZE 120M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/oradata/${SID}/temp01.dbf' SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
SMALLFILE UNDO TABLESPACE "UNDOTBS1" DATAFILE '/oradata/${SID}/undotbs01.dbf' SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET ${NLS}
-- 库字符集设置
NATIONAL CHARACTER SET AL16UTF16
LOGFILE
GROUP 1 ('/oradata/${SID}/redo01a.log','/oradata/${SID}/redo01b.log') SIZE 204800K,
GROUP 2 ('/oradata/${SID}/redo02a.log','/oradata/${SID}/redo02b.log') SIZE 204800K,
GROUP 3 ('/oradata/${SID}/redo03a.log','/oradata/${SID}/redo03b.log') SIZE 204800K
-- 三组日志文件,每组俩日志成员,日志文件容量200M
USER SYS IDENTIFIED BY "${DBPASS}" USER SYSTEM IDENTIFIED BY "${DBPASS}";
-- 建库
spool off
set echo on
spool /home/oracle/CreateDBFiles.log
-- 创建users表空间的日志
CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/oradata/${SID}/users01.dbf' SIZE 5M REUSE
 AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT  AUTO;
ALTER DATABASE DEFAULT TABLESPACE "USERS";
spool off
-- 创建users表空间
set echo on
spool /home/oracle/CreateDBCatalog.log
-- 创建性能视图的日志
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/catalog.sql;
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/catblock.sql;
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/catproc.sql;
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/catoctk.sql;
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/owminst.plb;
connect "SYSTEM"/"${DBPASS}"
@/u01/app/oracle/product/10.2.0/db_1/sqlplus/admin/pupbld.sql;
set echo on
spool /home/oracle/sqlPlusHelp.log
-- 创建sqlplus帮助的日志
@/u01/app/oracle/product/10.2.0/db_1/sqlplus/admin/help/hlpbld.sql helpus.sql;
spool off
spool off
connect "SYS"/"${DBPASS}" as SYSDBA
set echo on
spool /home/oracle/postDBCreation.log
-- 收尾日志
set echo on
create spfile='/u01/app/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora' FROM pfile='/home/oracle/init.ora';
-- 创建spfile
shutdown immediate;
-- 关库
connect "SYS"/"${DBPASS}" as SYSDBA
startup ;
-- 重启库
select 'utl_recomp_begin: ' || to_char(sysdate, 'HH:MI:SS') from dual;
execute utl_recomp.recomp_serial();
select 'utl_recomp_end: ' || to_char(sysdate, 'HH:MI:SS') from dual;
spool off
EOF
# 建库日志在/home/oracle目录下,可以另外打开终端,监控日志,监控建库进度
# 如果需要重建,则:
# echo 'shutdown abort'|sqlplus / as sysdba
# rm -rvf cd /oradata/${SID}/*
# rm -rvf /u01/app/oracle/product/10.2.0/db_1/dbs/*${SID}*
# rm -rf /home/oracle/*.log
# 手工建库完成
rm -v /home/oracle/{*.log,init.ora}

6. 配置归档

sqlplus / as sysdba
define SID=orcl
-- 设置归档子目录,将归档存入和SID相同的子目录中
host mkdir -pv /arch/&SID
alter system set log_archive_format='arch_%t_%s_%r.arc' scope=spfile;
alter system set log_archive_dest_10='location=/arch/&SID' scope=spfile;
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
alter system archive log current;
alter system set control_file_record_keep_time=30;
-- 归档留存策略为30天
exit

7. 配置RMAN备份策略

目录配置:

mkdir -pv /backup/rman/script
mkdir -pv /backup/{autobackup,backupset}
mkdir -pv $ORACLE_HOME/block_change_trace
# 创建rman脚本目录、rman自动备份目录、备份集存储目录
# 创建块改变追踪目录

打开块改变追踪:

sqlplus / as sysdba
alter system set control_file_record_keep_time=30;
-- 归档留存策略为30天
alter database enable block change tracking using file '/u01/app/oracle/product/10.2.0/db_1/block_change_trace/track.file';
-- 打开块改变追踪
exit

设置备份策略:

rman target /
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/autobackup/%F';
exit
# 设置备份留存策略、打开控制文件自动备份

创建备份脚本:

# 备份脚本:
cat >/backup/rman/script/rman_inc0.sh<<EOFALL
#!/bin/bash
. ~/.bash_profile
export NLS_LANG=American_America.${NLS}
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
TIME=\$(date "+%Y_%m_%d_%H_%M_%S")

echo ''>>/backup/rman/script/rman_run.log
echo '###########################################################'>>/backup/rman/script/rman_run.log
echo '#######' \$(date '+%F %R:%S') Check and Delete Backup '#######' >>/backup/rman/script/rman_run.log
echo '###########################################################'>>/backup/rman/script/rman_run.log
echo ''>>/backup/rman/script/rman_run.log

rman target / log /backup/rman/script/rman_run.log append<<EOF
allocate channel for maintenance type disk;
crosscheck backup;
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-7';
delete noprompt obsolete;
delete noprompt expired backup;
EOF
# 删除7天前的归档

echo ''>>/backup/rman/script/rman_run.log
echo '##########################################################'>>/backup/rman/script/rman_run.log
echo '#######' \$(date '+%F %R:%S') Start Rman Inc0 Backup  '#######' >>/backup/rman/script/rman_run.log
echo '##########################################################'>>/backup/rman/script/rman_run.log
echo ''>>/backup/rman/script/rman_run.log

rman target / nocatalog log /backup/rman/script/rman_run.log append<<EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
set limit channel c1 readrate=10240;
set limit channel c1 kbytes=4096000;
set limit channel c2 readrate=10240;
set limit channel c2 kbytes=4096000;
backup as compressed backupset filesperset 3 incremental level 0 database format '/backup/backupset/inc0_%d_%T_%s_%p' tag=inc0_\$TIME;
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup as compressed backupset archivelog all not backed up 2 times tag=arch0_\$TIME format '/backup/backupset/arch0_%d_%T_%s_%p';
backup as compressed backupset current controlfile tag=ctl0_\$TIME format '/backup/backupset/ctl0_%d_%T_%s_%p';
backup as compressed backupset spfile tag=spfile0_\$TIME format '/backup/backupset/spfile0_%d_%T_%s_%p';
release channel c1;
release channel c2;
}
EOF
# 归档备份两次
EOFALL

备份任务:

chmod +x /backup/rman/script/rman_inc0.sh
crontab -l>/tmp/crontab.tmp
echo '# Rman Backup Job'>>/tmp/crontab.tmp
echo '0 0 * * * /bin/bash /backup/rman/script/rman_inc0.sh >/dev/null 2>&1'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp

测试:

/bin/bash /backup/rman/script/rman_inc0.sh >/dev/null 2>&1
cd /backup/rman/script/
cat rman_run.log

[TOC]