centos7安装oracle数据库

环境

1
2
[root@iZwz9cn4n7x5qttry9g2ggZ ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

oracle19c 最低配置要求

参数 最低要求
Oracle database 内存要求 至少1 GB,建议2 GB以上
Oracle Grid 内存要求 8 GB以上
Swap 要求 Between 1 GB and 2 GB: 1.5 times the size of the RAM
Swap 要求 Between 2 GB and 16 GB: Equal to the size of the RAM
Swap 要求 More than 16 GB: 16 GB
Linux x86_64系统版本要求 OEL \ RHL 7.4 以上
单机DB硬盘最低要求 至少7.2 GB
RAC DB 硬盘最低要求 至少14 GB

yum 方式安装

准备

  • 更新 yum (非必须)
1
yum update
  • 下载 oracle-database-preinstall
1
2
wget http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm
# 可在 http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/ 搜索 oracle-database-preinstall 选择性下载
  • 下载 oracle-database-ee-19c-1.0-1.x86_64.rpm
1
2
3
wget https://download.oracle.com/otn/linux/oracle19c/190000/oracle-database-ee-19c-1.0-1.x86_64.rpm
# 官网 https://www.oracle.com/cn/database/technologies/oracle-database-software-downloads.html#19c
# 点击下载 rpm 后 弹出框 连接另存为(可复制连接)

结果

1
2
3
4
5
[root@iZwz9cn4n7x5qttry9g2ggZ src]# ll
total 32
-rw-r--r-- 1 root root 4017 May 3 13:04 oracle-database-ee-19c-1.0-1.x86_64.rpm
-rw-r--r-- 1 root root 27152 Apr 1 13:47 oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm

安装

步骤1:安装oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm

1
2
yum install oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm
# 遇到提示 按 y

步骤2:安装oracle-database-ee-19c-1.0-1.x86_64.rpm

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
[root@iZwz9cn4n7x5qttry9g2ggZ src]# yum install oracle-database-ee-19c-1.0-1.x86_64.rpm 
Loaded plugins: fastestmirror
Cannot open: oracle-database-ee-19c-1.0-1.x86_64.rpm. Skipping.
Error: Nothing to do
### 报错了。想来应该是文件没下好,比较文件大小就知道了。官网的有 2.5G。
### 我猜应该是。我直接通过复制的连接下载,身份验证的问题

## 于是 打开浏览器调试模式。在点击下载 rpm 包时观察浏览器的 请求。最终获得的下载地址为:
# https://download.oracle.com/otn/linux/oracle19c/190000/oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369
# 很明显 后面多了 AuthParam 参数。

### 再次下载

[root@iZwz9cn4n7x5qttry9g2ggZ src]# wget https://download.oracle.com/otn/linux/oracle19c/190000/oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369
--2021-05-03 13:28:32-- https://download.oracle.com/otn/linux/oracle19c/190000/oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369
Resolving download.oracle.com (download.oracle.com)... 23.220.240.82
Connecting to download.oracle.com (download.oracle.com)|23.220.240.82|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2694664264 (2.5G) [application/x-redhat-package-manager]
Saving to: ‘oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369’

46% [======================================================> ] 1,254,098,351 6.47MB/s eta 3m 43s

Saving to: ‘oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369’

69% [==================================================================================> ] 1,880,335,791 6.44MB/s eta 2m 5s ^69% [==================================================================================> ] 1,884,276,143 6.31MB/s eta 2m 4s ^70% [==================================================================================> ] 1,887,569,327 6.19MB/s eta 2m 3s ^70% [==================================================================================> ] 1,892,005,557 4.68MB/s eta 2m 3s ^70% [==================================================================================> ] 1,894,856,237 4.72MB/s eta 2m 3s ^87% [======================================================================================================> ] 2,344,617,391 7.01MB/s eta 54s ^87% [======================================================================================================> ] 2,347,775,669 7.02MB/s eta 53s ^87% [=======================================================================================================> ] 2,359,924,405 7.08MB/s eta 52s
100%[======================================================================================================================>] 2,694,664,264 6.87MB/s in 6m 50s

2021-05-03 13:35:24 (6.26 MB/s) - ‘oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369’ saved [2694664264/2694664264]

[root@iZwz9cn4n7x5qttry9g2ggZ src]#
### 把 oracle-database-ee-19c-1.0-1.x86_64.rpm?AuthParam=1620019716_a0345bc3ba9ee07b0471db9425796369
### 改名为 oracle-database-ee-19c-1.0-1.x86_64.rpm
[root@iZwz9cn4n7x5qttry9g2ggZ src]# mv oracle-database-ee-19c-1.0-1.x86_64.rpm\?AuthParam\=1620019716_a0345bc3ba9ee07b0471db9425796369 oracle-database-ee-19c-1.0-1.x86_64.rpm
[root@iZwz9cn4n7x5qttry9g2ggZ src]# ll
total 2631544
-rw-r--r-- 1 root root 2694664264 Apr 24 2019 oracle-database-ee-19c-1.0-1.x86_64.rpm
-rw-r--r-- 1 root root 27152 Apr 1 13:47 oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm

### 再次执行 安装
[root@iZwz9cn4n7x5qttry9g2ggZ src]# yum install oracle-database-ee-19c-1.0-1.x86_64.rpm

### 提示如下:安装完成

Dependencies Resolved

==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
oracle-database-ee-19c x86_64 1.0-1 /oracle-database-ee-19c-1.0-1.x86_64 6.9 G

Transaction Summary
==================================================================================================================================================================
Install 1 Package

Total size: 6.9 G
Installed size: 6.9 G
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 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.x86_64 0:1.0-1

Complete!
[root@iZwz9cn4n7x5qttry9g2ggZ src]#


配置环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vim /etc/init.d/oracledb_ORCLCDB-19c 

### 设置环境变量
# Setting the required environment variables

export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1

export ORACLE_VERSION=19c
# /etc/sysconfig/oracledb_ORCLCDB-19c.conf 文件名 ORCLCDB 部分与这里的 SID 需同步
#即 如果 export ORACLE_SID=ORC19C
#那么 /etc/sysconfig/ 下需要有 oracledb_ORC19C-19c.conf 文件(重命名即可)
export ORACLE_SID=ORCLCDB
export TEMPLATE_NAME=General_Purpose.dbc
#这里根据情况设定不同的字符集
export CHARSET=AL32UTF8
#export CHARSET=ZHS16GBK
#export CHARSET=UTF8
export PDB_NAME=ORCLPDB1
export LISTENER_NAME=LISTENER
export NUMBER_OF_PDBS=1
export CREATE_AS_CDB=true

文件修改后 执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 /etc/init.d/oracledb_ORCLCDB-19c configure
# 时间较长 耐心等待。。。
......
# 安装完成
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.
[root@iZwz9cn4n7x5qttry9g2ggZ ~]#

修改 oracle 用户密码

1
2
3
4
5
6
7
8
[root@iZwz9cn4n7x5qttry9g2ggZ ~]# passwd oracle
Changing password for user oracle.
New password: (1qaz!QAZ)
BAD PASSWORD: The password fails the dictionary check - it is based on a (reversed) dictionary word
Retype new password: (1qaz!QAZ)
passwd: all authentication tokens updated successfully.
[root@iZwz9cn4n7x5qttry9g2ggZ ~]#

登录

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@iZwz9cn4n7x5qttry9g2ggZ ~]# su - oracle
Last login: Mon May 3 16:53:04 CST 2021 on pts/0
[oracle@iZwz9cn4n7x5qttry9g2ggZ ~]$ sqlplus / as sysdba
-bash: sqlplus: command not found
[oracle@iZwz9cn4n7x5qttry9g2ggZ ~]$

