《Linux 下安装Oracle数据库 - Oracle 19C By CentOS 8 》
- 1 说明
- 1.1 前言
- 1.2 资源下载
- 2 安装步骤
- 2.1 上传安装包
- 2.2 下载数据库预安装包
- 2.3 安装数据库预安装包
- 2.4 安装Oracle数据库
- 2.4.1 第一次安装报错
- 2.4.2 解决安装报错
- 第一步:安装libnsl.so.1
- 第二步:删除原来安装的 /opt/oracle/*
- 第三步:卸载已安装的Oracle
- 第四步:重新执行一次安装。
- 2.5 配置环境变量
- 2.5.1 修改centos主机名
- 2.5.2 修改用户参数
- 2.5.3 配置时钟同步
- 2.6 创建数据库
- 3 数据库使用
- 3.1 启动数据库
- 3.2 登录数据库时报错处理
- 3.3 查询数据库
1 说明
1.1 前言
本文是Linux系统命令行模式安装Oracle数据库的学习实验记录,根据真实环境操作进行记录。具备较强的可操作性、可重复性。
本次实验在虚拟机
环境中完成,Oracle数据库通过在Linux命令行方式安装
。
本文主要用实操实验方式探究Linux命令行安装Oracle数据库过程。对虚拟机软件安装、虚拟机下Linux环境搭建不做详细展开。
1.2 资源下载
1、虚拟机软件版本:本文使用VMware Workstation 17 Pro
2、操作系统版本:一键下载
[root@localhost proc]# cat /etc/redhat-release
CentOS Linux release 8.5.2111
3、数据库版本:一键下载
本文使用Oracle 19C,具体版本为
19.3 - Enterprise Edition (also includes Standard Edition 2)
4、预安装包下载:参考2.2章节
5、本文相关资料已上传站内,可通过百度网盘下载全部内容。
点击跳转下载页面:感谢大家支持!
2 安装步骤
2.1 上传安装包
创建目录,通过SecureFX将数据库安装包上传至服务器。
大家如果遇到上传相关问题,可留言咨询。看到必回。
//创建目录
[root@localhost proc]# mkdir -p /oracle/install
//对目录赋权
[root@localhost proc]# chmod -R 777 /oracle/install
--说明:此时可将文件上传至/Oracle/install目录。
遗留问题:虚拟网卡传输速度为何限制为100M?
2.2 下载数据库预安装包
命令:
wget http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
实际操作:
[root@localhost install]# pwd
/oracle/install
[root@localhost install]# ls
oracle-database-ee-19c-1.0-1.x86_64.rpm
[root@localhost install]# wget http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
--2023-06-24 08:45:51-- http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
Resolving yum.oracle.com (yum.oracle.com)... 2a02:26f0:2500:1bd::2a7d, 2a02:26f0:2500:1af::2a7d, 2.18.169.81
Connecting to yum.oracle.com (yum.oracle.com)|2a02:26f0:2500:1bd::2a7d|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm [following]
--2023-06-24 08:45:51-- https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
Connecting to yum.oracle.com (yum.oracle.com)|2a02:26f0:2500:1bd::2a7d|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18204 (18K) [application/x-rpm]
Saving to: ‘oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm’
oracle-database-preinsta 100%[==================================>] 17.78K 106KB/s in 0.2s
2023-06-24 08:45:52 (106 KB/s) - ‘oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm’ saved [18204/18204]
[root@localhost install]# ls
oracle-database-ee-19c-1.0-1.x86_64.rpm oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
2.3 安装数据库预安装包
1、安装命令:
yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
2、第一次安装报错:
[root@localhost install]# yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
CentOS Linux 8 - AppStream 62 B/s | 38 B 00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
3、解决第一次报错,参考:点击跳转。主要操作步骤如下:
//进入yum的repos目录
cd /etc/yum.repos.d/
//修改 centos 文件内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
//生成缓存更新
yum makecache
//运行yum update(该步骤较慢)
yum update -y
//返回安装目录重新执行命令
[root@localhost yum.repos.d]# cd /oracle/install/
[root@localhost install]# ls
oracle-database-ee-19c-1.0-1.x86_64.rpm oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
[root@localhost install]# yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
4、再次执行,出现第二次报错:
[root@localhost install]# yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
Last metadata expiration check: 0:06:14 ago on Sat 24 Jun 2023 08:58:15 AM PDT.
Error:
Problem: conflicting requests
- nothing provides compat-libcap1 needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
- nothing provides compat-libstdc++-33 needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
5、解决第二次报错:参考文章跳转
//尝试忽略,但是安装未成功。
[root@localhost install]# yum install --skip-broken oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
Last metadata expiration check: 0:04:39 ago on Sat 24 Jun 2023 09:08:19 AM PDT.
Dependencies resolved.
Nothing to do.
Complete!
//根据参考文章执行命令
[root@localhost install]# sudo rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
warning: oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
error: Failed dependencies:
compat-libcap1 is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
compat-libstdc++-33 is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
ksh is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
libaio-devel is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
libstdc++-devel is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
sysstat is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
xorg-x11-utils is needed by oracle-database-preinstall-19c-1.0-1.el7.x86_64
//果然如文章所言存在异常,先执行这个,在执行上面步骤
curl -o compat-libcap1-1.10-7.el7.x86_64.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/compat-libcap1-1.10-7.el7.x86_64.rpm
//并没有用。
sudo rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm --force --nodeps
6、解决过程存在问题。参考下面文章解决:点击跳转。将命令进行修改,执行成功。
正确命令如下
:
[root@localhost install]# sudo rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm --force --nodeps
warning: oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oracle-database-preinstall-19c-1.################################# [100%]
7、进行验证,如下为成功:
[root@localhost install]# id oracle
uid=65535(oracle) gid=65535(oinstall) groups=65535(oinstall),65541(racdba),65536(dba),65537(oper),65538(backupdba),65539(dgdba),65540(kmdba)
[root@localhost install]#
2.4 安装Oracle数据库
操作用户: root
操作目录: 安装包目录
大致时长: 5分钟
执行过程会执行进度条,如下:
Installing : oracle-database-ee-19c-1.0-1.x86_64 [======================= ] 1/1
2.4.1 第一次安装报错
1、第一次安装出现报错。操作过程详细:
[root@localhost install]# pwd
/oracle/install
[root@localhost install]# ls
compat-libcap1-1.10-7.el7.x86_64.rpm oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
oracle-database-ee-19c-1.0-1.x86_64.rpm
[root@localhost install]#
[root@localhost install]# yum -y localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm
Last metadata expiration check: 1 day, 23:06:39 ago on Sat 24 Jun 2023 09:08:19 AM PDT.
Dependencies resolved.
====================================================================================================
Package Architecture Version Repository Size
====================================================================================================
Installing:
oracle-database-ee-19c x86_64 1.0-1 @commandline 2.5 G
Transaction Summary
====================================================================================================
Install 1 Package
Total size: 2.5 G
Installed size: 6.9 G
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
ewTransaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64 1/1
Installing : oracle-database-ee-19c-1.0-1.x86_64 1/1
Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64 1/1
Exception java.lang.UnsatisfiedLinkError: /opt/oracle/product/19c/dbhome_1/oui/lib/linux64/liboraInstaller.so: libnsl.so.1: cannot open shared object file: No such file or directory occurred..
java.lang.UnsatisfiedLinkError: /opt/oracle/product/19c/dbhome_1/oui/lib/linux64/liboraInstaller.so: libnsl.so.1: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at oracle.sysman.oii.oiip.osd.unix.OiipuUnixOps.loadNativeLib(OiipuUnixOps.java:388)
at oracle.sysman.oii.oiip.osd.unix.OiipuUnixOps.<clinit>(OiipuUnixOps.java:130)
at oracle.sysman.oii.oiip.oiipg.OiipgEnvironment.getEnv(OiipgEnvironment.java:201)
at oracle.sysman.oii.oiix.OiixIniPair.instantiateEnvVars(OiixIniPair.java:299)
at oracle.sysman.oii.oiix.OiixIniPair.updateValue(OiixIniPair.java:230)
at oracle.sysman.oii.oiix.OiixIniPair.<init>(OiixIniPair.java:148)
at oracle.sysman.oii.oiix.OiixIniFile.readFile(OiixIniFile.java:809)
at oracle.sysman.oii.oiix.OiixIniFile.readIniFile(OiixIniFile.java:978)
at oracle.sysman.oii.oiix.OiixIniFile.getProfileString(OiixIniFile.java:385)
at oracle.sysman.oii.oiix.OiixOraparam.getOraparamProfileString(OiixOraparam.java:338)
at oracle.sysman.oii.oiix.OiixOraparam.getOraparamProfileString(OiixOraparam.java:296)
at oracle.sysman.oii.oiix.OiixOraparam.usePrereqChecker(OiixOraparam.java:416)
at oracle.sysman.oii.oiic.OiicSessionContext.setVariables(OiicSessionContext.java:1325)
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.execute(OiicBaseInventoryApp.java:771)
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.main_helper(OiicBaseInventoryApp.java:690)
at oracle.sysman.oii.oiic.OiicDetachHome.main(OiicDetachHome.java:420)
'DetachHome' failed.
Exception in thread "main" java.lang.NullPointerException
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.main_helper(OiicBaseInventoryApp.java:706)
at oracle.sysman.oii.oiic.OiicDetachHome.main(OiicDetachHome.java:420)
Exception java.lang.NoClassDefFoundError: Could not initialize class oracle.sysman.oii.oiip.osd.unix.OiipuUnixOps occurred..
java.lang.NoClassDefFoundError: Could not initialize class oracle.sysman.oii.oiip.osd.unix.OiipuUnixOps
at oracle.sysman.oii.oiip.oiipg.OiipgEnvironment.getEnv(OiipgEnvironment.java:201)
at oracle.sysman.oii.oiix.OiixIniPair.instantiateEnvVars(OiixIniPair.java:299)
at oracle.sysman.oii.oiix.OiixIniPair.updateValue(OiixIniPair.java:230)
at oracle.sysman.oii.oiix.OiixIniPair.<init>(OiixIniPair.java:148)
at oracle.sysman.oii.oiix.OiixIniFile.readFile(OiixIniFile.java:809)
at oracle.sysman.oii.oiix.OiixIniFile.readIniFile(OiixIniFile.java:978)
at oracle.sysman.oii.oiix.OiixIniFile.getProfileString(OiixIniFile.java:385)
at oracle.sysman.oii.oiix.OiixOraparam.getOraparamProfileString(OiixOraparam.java:338)
at oracle.sysman.oii.oiix.OiixOraparam.getOraparamProfileString(OiixOraparam.java:296)
at oracle.sysman.oii.oiix.OiixOraparam.usePrereqChecker(OiixOraparam.java:416)
at oracle.sysman.oii.oiic.OiicSessionContext.setVariables(OiicSessionContext.java:1325)
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.execute(OiicBaseInventoryApp.java:771)
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.main_helper(OiicBaseInventoryApp.java:690)
at oracle.sysman.oii.oiic.OiicAttachHome.main(OiicAttachHome.java:696)
'AttachHome' failed.
Exception in thread "main" java.lang.NullPointerException
at oracle.sysman.oii.oiic.OiicBaseInventoryApp.main_helper(OiicBaseInventoryApp.java:706)
at oracle.sysman.oii.oiic.OiicAttachHome.main(OiicAttachHome.java:696)
[SEVERE] An error occurred while registering the Oracle home. Verify logs in /var/log/oracle-database-ee-19c/results/oraInstall.log and /opt/oracle/oraInventory for more details and try again.
warning: %post(oracle-database-ee-19c-1.0-1.x86_64) scriptlet failed, exit status 1
Error in POSTIN scriptlet in rpm package oracle-database-ee-19c
Verifying : oracle-database-ee-19c-1.0-1.x86_64 1/1
Installed:
oracle-database-ee-19c-1.0-1.x86_64
Complete!
2.4.2 解决安装报错
2、参考文章解决:点击跳转
第一步:安装libnsl.so.1
第一步:安装libnsl.so.1 ,操作过程如下:
[root@localhost install]# yum -y install /lib64/libnsl.so.1
Last metadata expiration check: 1 day, 23:21:45 ago on Sat 24 Jun 2023 09:08:19 AM PDT.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
libnsl x86_64 2.28-164.el8 baseos 103 k
Transaction Summary
===============================================================================================================================================================================================================
Install 1 Package
Total download size: 103 k
Installed size: 160 k
Downloading Packages:
libnsl-2.28-164.el8.x86_64.rpm 96 kB/s | 103 kB 00:01
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 95 kB/s | 103 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : libnsl-2.28-164.el8.x86_64 1/1
Running scriptlet: libnsl-2.28-164.el8.x86_64 1/1
Verifying : libnsl-2.28-164.el8.x86_64 1/1
Installed:
libnsl-2.28-164.el8.x86_64
Complete!
第二步:删除原来安装的 /opt/oracle/*
[root@localhost install]# cd /opt/oracle/
[root@localhost oracle]# ls -l
total 0
drwxrwx---. 3 oracle oinstall 18 Jun 26 08:20 oraInventory
drwxr-xr-x. 3 oracle oinstall 17 Jun 26 08:15 product
[root@localhost oracle]# rm -rf *
[root@localhost oracle]# ls
[root@localhost oracle]# ^C
第三步:卸载已安装的Oracle
[root@localhost oracle]# yum -y remove oracle-database-ee-19c
---
//中间很多行,此处略。
---
Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64 1/1
Verifying : oracle-database-ee-19c-1.0-1.x86_64 1/1
Removed:
oracle-database-ee-19c-1.0-1.x86_64
Complete
第四步:重新执行一次安装。
[root@localhost install]# yum -y localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm
Last metadata expiration check: 1 day, 23:28:46 ago on Sat 24 Jun 2023 09:08:19 AM PDT.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
oracle-database-ee-19c x86_64 1.0-1 @commandline 2.5 G
Transaction Summary
===============================================================================================================================================================================================================
Install 1 Package
Total size: 2.5 G
Installed size: 6.9 G
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64 1/1
Installing : oracle-database-ee-19c-1.0-1.x86_64 1/1
Running scriptlet: oracle-database-ee-19c-1.0-1.x86_64 1/1
[INFO] Executing post installation scripts...
[INFO] Oracle home installed successfully and ready to be configured.
To configure a sample Oracle Database you can execute the following service configuration script as root: /etc/init.d/oracledb_ORCLCDB-19c configure
Verifying : oracle-database-ee-19c-1.0-1.x86_64 1/1
Installed:
oracle-database-ee-19c-1.0-1.x86_64
Complete!
2.5 配置环境变量
2.5.1 修改centos主机名
类型 | 英文 | 解释 |
---|---|---|
静态 | Static hostname | 内核主机名,是系统在启动时从/etc/hostname自动初始化的主机名。 |
瞬态 | Tansient hostname | 系统运行时临时分配的主机名,例如,通过DHCP或mDNS服务器分配。 |
灵活 | Pretty hostname | 有人叫做“别名”主机名,允许使用自由形式(包括特殊/空白字符)的主机名,以展示给终端用户(如xh01@f5)。 |
说明:“静态”主机名和“瞬态”主机名都遵从作为互联网域名同样的字符限制规则。
//查看主机名
[else@localhost ~]$ hostnamectl status
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: d611b318554e4318b18f552cbc04e60b
Boot ID: bd4118580e4c4248a9186f8a49652f5d
Virtualization: vmware
Operating System: CentOS Linux 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-348.el8.x86_64
Architecture: x86-64
//查看主机名2
[else@localhost ~]$ hostname
oracent
--只查看静态主机名
hosnamectl --static
--只查看瞬态主机名
hostnamectl --transient
-只查看灵活主机名
hostnamectl --pretty
//修改主机名
--临时修改
hostname oracent
--永久修改三个主机名
hostnamectl set-hostname oracent
--手动修改
vim /etc/hostname
参考文章:添加链接描述
2.5.2 修改用户参数
操作用户:Oracle
#注意:配置的是oracle用户的环境变量,因为以后所有操作都是在oracle用户下操作,并不是root用户
#所以下面修改的是oracle/.bash_profile
vim /home/oracle/.bash_profile
#添加如下内容:
export ORACLE_HOSTNAME=oracent --- linux服务器主机名,就是你的主机名,可以利用hostname命令查看
export ORACLE_UNQNAME=ORCLCDB --- 设置成数据库实例名(根据建立的数据库修改)
export ORACLE_SID=ORCLCDB --- 数据库实例名(根据建立的数据库修改,建议就用这个)
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1
export ORACLE_INVENTORY=$ORACLE_BASE/oraInventory
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 --- sqlplus 操作需要用到的编码,要和数据库编码一致
# 下面三个是为了解决sqlplus下方向键和回退键不能使用的问题,必须安装 rlwrap 后面会提到
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias ggsci='rlwrap ggsci'
2.5.3 配置时钟同步
[root@oracent ~]# yum -y install chrony
Last metadata expiration check: 0:06:11 ago on Wed 28 Jun 2023 09:14:48 AM PDT.
Package chrony-4.1-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
//修改时区为东八区,恢复正常。
[root@oracent ~]# timedatectl set-timezone Asia/Shanghai
//配置/etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst
server 0.time1.aliyun.com iburst
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 192.168.3.0/24
//相关命令
systemctl start chronyd --启动
systemctl enable chronyd --开机自启动
systemctl restart chronyd --重启
systemctl enable chronyd --查看状态
chronyc sources --使生效
参考文章:Linux时间同步:chrony
2.6 创建数据库
[root@oracent ~]# /etc/init.d/oracledb_ORCLCDB-19c configure
Configuring Oracle Database ORCLCDB.
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.
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.
3 数据库使用
3.1 启动数据库
第一次启动失败。报错为:
Since ORACLE_HOME is not set, cannot auto-start Oracle Net Listener.
操作如下:
[oracle@oracent ~]$ lsnrctl start
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-JUN-2023 23:25:33
Copyright (c) 1991, 2019, Oracle. All rights reserved.
TNS-01106: Listener using listener name LISTENER has already been started
[oracle@oracent ~]$ dbstart
Since ORACLE_HOME is not set, cannot auto-start Oracle Net Listener.
Usage: /opt/oracle/product/19c/dbhome_1/bin/dbstart ORACLE_HOME
解决方法,修改环境变量:
//分别修改以下两个文件
[oracle@oracent bin]$ vim $ORACLE_HOME/bin/dbstart
[oracle@oracent bin]$ vim $ORACLE_HOME/bin/dbshut
//修改如下段落
--将ORACLE_HOME=$1 修改为 ORACLE_HOME=$ORACLE_HOME
--将ORACLE_HOME_LISTNER=$1 修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME
# This is to bring down Oracle Net Listener
ORACLE_HOME_LISTNER=$ORACLE_HOME
if [ ! $ORACLE_HOME_LISTNER ] ; then
echo "Since ORACLE_HOME is not set, cannot auto-stop Oracle Net Listener"
echo "Usage: $0 ORACLE_HOME"
else
# Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
# a different ORACLE_HOME for each entry in the oratab.
ORACLE_HOME=$ORACLE_HOME; export ORACLE_HOME
//保存后再次启动,不再报错。
[oracle@oracent bin]$ dbstart
[oracle@oracent bin]$
3.2 登录数据库时报错处理
第一次连接数据库报错,如下:
[oracle@oracent bin]$ sqlplus / as sysdba
bash: rlwrap: command not found...
资源下载:rlwrap-0.46.1.tar.gz
//上传文件后解压
[root@oracent rlwrap-0.46.1]# tar -xvzf rlwrap-0.46.1.tar.gz
[root@oracent oracle]# ls -l
total 340
drwxrwxr-x. 8 else else 4096 Jun 29 23:55 rlwrap-0.46.1
-rw-rw-r--. 1 else else 340033 Jun 29 23:49 rlwrap-0.46.1.tar.gz
//进入目录,进行安装
[root@oracent oracle]# cd rlwrap-0.46.1
[root@oracent oracle]# ./configure
//第一次安装报错:
configure: error:
You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build
// 安装依赖
[root@oracent oracle]#
[root@oracent oracle]# yum install readline-devel
Last metadata expiration check: 0:08:57 ago on Thu 29 Jun 2023 11:48:43 PM CST.
Dependencies resolved.
====================================================================================================
Package Architecture Version Repository Size
====================================================================================================
Installing:
readline-devel x86_64 7.0-10.el8 baseos 204 k
Installing dependencies:
ncurses-c++-libs x86_64 6.1-9.20180224.el8 baseos 58 k
ncurses-devel x86_64 6.1-9.20180224.el8 baseos 528 k
Transaction Summary
====================================================================================================
Install 3 Packages
Total download size: 790 k
Installed size: 1.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): ncurses-c++-libs-6.1-9.20180224.el8.x86_64.rpm 34 kB/s | 58 kB 00:01
(2/3): readline-devel-7.0-10.el8.x86_64.rpm 111 kB/s | 204 kB 00:01
(3/3): ncurses-devel-6.1-9.20180224.el8.x86_64.rpm 270 kB/s | 528 kB 00:01
----------------------------------------------------------------------------------------------------
Total 402 kB/s | 790 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ncurses-c++-libs-6.1-9.20180224.el8.x86_64 1/3
Installing : ncurses-devel-6.1-9.20180224.el8.x86_64 2/3
Installing : readline-devel-7.0-10.el8.x86_64 3/3
Running scriptlet: readline-devel-7.0-10.el8.x86_64 3/3
Verifying : ncurses-c++-libs-6.1-9.20180224.el8.x86_64 1/3
Verifying : ncurses-devel-6.1-9.20180224.el8.x86_64 2/3
Verifying : readline-devel-7.0-10.el8.x86_64 3/3
Installed:
ncurses-c++-libs-6.1-9.20180224.el8.x86_64 ncurses-devel-6.1-9.20180224.el8.x86_64
readline-devel-7.0-10.el8.x86_64
Complete!
编译安装
[root@oracent rlwrap-0.46.1]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make sets $(MAKE)... (cached) yes
checking whether build environment is sane... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for wchar.h... yes
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking how to run the C preprocessor... gcc -E
checking for perl... /usr/bin/perl
checking for strip... strip
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for errno.h... yes
checking for fcntl.h... yes
checking for libgen.h... yes
checking for libutil.h... no
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for sched.h... yes
checking for sys/file.h... yes
checking for sys/ioctl.h... yes
checking for sys/wait.h... (cached) yes
checking for sys/resource.h... yes
checking for stddef.h... yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking for stdint.h... (cached) yes
checking for time.h... yes
checking for sys/time.h... yes
checking for getopt.h... yes
checking for regex.h... yes
checking for curses.h... yes
checking for stropts.h... no
checking for termcap.h... yes
checking for util.h... no
checking for term.h... yes
checking for ncurses/term.h... yes
checking for gcc options needed to detect all undeclared functions... none needed
checking whether PROC_PIDVNODEPATHINFO is declared... no
checking whether procstat_open_sysctl is declared... no
checking whether procstat_getprocs is declared... no
checking whether procstat_getfiles is declared... no
checking whether STAILQ_FOREACH is declared... no
checking argument type of tputs putc function... int
checking for an ANSI C-conforming const... yes
checking for pid_t... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking whether gcc needs -traditional... no
checking for getopt_long... yes
checking for basename... yes
checking for dirname... yes
checking for flock... yes
checking for getopt_long... (cached) yes
checking for isastream... yes
checking for mkstemps... yes
checking for pselect... yes
checking for putenv... yes
checking for readlink... yes
checking for sched_yield... yes
checking for setenv... yes
checking for setitimer... yes
checking for setsid... yes
checking for setrlimit... yes
checking for sigaction... yes
checking for snprintf... yes
checking for strlcpy... no
checking for strlcat... no
checking for strnlen... yes
checking for system... yes
checking for openpty in -lutil... yes
checking for openpty... yes
checking for getpty... no
checking for grantpt... yes
checking for unlockpt... yes
checking for getpt...
checking for pty/tty type... checking for pty.h... yes
OPENPTY
configure: checking for pty ranges
checking for tgetent... no
checking for tgetent in -ltinfo... yes
checking for readline in -lreadline... yes
checking for tigetnum... yes
checking for readline/readline.h... yes
checking whether your readline headers and library know about rl_set_screen_size... yes
checking whether your readline headers and library know about rl_basic_quote_characters... yes
checking whether your readline headers and library know about rl_variable_value... yes
checking whether your readline headers and library know about rl_readline_version... yes
checking whether your readline headers and library know about rl_executing_keyseq... yes
checking whether the private symbol _rl_horizontal_scroll_mode is visble in your readline libs... yes
Will rlwrap find command's working directory under /proc/<commands pid>/cwd? let's see...
checking for /proc/13315/cwd/configure.ac... yes
checking whether we can find command line under <opt_proc_mountpoint>/<pid>/cmdline and mirror it by overwriting our own *argv (this may take a few secs)... yes
checking that generated files are newer than configure... done
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating filters/Makefile
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating doc/rlwrap.man
config.status: creating config.h
config.status: executing depfiles commands
Now do:
make (or gmake) to build rlwrap
make check for instructions how to test it
make install to install it
[root@oracent rlwrap-0.46.1]# make
make all-recursive
make[1]: Entering directory '/home/oracle/rlwrap-0.46.1'
Making all in doc
make[2]: Entering directory '/home/oracle/rlwrap-0.46.1/doc'
sed -e 's#@DATADIR@#/usr/local/share#' rlwrap.man > rlwrap.1
make[2]: Leaving directory '/home/oracle/rlwrap-0.46.1/doc'
Making all in src
make[2]: Entering directory '/home/oracle/rlwrap-0.46.1/src'
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT signals.o -MD -MP -MF .deps/signals.Tpo -c -o signals.o signals.c
mv -f .deps/signals.Tpo .deps/signals.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT readline.o -MD -MP -MF .deps/readline.Tpo -c -o readline.o readline.c
mv -f .deps/readline.Tpo .deps/readline.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT pty.o -MD -MP -MF .deps/pty.Tpo -c -o pty.o pty.c
mv -f .deps/pty.Tpo .deps/pty.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT completion.o -MD -MP -MF .deps/completion.Tpo -c -o completion.o completion.c
mv -f .deps/completion.Tpo .deps/completion.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT term.o -MD -MP -MF .deps/term.Tpo -c -o term.o term.c
mv -f .deps/term.Tpo .deps/term.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT ptytty.o -MD -MP -MF .deps/ptytty.Tpo -c -o ptytty.o ptytty.c
ptytty.c: In function ‘ptytty_control_tty’:
ptytty.c:257:9: warning: implicit declaration of function ‘isastream’; did you mean ‘system’? [-Wimplicit-function-declaration]
if (isastream(fd_tty) == 1) {
^~~~~~~~~
system
mv -f .deps/ptytty.Tpo .deps/ptytty.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT utils.o -MD -MP -MF .deps/utils.Tpo -c -o utils.o utils.c
mv -f .deps/utils.Tpo .deps/utils.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT string_utils.o -MD -MP -MF .deps/string_utils.Tpo -c -o string_utils.o string_utils.c
mv -f .deps/string_utils.Tpo .deps/string_utils.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT malloc_debug.o -MD -MP -MF .deps/malloc_debug.Tpo -c -o malloc_debug.o malloc_debug.c
mv -f .deps/malloc_debug.Tpo .deps/malloc_debug.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT multibyte.o -MD -MP -MF .deps/multibyte.Tpo -c -o multibyte.o multibyte.c
mv -f .deps/multibyte.Tpo .deps/multibyte.Po
gcc -DHAVE_CONFIG_H -I. -I.. -DDATADIR=\"/usr/local/share\" -g -O2 -MT filter.o -MD -MP -MF .deps/filter.Tpo -c -o filter.o filter.c
mv -f .deps/filter.Tpo .deps/filter.Po
gcc -DDATADIR=\"/usr/local/share\" -g -O2 -o rlwrap main.o signals.o readline.o pty.o completion.o term.o ptytty.o utils.o string_utils.o malloc_debug.o multibyte.o filter.o -lutil -lreadline -ltinfo
make[2]: Leaving directory '/home/oracle/rlwrap-0.46.1/src'
Making all in filters
make[2]: Entering directory '/home/oracle/rlwrap-0.46.1/filters'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/oracle/rlwrap-0.46.1/filters'
make[2]: Entering directory '/home/oracle/rlwrap-0.46.1'
make[2]: Leaving directory '/home/oracle/rlwrap-0.46.1'
make[1]: Leaving directory '/home/oracle/rlwrap-0.46.1'
该报错,退出重连可能就好了。
3.3 查询数据库
[oracle@oracent ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jul 3 00:10:50 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> SQL> select count(1) from v$database ;
COUNT(1)
----------
1
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@oracent ~]$