作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG数据库运维(如安装迁移,性能优化、故障应急处理等)
公众号:老苏畅谈运维
欢迎关注本人公众号,更多精彩与您分享。
一、概述
本文将介绍银河麒麟操作系统V10下静默安装oracle 19c单机数据库的过程。
1.1 主机信息
|系统版本|Kylin Linux Advanced Server release V10 (Lance)|
|-|-|-|
|主机名|oracle-19c|
|IP地址|192.168.12.110|
1.2 数据库信息
|数据库版本|oracle 19.22|
|-|-|-|
|数据库实例名|oracle|
|数据库服务名|oracle|
|数据库字符集|ZHS16GBK|
|数据文件目录|/data/ORACLE|
|归档目录|/arch|
二、麒麟系统配置
2.1 关闭防火墙
[root@oracle-19c ~]# systemctl stop firewalld.service
[root@oracle-19c ~]# systemctl disable firewalld.service
[root@oracle-19c ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2.2 关闭selinux
[root@oracle-19c ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@oracle-19c ~]# setenforce 0
setenforce: SELinux is disabled
[root@oracle-19c ~]# getenforce
Disabled
2.3 配置yum源
[root@oracle-19c yum.repos.d]# yum repolist -v
加载插件:builddep, changelog, config-manager, copr, debug, download, generate_completion_cache, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync
YUM version: 4.2.23
cachedir: /var/cache/dnf
2.4 安装依赖包
yum install -y bc \
binutils \
elfutils-libelf \
elfutils-libelf-devel \
fontconfig-devel \
glibc \
glibc-devel \
ksh \
libaio \
libaio-devel \
libXrender \
libX11 \
libXau \
libXi \
libXtst \
libgcc \
libnsl \
librdmacm \
libstdc++ \
libstdc++-devel \
libxcb \
libibverbs \
make \
policycoreutils \
policycoreutils-python-utils \
smartmontools \
sysstat
2.5 配置hosts
[root@oracle-19c ~]# cat <<EOF>>/etc/hosts
192.168.12.110 oracle-19c
EOF
2.6 配置内核参数
[root@oracle-19c yum.repos.d]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
kernel.sysrq=0
net.ipv4.ip_forward=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.tcp_syncookies=1
kernel.dmesg_restrict=1
net.ipv6.conf.all.accept_redirects=0
net.ipv6.conf.default.accept_redirects=0
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 7903699
kernel.shmmax = 32373555199
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
vm.min_free_kbytes=126459
net.ipv4.conf.ens192.rp_filter = 1
vm.swappiness = 10
kernel.panic_on_oops = 1
kernel.randomize_va_space = 2
kernel.numa_balancing = 0
--生效
sysctl -p
2.7 配置资源限制
[root@oracle-19c ]# vi /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft nproc 2047
oracle hard nproc 16384
oracle hard memlock unlimited
oracle soft memlock unlimited
2.8 创建用户和组
## 创建 oinstall dba oper 组
/usr/sbin/groupadd -g 54321 oinstall
/usr/sbin/groupadd -g 54322 dba
/usr/sbin/groupadd -g 54323 oper
/usr/sbin/groupadd -g 54324 backupdba
/usr/sbin/groupadd -g 54325 dgdba
/usr/sbin/groupadd -g 54326 kmdba
/usr/sbin/groupadd -g 54330 racdba
## 创建 oracle 用户
/usr/sbin/useradd -u 54321 -g oinstall -G asmdba,dba,backupdba,dgdba,kmdba,racdba,oper oracle
## 修改 oracle 用户密码为 oracle
echo "oracle" |passwd oracle --stdin
## 检查 oracle 用户
[root@oracle-19c ~]# id oracle
用户id=54321(oracle) 组id=54321(oinstall) 组=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
2.9 创建安装目录
[root@oracle-19c ~]# mkdir -p /u01/app/oracle/product/19.3.0/db
[root@oracle-19c ~]# mkdir -p /u01/app/oraInventory
[root@oracle-19c ~]# mkdir -p /home/oracle/scripts
[root@oracle-19c ~]# chown -R oracle:oinstall /u01/
[root@oracle-19c ~]# chown -R oracle:oinstall /home/oracle/scripts
[root@oracle-19c ~]# chmod -R 775 /u01/
[root@oracle-19c ~]# chmod -R oracle:oinstall /arch
2.10 配置环境变量
[root@oracle-19c ~]# cat >> ~oracle/.bash_profile <<EOF
umask 022
export TMP=/tmp
export TMPDIR=$TMP
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/db
export ORACLE_TERM=xterm
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=orcl
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/perl/bin:$PATH
export PERL5LIB=$ORACLE_HOME/perl/lib
alias sas='sqlplus / as sysdba'
alias awr='sqlplus / as sysdba @?/rdbms/admin/awrrpt'
alias ash='sqlplus / as sysdba @?/rdbms/admin/ashrpt'
alias alert='vi $ORACLE_BASE/diag/rdbms/*/$ORACLE_SID/trace/alert_$ORACLE_SID.log'
export PS1="[`whoami`@`hostname`:"'$PWD]$ '
export CV_ASSUME_DISTID=OL7
EOF
三、安装oracle软件
3.1 上传安装介质
[oracle@oracle-19c:/soft]$ ll
-rw-r--r-- 1 oracle oinstall 2.9G Apr 20 14:13 LINUX.X64_193000_db_home.zip
-rw-r--r-- 1 oracle oinstall 122M Apr 20 17:08 p35926646_190000_Linux-x86-64.zip
-rw-r--r-- 1 oracle oinstall 1.7G Apr 20 17:08 p35943157_190000_Linux-x86-64.zip
-rw-r--r-- 1 oracle oinstall 122M Apr 20 20:13 p6880880_190000_Linux-x86-64.zip
3.2 静默安装数据库
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db]$ unzip /soft/LINUX.X64_193000_db_home.zip
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db]$ unzip /soft/p6880880_12.2.0.1.41-122010_LINUX.zip
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db]$ ./runInstaller -silent -force -responseFile /soft/db.rsp -ignorePrereq -waitForCompletionLaunching Oracle Database Setup Wizard...
[WARNING] [INS-13014] Target environment does not meet some optional requirements.
CAUSE: Some of the optional prerequisites are not met. See logs for details. installActions2024-04-20_07-59-37PM.log
ACTION: Identify the list of failed prerequisite checks from the log: installActions2024-04-20_07-59-37PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
The response file for this session can be found at:
/u01/app/oracle/product/19.3.0/db/install/response/db_2024-05-27_07-59-37PM.rsp
You can find the log of this install session at:
/tmp/InstallActions2024-05-27_07-59-37PM/installActions2024-05-27_07-59-37PM.log
As a root user, execute the following script(s):
1. /u01/app/oraInventory/orainstRoot.sh
2. /u01/app/oracle/product/19.3.0/db/root.sh
Execute /u01/app/oraInventory/orainstRoot.sh on the following nodes:
[oracle-19c]
Execute /u01/app/oracle/product/19.3.0/db/root.sh on the following nodes:
[oracle-19c]
Successfully Setup Software with warning(s).
Moved the install session logs to:
/u01/app/oraInventory/logs/InstallActions2024-05-27_07-59-37PM
3.3 安装数据库补丁
[oracle@oracle-19c:/soft]$ unzip p35926646_190000_Linux-x86-64.zip
[oracle@oracle-19c:/soft]$ unzip p35943157_190000_Linux-x86-64.zip
[oracle@oracle-19c:/soft]$ cd 35943157/
[oracle@oracle-19c:/soft/35943157]$ opatch apply
Patch 35943157 successfully applied.
Sub-set patch [29517242] has become inactive due to the application of a super-set patch [35943157].
Please refer to Doc ID 2161861.1 for any possible further required actions.
Log file location: /u01/app/oracle/product/19.3.0/db/cfgtoollogs/opatch/opatch2024-05-27_20-14-23PM_1.log
OPatch succeeded.
[oracle@oracle-19c:/soft]$ cd 35926646/
[oracle@oracle-19c:/soft/35926646]$ opatch apply
Oracle Interim Patch Installer version 12.2.0.1.41
Copyright (c) 2024, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/19.3.0/db
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/19.3.0/db/oraInst.loc
OPatch version : 12.2.0.1.41
OUI version : 12.2.0.7.0
Log file location : /u01/app/oracle/product/19.3.0/db/cfgtoollogs/opatch/opatch2024-05-27_20-22-03PM_1.log
Verifying environment and performing prerequisite checks...
OPatch continues with these patches: 35926646
Do you want to proceed? [y|n]
y
User Responded with: Y
All checks passed.
Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.
(Oracle Home = '/u01/app/oracle/product/19.3.0/db')
Is the local system ready for patching? [y|n]
y
User Responded with: Y
Backing up files...
Applying interim patch '35926646' to OH '/u01/app/oracle/product/19.3.0/db'
Patching component oracle.javavm.server, 19.0.0.0.0...
Patching component oracle.javavm.server.core, 19.0.0.0.0...
Patching component oracle.rdbms.dbscripts, 19.0.0.0.0...
Patching component oracle.rdbms, 19.0.0.0.0...
Patching component oracle.javavm.client, 19.0.0.0.0...
Patch 35926646 successfully applied.
Log file location: /u01/app/oracle/product/19.3.0/db/cfgtoollogs/opatch/opatch2024-05-27_20-22-03PM_1.log
OPatch succeeded.
3.4 配置监听
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db/network/admin]$ lsnrctl start
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 27-APR-2024 20:31:33
Copyright (c) 1991, 2023, Oracle. All rights reserved.
Starting /u01/app/oracle/product/19.3.0/db/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Log messages written to /u01/app/oracle/diag/tnslsnr/oracle-19c/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle-19c.itgfinance.com.cn)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 27-APR-2024 20:31:33
Uptime 0 days 0 hr. 0 min. 15 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle-19c/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle-19c.itgfinance.com.cn)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db/network/admin]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 20-APR-2024 20:31:54
Copyright (c) 1991, 2023, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 27-APR-2024 20:31:33
Uptime 0 days 0 hr. 0 min. 21 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle-19c/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle-19c.itgfinance.com.cn)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@oracle-19c:/u01/app/oracle/product/19.3.0/db/network/admin]$
3.5 创建数据库
[oracle@oracle-19c:/soft]$
dbca -silent -createDatabase \
-templateName General_Purpose.dbc \
-gdbname oracle -sid oracle -responseFile NO_VALUE \
-characterSet ZHS16GBK \
-sysPassword oracle \
-systemPassword oracle \
-createAsContainerDatabase false\
-databaseType MULTIPURPOSE \
-automaticMemoryManagement false \
-totalMemory 24567 \
-storageType FS \
-datafileDestination "/data" \
-redoLogFileSize 1024 \
-emConfiguration NONE \
-ignorePreReqs \
-archiveLogDest "/arch" \
-enableArchive true \
-useOMF true \
-initParams processes=3000,undo_retention=86400,audit_trail=none
四、配置oracle
4.1 设置开机启动
####配置oratab
[oracle@oracle-19c:/arch/backup/rman]$ cat /etc/oratab
oracle:/u01/app/oracle/product/19.3.0/db:Y
####配置启停脚本
[root@oracle-19c ~]# cat /usr/local/bin/startOracle.sh
#!/bin/bash
# Load Oracle environment variables
. /home/oracle/.bash_profile
# Start Oracle Database
$ORACLE_HOME/bin/dbstart $ORACLE_HOME > /dev/null 2>&1 &
$ORACLE_HOME/bin/lsnrctl start > /dev/null 2>&1 &
[root@oracle-19c ~]# cat /usr/local/bin/stopOracle.sh
#!/bin/bash
# Load Oracle environment variables
. /home/oracle/.bash_profile
# Stop Oracle Database
$ORACLE_HOME/bin/dbshut $ORACLE_HOME > /dev/null 2>&1 &
$ORACLE_HOME/bin/lsnrctl stop > /dev/null 2>&1 &
####配置systemd
[root@oracle-19c ~]# su - oracle
[oracle@oracle-19c~]$ cd $ORACLE_HOME/bin
[oracle@oracle-19c bin]$ vi dbstart
ORACLE_HOME_LISTNER=$1
修改:
ORACLE_HOME_LISTNER=/u01/app/oracle/product/19.3.0/db
[root@oracle-19c ~]# su - oracle
[oracle@oracle-19c ~]$ cd $ORACLE_HOME/bin
[oracle@oracle-19c bin]$ vi dbshut
ORACLE_HOME_LISTNER=$1
-->
ORACLE_HOME_LISTNER=/u01/app/oracle/product/19.3.0/db
[root@oracle-19c ~]# cat /usr/lib/systemd/system/oracle.service
[Unit]
Description=Oracle Database 19c
After=syslog.target network.target
[Service]
Type=forking
User=oracle
Group=oinstall
ExecStart=/usr/local/bin/startOracle.sh
ExecStop=/usr/local/bin/stopOracle.sh
Environment=ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
Environment=ORACLE_SID=ORACLE
[Install]
WantedBy=multi-user.target
--重新加载systemd
[root@oracle-19c ~]# systemctl daemon-reload
--启动数据库
[root@ oracle-19c~]# systemctl start oracle
--停止数据库
[root@oracle-19c ~]# systemctl stop oracle
--允许自启动
[root@oracle-19c ~]# systemctl enable oracle
Created symlink from /etc/systemd/system/multi-user.target.wants/oracle.service to /usr/lib/systemd/system/oracle.service.
4.2 配置备份
Rman配置
[oracle@oracle-19c:/arch/backup/rman]$ rman target /
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 7;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP OFF;
Rman全备脚本,当前配置保留7天全备
[oracle@oracle-19c:/home/oracle/scripts]$ cat fulldbbackup.sh
#!/bin/bash
source ~/.bash_profile
backtime=`date +"20%y%m%d%H%M%S"`
rman target / log=/home/oracle/scripts/log/level0_backup_${backtime}.log<<EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
crosscheck backup;
crosscheck archivelog all;
sql"alter system archive log current";
delete noprompt expired backup;
delete noprompt obsolete device type disk;
backup as compressed backupset incremental level 0 database include current controlfile format '/arch/backup/rman/backlv0_%d_%T_%t_%s_%p';
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL NOT BACKED UP FORMAT '/arch/backup/rman/arch_%d_%T_%t_%s_%p';
backup as compressed backupset spfile format '/arch/backup/rman/spfile_%d_%T_%t_%s_%p';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
EOF