文章目录
1. 简介
本文介绍如何在CentOS7.6上安装Oracle Database 12c Release 2
1.1 环境介绍
- 软件相关
软件 | 版本 | 备注 |
---|---|---|
本地操作系统 | Win10 | ip:192.168.1.1 |
虚拟机操作系统 | CentOS Linux release 7.6.1810 (Core) | ip:192.168.1.14 内存2.8G swap 2G |
Oracle | Oracle Database 12c Release 2 | linux版本 |
MobaXterm | MobaXterm_Personal_12.3 | 用于在本地启动Xserver |
2. 软件下载
2.1 Oracle下载
下载途径 | 地址 |
---|---|
官方下载 | https://www.oracle.com/database/technologies/oracle12c-linux-12201-downloads.html |
百度云盘 | https://pan.baidu.com/s/1zmAxc-qI3GNjOYe4UUF67A |
- 官方下载介绍
浏览其中打开官方下载地址,点击文件名称进行下载,如下图所示
2.2 MobaXterm下载
Oracle安装过程中需要将服务器(192.168.1.14)的图形界面显示到本地(192.168.1.1),本地需要启动Xserver用于显示服务器传过来的图形界面,MobaXterm
提供了简单易用的Xserver启动方式
下载途径 | 地址 |
---|---|
官方下载 | https://mobaxterm.mobatek.net/download-home-edition.html |
百度云盘 | https://pan.baidu.com/s/1r9jpp5IYmxXpKfC71B7Q3Q |
-
官方下载介绍
浏览其中打开官方下载地址,点击左边的
便携包
进行下载,如下图所示
2.3 软件验证
使用oracle用户操作
将下载的oracle安装包linuxx64_12201_database.zip
上传到虚拟机192.168.1.14
的/home/oracle
目录下
# 上传完成后,查看软件包
[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ ll
总用量 3372752
-rw-r--r--. 1 oracle oinstall 3453696911 10月 31 23:28 linuxx64_12201_database.zip
# 验证软件包是否完整
[oracle@localhost ~]$ cksum linuxx64_12201_database.zip
4170261901 3453696911 linuxx64_12201_database.zip
# 返回信息中第一个值为cksum,第二个值为文件大小
# 与从官方下载时,页面上的cksum和bytes进行比较,一致则说明软件包没问题
3. 安装前准备
3.1 依赖包安装
安装oracle依赖的linux软件包,下面的命令不一定全
,不过不用担心
安装oracle的时候有检查,到时候检查出来的单独安装即可
# oracle安装需要
yum install -y compat-libcap1 libstdc++-devel sysstat gcc-c++ ksh libaio-devel smartmontools net-tools
# 解压用
yum install -y unzip
# 显示到本地用
yum install -y xdpyinfo
3.2 内核参数设置
创建文件/etc/sysctl.d/97-oracledatabase-sysctl.conf
vim /etc/sysctl.d/97-oracledatabase-sysctl.conf
97-oracledatabase-sysctl.conf
内容如下
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
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
执行下面命令使配置生效
# 应用配置
/sbin/sysctl --system
# 使用以下命令确认
/sbin/sysctl -a
3.3 用户和组创建
# 创建组oinstall,组id:54321
/usr/sbin/groupadd -g 54321 oinstall
# 查看组
grep oinstall /etc/group
# 用户创建oracle,用户id:54321,属于oinstall组
/usr/sbin/useradd -u 54321 -g oinstall oracle
# 修改oracle用户密码
passwd oracle
# 输入两次密码,我设置的为oracle
3.4 系统资源参数
3.4.1 资源限制配置
安装用户oracle
资源限制官方
建议范围
资源中文描述 | 资源 | Soft Limit | Hard Limit |
---|---|---|---|
文件描述符 | nofile | at least 1024 | at least 65536 |
进程 | nproc | at least 2047 | at least 16384 |
进程堆栈段的大小 | stack | at least 10240 KB | at least 10240 KB, and at most 32768 KB |
使用root操作
# 编辑limits.conf文件
vim /etc/security/limits.conf
# 添加如下内容,对oracle用户资源限制进行配置
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
3.4.2 资源限制检查
使用oracle用户操作
# 检查 soft nofile,soft nproc,soft stack
[oracle@localhost ~]$ ulimit -Sn -Su -Ss
open files (-n) 1024
max user processes (-u) 2047
stack size (kbytes, -s) 10240
# 检查 hard nofile,hard nproc,hard stack
[oracle@localhost ~]$ ulimit -Hn -Hu -Hs
open files (-n) 65536
max user processes (-u) 16384
stack size (kbytes, -s) 32768
3.5 启动Xserver
解压我们下载MobaXterm_Portable_v12.3.zip
,进入解压后文件双击MobaXterm_Personal_12.3.exe
进行启动,启动后界面如下图
依次点击Settings
->X11
,将X11 remote access
改为full
,最后点击OK,如下图所示
点击右上角的Xserver
进行启动
启动后Xserver
图标会出现彩虹颜色
4. 安装
使用oracle
账号登入或者通过su - oracle
切换到oracle账号下,我是通过oracle账号直接
登入操作的,
4.1 解压安装
# 解压
[oracle@localhost ~]$ unzip linuxx64_12201_database.zip
# 设置回显到本地,(此处我win10本地ip为192.168.1.1)
[oracle@localhost ~]$ export DISPLAY=192.168.1.1:0.0
# 设置语言为英文,中文有乱码(也可以自己寻找中文方式,此处使用英文安装)
[oracle@localhost ~]$ export LANG=en_US.UTF-8
# 启动,如果没有什么意外的话,本地会弹出oracle安装图形界面
# 请确保已完成3.1中xdpyinfo包安装
./database/runInstaller
去除I wish ...
勾选状态(不接收安全更新提醒邮件),然后点击next
在弹出的提示框中选择Yes
保持默认(创建并配置一个数据库),点击Next
选择server版本
,点击Next
保持默认的单实例数据库
安装,点击Next
保持默认的标准安装
,点击Next
为所有用户设置默认密码(我设置密码的为oracle),去除Create as Container database
(12C开始提供一个实例多db的支持,此处是用于做测试,不使用此新特性。如果勾选此选项,创建出来的数据库在创建用户时需以c##
开头。),点击Next
在弹出的提示框选择Yes
保持默认,点击Next
如过检查出了Swap没有通过,可以直接忽略掉,点击Next
在弹出的提示框选择Yes
点击Install
开始安装
安装过程中会提示需要用root
执行两个脚本,
另起一个root
账号登入的终端,执行上面两个脚本
# 执行第一个脚本
[root@localhost ~]# /home/oracle/app/oraInventory/orainstRoot.sh
Changing permissions of /home/oracle/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /home/oracle/app/oraInventory to oinstall.
The execution of the script is complete.
# 执行第二个脚本
[root@localhost ~]# /home/oracle/app/oracle/product/12.2.0/dbhome_1/root.sh
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /home/oracle/app/oracle/product/12.2.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
# 保持默认回车
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Do you want to setup Oracle Trace File Analyzer (TFA) now ? yes|[no] :
# 输入yes
yes
Installing Oracle Trace File Analyzer (TFA).
Log File: /home/oracle/app/oracle/product/12.2.0/dbhome_1/install/root_localhost.localdomain_2019-11-01_00-04-37-956550738.log
Finished installing Oracle Trace File Analyzer (TFA)
执行完两个脚本后,点击OK即可
经过十几分钟的安装,最终出现以下界面提示安装成功,然后点击关闭即可
4.2 登入测试
4.2.1 设置环境变量
配置ORACLE_HOME,并将ORACLE_HOME/bin添加到PATH中
oracle用户操作
# 编辑.bash_profile
[oracle@localhost ~]$ vim .bash_profile
在.bash_profile
结尾添加如下配置
ORACLE_HOME=/home/oracle/app/oracle/product/12.2.0/dbhome_1
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export PATH ORACLE_HOME ORACLE_SID
执行下面命令使配置生效
[oracle@localhost ~]$ source .bash_profile
4.2.2 登入
# 用systemy用户登入,如果配置了ORACLE_SID环境变量,最后面的@orcl可以省略
[oracle@localhost ~]$ sqlplus system/oracle@orcl
SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 1 00:30:01 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Fri Nov 01 2019 00:29:10 +08:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
# 查看前四个用户名
SQL> select username from dba_users where rownum<5 ;
USERNAME
--------------------------------------------------------------------------------
SYS
AUDSYS
SYSTEM
SYSBACKUP
启动与关闭
关闭
- 关闭数据库
# 使用sys以sysdba角色登入
[oracle@localhost ~]$ sqlplus sys/oracle@orcl as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 1 22:20:49 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
# 停止数据库
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
# 退出SQL,返回到shell
SQL> quit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
- 关闭监听
[oracle@localhost ~]$ lsnrctl stop
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 01-NOV-2019 22:24:30
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
The command completed successfully
启动
- 配置监听
配置listener.ora,默认安装完成后listener.ora内容如下
# listener.ora Network Configuration File: /home/oracle/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
没有我们安装数据库实例orcl的监听需要添加以下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
添加完成后截图如下
- 启动监听
[oracle@localhost ~]$ lsnrctl start
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 01-NOV-2019 22:31:20
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /home/oracle/app/oracle/product/12.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /home/oracle/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /home/oracle/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 01-NOV-2019 22:31:20
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /home/oracle/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
- 启动数据库
# 使用sys以sysdba角色登入
[oracle@localhost ~]$ sqlplus sys/oracle@orcl as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 1 22:32:18 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
# 启动数据库
SQL> startup
ORACLE instance started.
Total System Global Area 763363328 bytes
Fixed Size 8797440 bytes
Variable Size 620757760 bytes
Database Buffers 125829120 bytes
Redo Buffers 7979008 bytes
Database mounted.
Database opened.
# 退出
SQL> quit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
启动简洁方式
参照CentOS7.6设置Oracle12cRelease2开机启动
参考列表
官方安装文档html版:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/ladbi/index.html
官方安装文档pdf版:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/ladbi/database-installation-guide-linux.pdf
Oracle关闭/启动:https://www.cnblogs.com/muhehe/p/7944887.html