#通过百度 解决办法。新建文件 添加如下内容并保存

[root@iZwz9cn4n7x5qttry9g2ggZ ~]# vim /etc/profile.d/oracle19c.sh
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin
export ORACLE_SID=ORCLCDB

# 使文件生效
source /etc/profile
# 检查是否生效
[root@iZwz9cn4n7x5qttry9g2ggZ ~]# echo $ORACLE_SID
ORCLCDB

######################
#再次登录
[root@iZwz9cn4n7x5qttry9g2ggZ ~]# su - oracle
Last login: Mon May 3 16:53:57 CST 2021 on pts/0
[oracle@iZwz9cn4n7x5qttry9g2ggZ root]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Mon May 3 18:58:14 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle. All rights reserved.

Connected to an idle instance.

#启动实例
SQL> startup;
ORACLE instance started.

Total System Global Area 738194408 bytes
Fixed Size 9139176 bytes
Variable Size 478150656 bytes
Database Buffers 247463936 bytes
Redo Buffers 3440640 bytes
Database mounted.
Database opened.
SQL>
#修改密码
SQL> password system
Changing password for system
New password:
Retype new password:
Password changed
#登录
SQL> conn system/123456
Connected.
SQL> show user
USER is "SYSTEM"
SQL>

### 另开窗口:进入 ${ORACLE_HOME}/bin 下
### su oracle
### 执行:
[oracle@iZwz9cn4n7x5qttry9g2ggZ bin]$ lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 03-MAY-2021 19:17:13

Copyright (c) 1991, 2019, Oracle. All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/iZwz9cn4n7x5qttry9g2ggZ/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=iZwz9cn4n7x5qttry9g2ggZ)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=iZwz9cn4n7x5qttry9g2ggZ)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 03-MAY-2021 19:17:15
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/iZwz9cn4n7x5qttry9g2ggZ/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=iZwz9cn4n7x5qttry9g2ggZ)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[oracle@iZwz9cn4n7x5qttry9g2ggZ bin]$


