CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

时间:2022-08-29 19:27:15

安装阿里云 YUM 源

https://opsx.alibaba.com/mirror?lang=zh-CN

一、安装Oracle数据库

1.安装 Oracle 预安装 RPM

yum -y localinstall https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm

2.安装 Oracle Database RPM

https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

# 若未注册可用我的,勿做修改

1161360442@qq.com
Oracle123
yum -y localinstall /tmp/oracle-database-ee-18c-1.0-.x86_64.rpm

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

二、创建和配置 Oracle 数据库

1.查看配置

# 根据需要修改
cat /etc/sysconfig/oracledb_ORCLCDB-18c.conf #This is a configuration file to setup the Oracle Database.
#It is used when running '/etc/init.d/oracledb_ORCLCDB configure'.
#Please use this file to modify the default listener port and the
#Oracle data location. # LISTENER_PORT: Database listener
# 侦听器的侦听端口
LISTENER_PORT= # ORACLE_DATA_LOCATION: Database oradata location
# 数据存放位置
ORACLE_DATA_LOCATION=/opt/oracle/oradata # EM_EXPRESS_PORT: Oracle EM Express listener
# Enterprise Manager 的侦听端口
EM_EXPRESS_PORT=

2.创建 Oracle 数据库实例

查看脚本

#!/bin/bash
#
# chkconfig:
# Description: This script is responsible for taking care of configuring the Oracle Database and its associated services.
#
# processname: oracledb_ORCLCDB-18c
# Red Hat or SuSE config: /etc/sysconfig/oracledb_ORCLCDB-18c
# # Set path if path not set
case $PATH in
"") PATH=/bin:/usr/bin:/sbin:/etc
export PATH ;;
esac # Check if the root user is running this script
if [ $(id -u) != "" ]
then
echo "You must be root user to run the configurations script. Login as root user and try again."
exit
fi # Setting the required environment variables
export ORACLE_HOME=/opt/oracle/product/18c/dbhome_1 export ORACLE_VERSION=18c
export ORACLE_SID=ORCLCDB
export TEMPLATE_NAME=General_Purpose.dbc
export CHARSET=AL32UTF8
export PDB_NAME=ORCLPDB1
export LISTENER_NAME=LISTENER
export NUMBER_OF_PDBS=
export CREATE_AS_CDB=true # General exports and vars
export PATH=$ORACLE_HOME/bin:$PATH
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
DBCA=$ORACLE_HOME/bin/dbca
ORACLE_OWNER=oracle
RETVAL=
CONFIG_NAME="oracledb_$ORACLE_SID-$ORACLE_VERSION.conf"
CONFIGURATION="/etc/sysconfig/$CONFIG_NAME" # Commands
if [ -z "$SU" ];then SU=/bin/su; fi
if [ -z "$GREP" ]; then GREP=/usr/bin/grep; fi
if [ ! -f "$GREP" ]; then GREP=/bin/grep; fi # To start the DB
start()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq ]
then
echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
exit
fi
# Check if the DB is already started
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ];
then # Unset the proxy env vars before calling sqlplus
unset_proxy_vars echo "Starting Oracle Net Listener."
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR start $LISTENER_NAME" > /dev/null >&
RETVAL=$?
if [ $RETVAL -eq ]
then
echo "Oracle Net Listener started."
fi echo "Starting Oracle Database instance $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
connect / as sysdba
startup
alter pluggable database all open
exit;
EOF" > /dev/null 2>&1
RETVAL1=$?
if [ $RETVAL1 -eq ]
then
echo "Oracle Database instance $ORACLE_SID started."
fi
else
echo "The Oracle Database instance $ORACLE_SID is already started."
exit
fi echo
if [ $RETVAL -eq ] && [ $RETVAL1 -eq ]
then
return
else
echo "Failed to start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
exit
fi
} # To stop the DB
stop()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq ]
then
echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
exit
fi
# Check if the DB is already stopped
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ]
then
echo "Oracle Database instance $ORACLE_SID is already stopped."
exit
else # Unset the proxy env vars before calling sqlplus
unset_proxy_vars echo "Shutting down Oracle Database instance $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
connect / as sysdba
shutdown immediate
exit;
EOF" > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq ]
then
echo "Oracle Database instance $ORACLE_SID shut down."
fi echo "Stopping Oracle Net Listener."
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR stop $LISTENER_NAME" > /dev/null >&
RETVAL1=$?
if [ $RETVAL1 -eq ]
then
echo "Oracle Net Listener stopped."
fi
fi echo
if [ $RETVAL -eq ] && [ $RETVAL1 -eq ]
then
return
else
echo "Failed to stop Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
exit
fi
} # To call DBCA to configure the DB
configure_perform()
{
# Unset the proxy env vars before calling dbca
unset_proxy_vars echo "Configuring Oracle Database $ORACLE_SID." $SU -s /bin/bash $ORACLE_OWNER -c "$DBCA -silent -createDatabase -gdbName $ORACLE_SID -templateName $TEMPLATE_NAME -characterSet $CHARSET -createAsContainerDatabase $CREATE_AS_CDB -numberOfPDBs $NUMBER_OF_PDBS -pdbName $PDB_NAME -createListener $LISTENER_NAME:$LISTENER_PORT -datafileDestination $ORACLE_DATA_LOCATION -sid $ORACLE_SID -autoGeneratePasswords -emConfiguration DBEXPRESS -emExpressPort $EM_EXPRESS_PORT" RETVAL=$? echo
if [ $RETVAL -eq ]
then
echo "Database configuration completed successfully. The passwords were auto generated, you must change them by connecting to the database using 'sqlplus / as sysdba' as the oracle user."
return
else
echo "Database configuration failed."
exit
fi
} # Enh - Unsets the proxy env variables
unset_proxy_vars()
{
if [ "$http_proxy" != "" ]
then
unset http_proxy
fi if [ "$HTTP_PROXY" != "" ]
then
unset HTTP_PROXY
fi if [ "$https_proxy" != "" ]
then
unset https_proxy
fi if [ "$HTTPS_PROXY" != "" ]
then
unset HTTPS_PROXY
fi
} # Check if the DB is already configured
check_for_configuration()
{
configfile=`$GREP --no-messages $ORACLE_SID:$ORACLE_HOME /etc/oratab` > /dev/null >&
if [ "$configfile" = "" ]
then
return
fi
return
} read_config_file()
{
if [ -f "$CONFIGURATION" ]
then
. "$CONFIGURATION"
else
echo "The Oracle Database is not configured. Unable to read the configuration file '$CONFIGURATION'"
exit ;
fi
} # Entry point to configure the DB
configure()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq ]
then
echo "Oracle Database instance $ORACLE_SID is already configured."
exit
fi
read_config_file
check_port_availability
check_em_express_port_availability
configure_perform
} check_port_availability()
{
port=`netstat -n --tcp --listen | $GREP :$LISTENER_PORT`
if [ "$port" != "" ]
then
echo "Port $LISTENER_PORT appears to be in use by another application. Specify a different port in the configuration file '$CONFIGURATION'"
exit ;
fi
} # Validation method to check for port availability for Oracle EM Express
check_em_express_port_availability()
{
port=`netstat -n --tcp --listen | $GREP :$EM_EXPRESS_PORT`
if [ "$port" != "" ]
then
echo "Port $EM_EXPRESS_PORT appears to be in use by another application. Specify a different Oracle EM Express port in the configuration file '$CONFIGURATION'"
exit ;
fi
} restart()
{
# Check if the DB is already stopped
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ]
then
start
else
stop
start
fi
} case "$1" in
start)
start
;;
stop)
stop
;;
configure)
configure
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|configure}"
exit
;;
esac exit

