Centos7上以RPM包方式安装Oracle 18c XE
安装阿里云 YUM 源
https://opsx.alibaba.com/mirror?lang=zh-CN
一、安装oracle数据库
- 安装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
- 安装Oracle Database RPM
yum localinstall -y oracle-database-xe-18c-1.0-1.x86_64.rpm
二、创建和配置Oracle数据库
1.查看配置
#根据需要修改
cat /etc/sysconfig/oracle-xe-18c.conf
[root@localhost sysconfig]# cat oracle-xe-18c.conf
#This is a configuration file to setup the Oracle Database.
#It is used when running '/etc/init.d/oracle-xe-18c configure'.
# LISTENER PORT used Database listener, Leave empty for automatic port assignment
LISTENER_PORT=1521
# EM_EXPRESS_PORT Oracle EM Express URL port
EM_EXPRESS_PORT=5500
# Character set of the database
CHARSET=AL32UTF8
# Database file directory
# If not specified, database files are stored under Oracle base/oradata
DBFILE_DEST=
# SKIP Validations, memory, space
SKIP_VALIDATIONS=false
2.创建Oracle数据库实例
执行脚本
/etc/init.d/oracle-xe-18c configure
# 执行脚本之后将创建一个容器数据库(ROOTCDB)和一个可插拔数据库(XEPDB1),并且配置的默认监听端口是1521。
注意: /opt 目录剩余空间大小
[root@localhost home]# /etc/init.d/oracle-xe-18c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
Confirm the password:
Configuring Oracle Listener.
Listener configuration succeeded.
Configuring Oracle Database XE.
Enter SYS user password:
**********
Enter SYSTEM user password:
**********
Enter PDBADMIN User Password:
**********
Prepare for db operation
7% complete
Copying database files
29% complete
Creating and starting Oracle instance
30% complete
31% complete
34% complete
38% complete
41% complete
43% complete
Completing Database Creation
47% complete
50% complete
Creating Pluggable Databases
54% complete
71% complete
Executing Post Configuration Actions
93% complete
Running Custom Scripts
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/XE.
Database Information:
Global Database Name:XE
System Identifier(SID):XE
Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.
Connect to Oracle Database using one of the connect strings:
Pluggable database: localhost.localdomain/XEPDB1
Multitenant container database: localhost.localdomain
Use https://localhost:5500/em to access Oracle Enterprise Manager for Oracle Database XE
[root@localhost home]# echo $?
0
三、使用
#作用于/etc/profile 一样
vi /etc/profile.d/oracle.sh
#!/bin/bash
export ORACLE_SID=XE
export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
export ORACLE_BASE=/opt/oracle
export PATH=$PATH:/opt/oracle/product/18c/dbhomeXE/bin
#刷新环境变量
source /etc/profile.d/oracle.sh
相关命令
#监听端口查看
netstat -tunlp | 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 abc123456;
alter user sys identified by abc123456;
-- 版本查询
select banner from sys.v_$version;
-- 查看所有用户
select username from dba_users;
开放防火墙端口
firewall-cmd --permanent --add-port=1521/tcp
firewall-cmd --reload
firewall-cmd --list-ports
四、添加开机自启动
1.新建环境参数
vi /etc/sysconfig/XE.oracledb
ORACLE_BASE=/opt/oracle/oradata
ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
ORACLE_SID=XE
2.新建监听服务
vi /usr/lib/systemd/system/XE@lsnrctl.service
[Unit]
Description=Oracle Net Listener
After=network.target
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/XE.oracledb
ExecStart=/opt/oracle/product/18c/dbhomeXE/bin/lsnrctl start
ExecStop=/opt/oracle/product/18c/dbhomeXE/bin/lsnrctl stop
User=oracle
[Install]
WantedBy=multi-user.target
3.新建数据库服务
vi /usr/lib/systemd/system/XE@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/dbhomeXE/bin/dbstart $ORACLE_HOME
ExecStop=/opt/oracle/product/18c/dbhomeXE/bin/dbshut $ORACLE_HOME
User=oracle
[Install]
WantedBy=multi-user.target
4.设置服务自启动
# 刷新服务
systemctl daemon-reload
# 设置开机自启动
systemctl enable XE@lsnrctl XE@oracledb
5.设置数据库自启动
# 此文件由 root.sh 创建
# 格式为:$ORACLE_SID:$ORACLE_HOME:<N|Y>
# 第一个和第二个字段分别是数据库的系统标识符和主目录。
第三个字段为是否跟随 dbstart 命令启动数据库实例
# 不允许有相同 $ORACLE_SID 的条目
vi /etc/oratab
XE:/opt/oracle/product/18c/dbhomeXE:Y