修改数据库登录密码

  • 查看已启用的用户
1
2
3
4
5
6
SQL> select username from dba_users where account_status='OPEN';

USERNAME
--------------------------------------------------------------------------------
SYS
SYSTEM
  • 修改密码
1
2
3
4
5
6
7
8
9
10
#修改密码
SQL> password system
Changing password for system
New password:
Retype new password:
Password changed

#或者
alter user sys identified by [密码]
alter user SYSTEM identified by [密码]
  • 解锁用户
1
2
#若用新建用户登录时遇到ORA-01017则需要对用户进行解锁操作
ALTER USER username ACCOUNT UNLOCK;
  • 配置对应的 oci.dll

工具->选项->环境 oci 环境。这里的 oci.dll 版本一定要用对,不能低于与之对应的服务端版本。

oci.dll 可从 oracle instant client 中找到。

oracle instant client 官网下载地址:https://www.oracle.com/database/technologies/instant-client/downloads.html

image-20210503225802505

  • 连接参数

服务名根据自己的情况填写(我安装的时候就是ORCLCDB)

或者启动后在监听文件中可看到

文件:/opt/oracle/product/19c/dbhome_1/network/admin/listener.ora

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dbname)
(ORACLE_HOME = /opt/oracle/product/19c/dbhome_1)
(SID_NAME = dbname)
)

(SID_DESC =
(GLOBAL_DBNAME = ORCLCDB)
(ORACLE_HOME = /opt/oracle/product/19c/dbhome_1)
(SID_NAME = ORCLCDB)
)

)


image-20210503230348872

提示:如果一直用 navicat 连不上,可通过 idea 尝试连接。另外 navicat 重新配置 oci.dll 后一定要重启。

设置开机启动

  1. vim /etc/oratab
1
2
#将 N 改为 Y
ORA19C:/opt/oracle/product/19c/dbhome_1:Y
  1. vim /usr/bin/oracle.sh
1
2
3
4
#! /bin/bash
# script For oracle19c.service
/opt/oracle/product/19c/dbhome_1/bin/lsnrctl start
/opt/oracle/product/19c/dbhome_1/bin/dbstart /opt/oracle/product/19c/dbhome_1

chmod 777 /usr/bin/oracle.sh

  1. vim /etc/systemd/system/oracle-19c.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Oracle19c
After=syslog.target network.target

[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
Type=oneshot
RemainAfterExit=yes
User=oracle
Environment="ORACLE_HOME=/opt/oracle/product/19c/dbhome_1"
ExecStart=/usr/bin/oracle.sh

[Install]
WantedBy=multi-user.target
  1. 开启服务
1
systemctl enable oracle-19c
  1. 测试
    1. reboot

    2. systemctl status oracle-19c

    3. 本地连接 出错

      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
      su - oracle

      sqlplus / as sysdba
      shutdown abort
      # startup mount
      SQL> startup;
      ORA-01078: failure in processing system parameters
      LRM-00109: could not open parameter file '/opt/oracle/product/19c/dbhome_1/dbs/initORCLCDB.ora'

      [root@iZwz9cn4n7x5qttry9g2ggZ pfile]# pwd
      /opt/oracle/admin/ORCLCDB/pfile
      [root@iZwz9cn4n7x5qttry9g2ggZ pfile]# cp init.ora /opt/oracle/product/19c/dbhome_1/dbs/initORCLCDB.ora

      [root@iZwz9cn4n7x5qttry9g2ggZ dbs]# pwd
      /opt/oracle/product/19c/dbhome_1/dbs
      [root@iZwz9cn4n7x5qttry9g2ggZ dbs]# chown -R oracle:oinstall initORCLCDB.ora
      #再次启动
      SQL> startup;
      ORACLE instance started.

      Total System Global Area 738194408 bytes
      Fixed Size 9139176 bytes
      Variable Size 478150656 bytes
      Database Buffers 247463936 bytes
      Redo Buffers 3440640 bytes
      Database mounted.
      Database opened.

    4. 本地连接成功!


其它

linux 增加 exfat 磁盘驱动

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo yum install epel-release

# sudo rpm -v --import htytp://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
# sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
sudo yum -y install exfat-utils fuse-exfat


#
1.Install the nux repo for CentOS 7
yum install -y http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

2、yum install exfat-utils fuse-exfat
安装这两个包

参考

https://www.cnblogs.com/YC-L/p/14602415.html

https://www.cnblogs.com/jinanxiaolaohu/p/10799101.html

https://blog.csdn.net/wanghailong_qd/article/details/85887825

https://www.jianshu.com/p/24dc1f390e13

https://blog.csdn.net/guchuanlong/article/details/7299079