执行脚本

# 执行脚本之后将创建一个容器数据库(ORCLCDB)和一个可插拔数据库(ORCLPDB1),并且配置的默认监听端口是1521。注意 /opt 目录剩余空间大小
/etc/init.d/oracledb_ORCLCDB-18c configure

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

查看 oratab

# 记录每个数据库的信息,最后一个字母为是否在系统启动时启动
cat /etc/oratab

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

三、使用

# 作用与 /etc/profile 一样
vim /etc/profile.d/oracle.sh export ORACLE_BASE=/opt/oracle/oradata
export ORACLE_HOME=/opt/oracle/product/18c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=ORCLCDB
export NLS_LANG=american_america.AL32UTF8 # 刷新环境变量
source /etc/profile.d/oracle.sh

相关命令

# 监听端口查看
netstat -nultp | grep -E '1521|5500' # 监听
lsnrctl start
lsnrctl stop
lsnrctl stat # 数据库
dbstart $ORACLE_HOME
dbshut $ORACLE_HOME

连接到 oracle 数据库

# 切换到 oracle 用户,root 用户下无法连接
su - oracle # 启动监听
lsnrctl start # 以 sysdba 身份登录
sqlplus / as sysdba

修改数据库密码

-- 启动数据库
startup; -- 配置 system 和 sys 账户的密码
alter user system identified by oracle;
alter user sys identified by oracle; -- 版本查询
select banner from sys.v_$version; -- 查看所有用户
select username from dba_users;

