Oracle 19c Single 安装

前言

19C 是未来几年 Oracle 数据库的大趋势,同样的作为长期稳定版,11GR2 在 2020 年 10 月份官方就宣布停止 Support 了,19C 将成为新的长期稳定版,并持续支持到 2027 年,也就意味着 19C 版本将成为最佳选择

image-20220109234706402

Oracle 19C 是支持 RHEL 7 和 RHEL 8 版本的系统进行安装的,RHEL 6 不再被兼容

image-20220109234845049

Linux系统配置

环境信息

主机名 IP地址 操作系统版本 Oracle版本 磁盘空间 内存
orcl 192.168.40.11 rhel 7.6 19c 80G 8G

关闭防火墙

1
2
3
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

关闭Selinux

1
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

配置yum源

挂在镜像

1
mount /dev/cdrom /mnt

配置yum文件

1
2
3
4
5
6
7
8
9
mkdir /etc/yum.repos.d/bak -p
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
cat<<EOF>/etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
EOF

安装依赖包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
yum install -y bc \
binutils \
compat-libcap1 \
compat-libstdc++-33 \
gcc \
gcc-c++ \
elfutils-libelf \
elfutils-libelf-devel \
glibc \
glibc-devel \
ksh \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
libxcb \
libX11 \
libXau \
libXi \
libXtst \
libXrender \
libXrender-devel \
make \
net-tools \
nfs-utils \
smartmontools \
sysstat \
e2fsprogs \
e2fsprogs-libs \
fontconfig-devel \
expect \
unzip \
openssh-clients \
readline* \
psmisc --skip-broken

检查是否安装完成

1
rpm -q bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel make net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline

手动安装compat-libstdc++

1
rpm -ivh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm

配置hosts

1
2
3
cat <<EOF >>/etc/hosts
192.168.40.11 orcl
EOF

存储配置

1
2
3
4
5
6
7
8
9
10
fdisk -l

## lvm
pvcreate /dev/sdb /dev/sdc
vgcreate oraclevg /dev/sdb
vgcreate backupvg /dev/sdc
lvcreate -n oraclelv -L 80000M oraclevg
lvcreate -n oradatalv -L 100000M oraclevg
lvcreate -n backuplv -L 50000M backupvg
lvcreate -n archivelv -L 50000M backupvg

格式化:

1
2
3
4
mkfs.xfs /dev/backupvg/backuplv
mkfs.xfs /dev/backupvg/archivelv
mkfs.xfs /dev/oraclevg/oradatalv
mkfs.xfs /dev/oraclevg/oraclelv

挂载:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vi /etc/fstab
/dev/backupvg/backuplv /backup xfs defaults 0 0
/dev/backupvg/archivelv /archive xfs defaults 0 0
/dev/oraclevg/oraclelv /oracle xfs defaults 0 0
/dev/oraclevg/oradatalv /oradata xfs defaults 0 0

mkdir /backup
mkdir /archive
mkdir /oracle
mkdir /oradata

mount /backup
mount /archive
mount /oracle
mount /oradata

创建用户、组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
## 创建 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 dba,backupdba,dgdba,kmdba,racdba,oper oracle

## 修改 oracle 用户密码为 oracle
echo oracle | passwd --stdin oracle

## 检查 oracle 用户
id oracle

创建安装目录

1
2
3
4
5
6
mkdir -p /oracle/app/oracle/product/19.3.0/db
mkdir -p /oracle/app/oraInventory
chown -R oracle:oinstall /oradata
chown -R oracle:oinstall /archive
chown -R oracle:oinstall /oracle/app
chmod -R 775 /oracle/app

配置avahi-deamon

1
2
3
4
5
6
7
8
9
systemctl stop avahi-daemon.socket
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service
systemctl disable avahi-daemon.socket

##关闭 NOZEROCONF
cat <<EOF >>/etc/sysconfig/network
NOZEROCONF=yes
EOF

关闭透明大页和numa

1
2
sed -i 's/quiet/quiet transparent_hugepage=never numa=off/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg

配置系统参数文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
DAYTIME=$(date +%Y%m%d)
mv /etc/sysctl.conf /etc/sysctl.conf.${DAYTIME}
memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')
totalMemory=$((memTotal / 2048))
shmall=$((memTotal / 4))
if [ $shmall -lt 2097152 ]; then
shmall=2097152
fi
shmmax=$((memTotal * 1024 - 1))
if [ "$shmmax" -lt 4294967295 ]; then
shmmax=4294967295
fi
cat <<EOF >/etc/sysctl.conf
##shmmal's Calculation formula: physical memory 8G:(8*1024*1024*1024)/4096=2097152
##shmmax's Calculation formula: physical memory 8G:(8/2)*1024*1024*1024 -1=4294967295
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = $shmall
kernel.shmmax = $shmmax
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
EOF

# 生效
sysctl -p

系统资源限制

1
2
3
4
5
6
7
8
9
10
cat <<EOF >>/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 134217728
oracle soft memlock 134217728
EOF

配置pam.d

1
2
3
4
cat <<EOF >>/etc/pam.d/login
session required pam_limits.so
session required /lib64/security/pam_limits.so
EOF

配置用户环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## 配置 root 用户
cat <<EOF >>/root/.bash_profile
alias so='su - oracle'
export PS1="[\`whoami\`@\`hostname\`:"'\$PWD]# '
EOF

