CentOS 7.9 静默安装 Oracle 12c
环境配置
确认磁盘目录
确认磁盘目录,避免安装到root盘
[root@oracle-1 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 93G 1.9G 92G 3% /
/dev/sda1 497M 226M 272M 46% /boot
/dev/mapper/centos-data 102G 205M 102G 1% /u12
tmpfs 1.6G 0 1.6G 0% /run/user/0
修改主机名和hosts
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname oracle
[root@localhost ~]# hostnamectl status
Static hostname: oracle
Icon name: computer-vm
Chassis: vm
Machine ID: ax**fw
Boot ID: v**
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.92.1.el7.x86_64
Architecture: x86-64
[root@localhost ~]# vi /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1 oracle localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 oracle localhost localhost.localdomain localhost6 localhost6.localdomain6
#实际ip要添加,否则netca执行时报端口 1521 被占用
192.168.18.20 oracle
关闭防火墙
[root@localhost ~]# systemctl stop firewalld
关闭 selinux
[root@localhost ~]# vi /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing #默认为此,修改为 disabled
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
确认已关闭Transparent HugePages
[root@localhost ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
检查与配置分区大小
RAM为1-2GB时,SWAP大小建议为RAM大小的 1.5 倍
RAM为2-16GB时,SWAP大小建议与RAM大小相等
RAM大于16GB时,SWAP大小建议为 16GB
free -m
mkdir /swapvol
dd if=/dev/zero of=/swapvol/swapfile bs=1M count=10240
mkswap /swapvol/swapfile
swapon /swapvol/swapfile
vi /etc/fstab
#文件末尾添加此行
/swapvol/swapfile swap swap defaults 0 0
更改 yum 镜像源
#检查是否已安装 wget
[root@localhost ~]# rpm -qa|grep wget
#若未安装,安装
[root@localhost ~]# yum install wget
#更改镜像源
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#执行更新
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum update
#配置阿里云epel源(理解是部分扩展包可从此下载)
[root@localhost ~]# yum install epel-release
[root@localhost ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
[root@localhost ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
[root@localhost ~]# wget /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装依赖包
可参考 官网(compat-openssl10,libnsl 装不上)
rpm -q bc binutils compat-openssl10 elfutils-libelf glibc glibc-devel ksh libaio libXrender libX11 libXau libXi libXtst libgcc libnsl libstdc++ libxcb libibverbs make smartmontools sysstat compat-libstdc++ compat-libstdc++-33 gcc gcc-c++ glibc-headers libaio-deve libstdc++-devel libstdc++-devel unixODBC-devel binutils-* compat-libstdc++* elfutils-libelf* glibc* gcc-* libaio* libgcc* libstdc++* make* sysstat* unixODBC* unzip compat-libcap1
yum -y install compat-openssl10 ksh libXrender libX11 libXau libXi libXtst libnsl libxcb libibverbs smartmontools sysstat compat-libstdc++ compat-libstdc++-33 gcc-c++ libaio-deve libstdc++-devel libstdc++-devel unixODBC-devel compat-libstdc++* elfutils-libelf* glibc* libaio* libgcc* libstdc++* make* sysstat* unixODBC* unzip compat-libcap1
创建用户组和用户
groupadd oinstall
groupadd dba
groupadd -g 503 oper
groupadd -g 504 asmadmin
groupadd -g 506 asmdba
groupadd -g 505 asmoper
groupadd backupdba
groupadd dgdba
groupadd kmdba
useradd -u 502 -g oinstall -G dba,asmdba,oper,backupdba,dgdba,kmdba oracle
创建文件目录和授权
mkdir /u12
mkdir -p /u12/app/oracle
chmod -R 775 /u12
chown -R oracle:oinstall /u12
chmod -R 775 /u12
chmod g+s /u12
上传oracle安装文件压缩包
从官网下载linux压缩包
通过mobaXterm上传压缩包到/u12
上传 3 份响应文件(提前配置好)
1、db_install.rsp
2、netca.rsp
3、dbca.rsp
修改Linux内核参数
vi /etc/sysctl.conf
写入以下内容
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
重启生效
sysctl -p
修改用设置限定
vi /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
配置环境变量
vi /etc/profile
#在末尾添加
# Oracle environment set
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
#使生效
source /etc/profile
切换 oracle 用户, 配置oracle 用户环境变量
su - oracle
vi .bash_profile
# Oracle Settings
export ORACLE_SID=orcl
export ORACLE_BASE=/u12/app/oracle
export ORACLE_HOME=/u12/app/oracle/product/12.2.0/dbhome_1
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=/lib:$HOME/lib:/lib/x86_64-linux-gnu:/usr/lib:$ORACLE_HOME/lib
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
使配置文件生效
source .bash_profile
安装 Oracle
切换 oracle 用户,解压缩到 /u12/database (database为压缩包内已存在的目录)
[oracle@oracle ~]$ cd /u12
[oracle@oracle u12 ~]$ unzip oracle-12c-db.zip
执行文件1:安装
cd /u12/database
./runInstaller -silent -noconfig -responseFile /u12/db_install.rsp
切换 root 分别执行输出的2份文件
su - root
/u12/app/oracle/oraInventory/orainstRoot.sh
/u12/app/oracle/product/12.2.0/dbhome_1/root.sh
检查日志,根据日志提示信息进行必要的修复(此示例为swap分区不够大和依赖包缺少)
执行文件2:监听
注:执行前检查 /etc/hosts 是否已经添加了ip映射
yourip oracle
su - oracle
netca -silent -responsefile /u12/netca.rsp
执行文件3:创建库
su - oracle
dbca -silent -createDatabase -responseFile /u12/dbca.rsp
安装完毕,检查和使用数据库
sqlplus 连接确认
[oracle@oracle ~]$ sqlplus / as sysdba
listener.ora & tnsnames.ora配置
listener.ora
vi $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /data/u01/app/oracle/product/12.2.0.1/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME=orcl)
(ORACLE_HOME=/u12/app/oracle/product/12.2.0/dbhome_1)
(SID_NAME=orcl)
)
)
ADR_BASE_LISTENER = /u12/app/oracle
tnsnames.ora
vi $ORACLE_HOME/network/admin/tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
(CONNECT_DATA =
(SERVER=DEDICATED)
(SERVICE_NAME=orcl)
)
)
重启监听服务
[oracle@oracle ~]$ lsnrctl stop
[oracle@oracle ~]$ lsnrctl start
重启数据库
SQL> shutdown;
SQL> startup;
SQL> alter system register;
SQL> quit;
监听确认
[oracle@oracle ~]$ lsnrctl reload
[oracle@oracle ~]$ lsnrctl status
防火墙开放端口
[root@oracle ~]# systemctl start firewalld.service
[root@oracle ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
#移除端口
#firewall-cmd --permanent --remove-port=1539/tcp
success
[root@oracle ~]# firewall-cmd --reload
[root@oracle ~]# firewall-cmd --list-ports
1521/tcp
[root@oracle ~]# netstat -lndtup | grep 1521
tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN 26871/tnslsnr
客户端连接确认(sql developer)
参考资源
安装参考资源:
[1]: https://blog.csdn.net/weixin_44499403/article/details/118102218
[2]: https://blog.csdn.net/EricLeiy/article/details/84334390?app_version=6.1.2&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%2284334390%22%2C%22source%22%3A%22wenlaishiwo%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
[3]: https://www.jianshu.com/p/241c205e5f64
[4]: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/ladbi/supported-red-hat-enterprise-linux-8-distributions-for-x86-64.html#GUID-FBEBE161-994D-41B8-B29B-177B47C86D2A
[5]: https://blog.csdn.net/catoop/article/details/101643695
[6]: https://www.jianshu.com/p/23729b982e82
[7]: https://blog.csdn.net/ljunjie82/article/details/42214835
[8]: https://blog.csdn.net/panhaigang123/article/details/79147587