CentOS 7 环境下 Oracle 12c 数据库静默安装与配置指南
一、 基础环境初始化
本文以 CentOS 7.x 操作系统为例,推荐硬件配置为:4核 CPU、4GB 内存、系统盘 40GB、数据盘 20GB。
1. 安装基础工具与关闭安全策略
首先安装解压缩工具,并禁用 SELinux 和系统防火墙,以避免安装过程中的权限与网络拦截问题。
# 安装解压工具
yum install -y unzip zip
# 临时并永久关闭 SELinux
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 停止并禁用 firewalld 防火墙
systemctl stop firewalld
systemctl disable firewalld
2. 配置本地 YUM 源与安装依赖
确保系统已配置可用的 YUM 源(本地镜像或局域网仓库),随后安装 Oracle 12c 所需的系统依赖包。
yum -y install binutils compat-libcap1 compat-libstdc++-33 elfutils-libelf-devel \
gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ \
libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
二、 系统参数与用户配置
1. 创建专属用户与用户组
为 Oracle 数据库创建独立的运行用户和管理组。
groupadd ora_inventory
groupadd ora_dba
useradd -g ora_inventory -G ora_dba ora_user
echo "Oracle@2023" | passwd --stdin ora_user
2. 调整内核参数
编辑 /etc/sysctl.conf 文件,追加以下内核参数以优化数据库性能。请注意,kernel.shmall 和 kernel.shmmax 需要根据服务器实际物理内存进行计算调整,确保 SGA 小于 shmmax。
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
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 = 1048586
保存后执行 sysctl -p 使配置立即生效。
3. 配置用户资源限制
修改 /etc/security/limits.conf,为 Oracle 用户设置进程数和文件描述符限制。
ora_user soft nproc 2047
ora_user hard nproc 16384
ora_user soft nofile 1024
ora_user hard nofile 65536
ora_user soft stack 10240
ora_user hard stack 32768
同时,在 /etc/pam.d/login 中确保加载了 limits 模块:
session required pam_limits.so
4. 设置环境变量与安装目录
切换至 Oracle 用户,配置 .bash_profile 环境变量。
su - ora_user
cat >> ~/.bash_profile <<EOF
export ORACLE_BASE=/u01/app/ora_user
export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0/dbhome_1
export ORACLE_SID=proddb
export PATH=\$ORACLE_HOME/bin:\$PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
EOF
source ~/.bash_profile
</code>
使用 root 用户创建基础目录并赋予权限:
mkdir -p /u01/app/ora_user
chown -R ora_user:ora_inventory /u01
chmod -R 775 /u01
三、 数据库软件静默安装
1. 解压安装包与配置响应文件
将 Oracle 12c 安装包上传至服务器并解压,随后编写静默安装响应文件 db_install.rsp。
unzip linuxx64_12201_database.zip -d /u01/
chown -R ora_user:ora_inventory /u01/database
创建并编辑 /home/ora_user/db_install.rsp:
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.2.0
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=ora_inventory
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_HOME=/u01/app/ora_user/product/12.2.0/dbhome_1
ORACLE_BASE=/u01/app/ora_user
oracle.install.db.InstallEdition=EE
oracle.install.db.OSDBA_GROUP=ora_dba
oracle.install.db.OSOPER_GROUP=ora_inventory
oracle.install.db.OSBACKUPDBA_GROUP=ora_dba
oracle.install.db.OSDGDBA_GROUP=ora_dba
oracle.install.db.OSKMDBA_GROUP=ora_dba
oracle.install.db.OSRACDBA_GROUP=ora_dba
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
2. 执行静默安装
使用 Oracle 用户执行安装命令,并通过 tail 实时查看安装日志。
cd /u01/database
./runInstaller -silent -force -responseFile /home/ora_user/db_install.rsp
# 在另一个终端查看日志
tail -f /u01/app/oraInventory/logs/installActions*.log
安装完成后,根据提示使用 root 用户执行以下两个脚本以完成权限配置:
/u01/app/oraInventory/orainstRoot.sh
/u01/app/ora_user/product/12.2.0/dbhome_1/root.sh
四、 监听器与数据库实例配置
1. 静默配置网络监听
使用 Oracle 用户调用 netca 工具配置监听器。
netca -silent -responseFile /u01/database/response/netca.rsp
# 验证监听状态
lsnrctl status
2. 静默创建数据库实例 (DBCA)
编写建库响应文件 /home/ora_user/dbca.rsp。以下示例配置了一个包含一个 PDB 的容器数据库 (CDB)。若需创建非容器数据库,请将 createAsContainerDatabase 及相关 PDB 参数移除。
responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=proddb
sid=proddb
databaseConfigType=SI
createAsContainerDatabase=true
numberOfPDBs=1
pdbName=pdb_prod
pdbAdminPassword=Pdb@2023
sysPassword=Sys@2023
systemPassword=Sys@2023
templateName=General_Purpose.dbc
characterSet=AL32UTF8
listeners=LISTENER
memoryPercentage=40
automaticMemoryManagement=false
执行 dbca 进行静默建库:
dbca -silent -createDatabase -responseFile /home/ora_user/dbca.rsp
五、 常见安装异常处理
如果在建库或安装过程中意外中断,再次执行时可能会提示实例已存在的错误。此时需要进行环境清理:
- 检查并清理
/etc/oratab文件中残留的 SID 记录,将其删除或注释。 - 使用
ps -ef | grep pmon查找后台残留的 Oracle 进程,并使用kill -9强制终止。 - 清理
$ORACLE_BASE下已生成的数据文件、控制文件及 admin 目录,确保下次安装时环境纯净。