## 配置 oracle 用户
cat <<EOF >>/home/oracle/.bash_profile
umask 022
export TMP=/tmp
export TMPDIR=\$TMP
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_BASE=/oracle/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/19.3.0/db
export ORACLE_HOSTNAME=orcl
export ORACLE_TERM=xterm
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=mesdb
export PATH=/usr/sbin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:\$PATH
alias sas='sqlplus / as sysdba'
export PS1="[\`whoami\`@\`hostname\`:"'\$PWD]\$ '
EOF

重启,检查Selinux、透明大页、numa

1
2
3
4
5
reboot 

cat /etc/selinux/config
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/cmdline

安装Oracle软件

上传安装包

使用ftp工具上传安装包

1
mkdir /soft

image-20220109172822777

从18c开始要求将Database安装包解压到ORACLE_HOME目录下

1
2
3
4
chown -R oracle:oinstall /soft
su - oracle
cd /soft
unzip -q LINUX.X64_193000_db_home.zip -d $ORACLE_HOME

RU补丁安装

Oracle19c支持在安装Oracle软件之前就打好补丁,可以提前打RU补丁,在安装时指定-applyRU参数

1
2
3
4
5
6
## 解压OPatch工具到$ORACLE_HOME目录
unzip -o -q p6880880_190000_Linux-x86-64.zip -d $ORACLE_HOME
opatch version

## 解压RU补丁包
unzip -q p33192793_190000_Linux-x86-64.zip

image-20220109173747923

开始安装

1
2
3
4
cd $ORACLE_HOME

## 指定RU补丁目录
./runInstaller -applyRU /soft/33192793/

image-20220109175105212

仅安装软件

image-20220109175205100

安装单实例数据库

image-20220109175236997

生产环境安装企业版

image-20220109175311157

安装目录,默认

image-20220109175344029

image-20220109175359109

用户组

image-20220109175429125

root脚本自动执行:

image-20220109175518229

安装前检查

image-20220109175601645

开始安装

image-20220109175633174

自动执行root脚本

image-20220109175744877

安装完成

image-20220109175758838

image-20220109175935925

创建监听

1
netca

image-20220109180039141

image-20220109180056252

image-20220109180108789

image-20220109180158581

image-20220109180207581

image-20220109180221629

检查监听

1
lsnrctl status

image-20220109180309445

创建数据库

1
dbca

选择创建数据库

image-20220109213155602

自定义创建

image-20220109213237927

image-20220109213920663

CDB&PDB

image-20220109214038496

存储配置

image-20220109214346088

归档&闪回

暂不开启归档和闪回

image-20220109214420047

选择监听

image-20220109214440783

数据库选项

生产环境无特殊要求全部安装

image-20220109214531999

配置选项

PGA:

image-20220109214818760

线程数:

image-20220109214842417

字符集:

image-20220109214903263

EM管理器

image-20220109215258128

数据库密码:mesdb2022

image-20220109215543617

创建选项

image-20220109215651312

表空间配置

控制文件大小改为8192

image-20220109220205032

开始创建

image-20220109220520009

image-20220109220528857

创建完成

image-20220109223833891

查看监听

image-20220109224228578

基本使用与配置

启动和停止

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sqlplus / as sysdba
startup
show pdbs
alter pluggable database mespdb open; ## 关闭=> close

##存储过程 启动全部
CREATE TRIGGER open_all_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'alter plggable database all open';
END open_all_pdbs;

##启动监听
lsnrctl start

image-20220107150235871

1
2
3
lsnrctl stop
sqlplus / as sysdba
shutdown immediate;

image-20220107150235871

日志查看

1
2
select * from v$diag_info;
cd /oracle/app/oracle/diag/rdbms/mesdb/mesdb/alert

image-20220107153632793

image-20220107153702836

PDB&CDB

1
2
show con_name;
alter session set container = mespdb;

image-20220107162507434

1
2
3
create tablespace mes datafile '/oradata/MESDB/mespdb/mes01.dbf' size 20m;
create user mesadmin identified by mes2022 default tablespace mes;
grant dba to mesadmin;

image-20220107162926063

TNS解析

1
2
3
4
5
cd $ORACLE_HOME/network/admin/
vi tnsnames.ora

tnsping mespdb
sqlplus mesadmin/mes2022@mespdb

image-20220107165043554

密码过期规则

后续配置在容器数据库下修改

关闭密码180天过期限制

1
2
3
conn /as sysdba
select * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
alter profile default limit password_life_time unlimited;

EM管理器

1
2
select DBMS_XDB.gethttpport from dual;
select DBMS_XBD_CONFIG.gethttpsport from dual;

访问地址:https://192.168.40.11:5500/em

image-20220109233843387

关闭审计

1
2
show parameter audit;
alter system set audit_trail=none scope = spfile;

相关参数

1
2
3
alter system set db_files = 8192 scope=spfile;
alter system set processes = 2000 scope=spfile; ## 进程数
alter system set open_cursors = 2000 scope=spfile; ## 游标数

归档

1
2
3
4
5
6
7
8
9
show parameter recover;
alter system set db_recovery_file_dest_size=10g; ## 略小于存储 留出冗余空间
alter system set db_recovery_file_dest = '/archive'; ## 归档存储路径
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
archive log list;
alter system switch logfile;