查看 em 界面,Oracle 18c 默认会开启 Enterprise Manager Database Express,修改完sys密码之后,就可以访问:https://IP:5500/em,忽略 https 证书错误,允许 Flash 加载

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

远程连接至 Oracle 数据库 (Navicat Premium)

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例

四、添加开机自启动

1.新建环境参数

vim /etc/sysconfig/ORCLCDB.oracledb

ORACLE_BASE=/opt/oracle/oradata
ORACLE_HOME=/opt/oracle/product/18c/dbhome_1
ORACLE_SID=ORCLCDB

2.新建监听服务

vim /usr/lib/systemd/system/ORCLCDB@lsnrctl.service

[Unit]
Description=Oracle Net Listener
After=network.target [Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCLCDB.oracledb
ExecStart=/opt/oracle/product/18c/dbhome_1/bin/lsnrctl start
ExecStop=/opt/oracle/product/18c/dbhome_1/bin/lsnrctl stop
User=oracle [Install]
WantedBy=multi-user.target

3.新建数据库服务

vim /usr/lib/systemd/system/ORCLCDB@oracledb.service

[Unit]
Description=Oracle Database service
After=network.target lsnrctl.service [Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCLCDB.oracledb
ExecStart=/opt/oracle/product/18c/dbhome_1/bin/dbstart $ORACLE_HOME
ExecStop=/opt/oracle/product/18c/dbhome_1/bin/dbshut $ORACLE_HOME
User=oracle [Install]
WantedBy=multi-user.target

4.设置服务自启动

# 刷新服务
systemctl daemon-reload # 设置开机自启动
systemctl enable ORCLCDB@lsnrctl ORCLCDB@oracledb

5.设置数据库自启动

# 此文件由 root.sh 创建
# 格式为:$ORACLE_SID:$ORACLE_HOME:<N|Y>
# 第一个和第二个字段分别是数据库的系统标识符和主目录。 第三个字段为是否跟随 dbstart 命令启动数据库实例
# 不允许有相同 $ORACLE_SID 的条目
vim /etc/oratab ORCLCDB:/opt/oracle/product/18c/dbhome_1:Y

https://docs.oracle.com/en/database/oracle/oracle-database/18/ladbi/running-rpm-packages-to-install-oracle-database.html#GUID-BB7C11E3-D385-4A2F-9EAF-75F4F0AACF02

https://blog.csdn.net/hanzheng260561728/article/details/88202571

https://blog.csdn.net/vkingnew/article/details/83189454

CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例的更多相关文章

  1. Centos7上以RPM包方式安装Oracle 18c XE

    Centos7上以RPM包方式安装Oracle 18c XE 安装阿里云 YUM 源 https://opsx.alibaba.com/mirror?lang=zh-CN 一.安装oracle数据库 ...

  2. CentOS7 图形化方式安装 Oracle 18c 单实例

    下载 Oracle 数据库,zip 包 https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.h ...

  3. MySQL在linux上的rpm包方式安装方法

    1.下载上传mysql server和client rpm包: [root@faspdev mnt]# ls MySQL-client-5.5.53-1.el6.x86_64.rpm MySQL-se ...

  4. RPM包方式安装Oracle21c的方法

    RPM包方式安装Oracle21c的方法 前言 北京时间2021.8.14 Oracle发布了最新的数据库版本Oracle21c, Oracle规划不再发布Oracle20c和Oracle22c, 直 ...

  5. MySQL使用RPM包方式安装

        CentOS7安装MySQL的方法之RPM包方式        

  6. Gitlab环境快速部署(RPM包方式安装)

    之前梳理了一篇Gitlab的安装CI持续集成系统环境---部署Gitlab环境完整记录,但是这是bitnami一键安装的,版本比较老.下面介绍使用rpm包安装Gitlab,下载地址:https://m ...

  7. CentOS 6&period;5 RPM包方式安装 Mysql 5&period;6

    1. 下载MySQL 5.6 下载页面:http://dev.mysql.com/downloads/mysql/此处选择“Red Hat Enterprise Linux 6 / Oracle Li ...

  8. CentOS7 图形化方式安装Oracle 18c 安装配置

    下载 Oracle 数据库,zip 包 https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.h ...

  9. CentOS7下源码包方式安装rabbitmq

    1.先安装erlang http://www.cnblogs.com/justphp/p/6093880.html 2.下载rabbitmq rpm包: wget http://www.rabbitm ...

随机推荐

  1. 【转】Spark性能优化指南——基础篇

    http://mp.weixin.qq.com/s?__biz=MjM5NDMwNjMzNA==&mid=2651805828&idx=1&sn=2f413828d1fdc6a ...

  2. WordPress ”无法发送电子邮件&comma;可能原因&colon;您的主机禁用了mail&lpar;&rpar;函数&OpenCurlyDoubleQuote;的解决办法

    WordPress网站中出现 "无法发送电子邮件,可能原因:您的主机禁用了mail()函数"的情况一般都是因为所在主机环境不支持在线邮件收发功能导致,如果不支持的话,那么像类似 N ...

  3. asp&period;net中使用ueditor

    原文地址:http://blog.uoolo.com/Article/16 还有在MVC中使用ueditor:http://blog.uoolo.com/Article/111 最初百度了一下“编辑器 ...

  4. sql 自身连接

    "select table1.field1, table2.field1 from table table1, table table2 where table1.id=table2.par ...

  5. Android SQLiteDatabase使用总结

    SQLiteDatabase数据库操作 1.创建一个继承了类SQLiteOPenHelper类复写相应的方法,和构造函数 2.然后创建一个类,定义一个私有变量(上述类的实例化对象),在构造函数中进行初 ...

  6. KEIL MDK 查看代码量、RAM使用情况--RO-data、RW-data、ZI-data的解释(转)

    源:KEIL MDK 查看代码量.RAM使用情况--RO-data.RW-data.ZI-data的解释 KEIL RVMDK编译后的信息 Program Size: Code=86496 RO-da ...

  7. &OpenCurlyDoubleQuote;军装照”背后——天天P图如何应对10亿流量的后台承载。

    WeTest 导读 天天P图"军装照"活动交出了一份10亿浏览量的答卷,一时间刷屏朋友圈,看到这幕,是不是特别想复制一个如此成功的H5?不过本文不教你如何做一个爆款H5,而是介绍天 ...

  8. Saliency Detection via Graph-Based Manifold Ranking

    Saliency Detection via Graph-Based Manifold Ranking https://www.yuque.com/lart/papers 本文不是按照之前的论文那样, ...

  9. FastJson 数组、List、Set、Map基本序列化与日期格式化

    摘要: FastJson可以直接序列化数组.List.Set.Map等,也可以直接支持日期类型数据的格式化,包括java.util.Date.java.sql.Date.java.sql.Timest ...

  10. internet连接共享

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_shai nternet连接共享 允许其他网络用户通过此计算机的internet连接来连接