安装前的准备
1. Download software pakage
链接: 百度网盘 请输入提取码 提取码: sexh
2. 然后上传到服务器。
用yum安装准备环境配置:
step1: 在安装之前,建议先更新yum源: yum update -y --nogpgcheck
[root@MaxwellDBA home]# yum update -y --nogpgcheck
Install required packages.
dnf -y install binutils gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libgcc.i686 libstdc++ libstdc++-devel libXi libXtst libnsl make sysstat
step2: 安装orale准备环境: yum localinstall oracle-database-preinstall-19c-1.0-1.el8.x86_64.rpm 安装完之后,会自动创建一个用户名是 oracle的dba账号,检查一下有没有安装成功,例如查看一下有没有oracle用户
[root@MaxwellDBA home]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54330(racdba),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba)
[root@MaxwellDBA home]#
Step3 : 因为默认云服务器默认主机名都是一大串数字并不好操作,建议修改一下服务器主机名: vim /etc/hostname 我这里改成 MaxwellDBA(下面会用到该主机名) 同时在 vim /etc/hosts 文件中加上自己的主机名,上面第一个红色框是我云服务器的ip地址。
安装oracle数据库
yum localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm 安静等待安装完成就行了,大概10分钟,软件路径在/opt 下生成一个oracle文件夹,虽然用的root账号安装,但是装完之后用户属于oracle
[root@MaxwellDBA home]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54330(racdba),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba)
[root@MaxwellDBA home]# yum localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm
Repository extras is listed more than once in the configuration
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Last metadata expiration check: 0:22:09 ago on Wed 29 Jun 2022 04:39:05 AM CST.
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
Is this ok [y/N]: Y
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!
[root@MaxwellDBA home]#
三、配置环境变量
注意:配置的是oracle用户的环境变量,因为以后所有操作都是在oracle用户下操作,并不是root用户
[root@MaxwellDBA home]# vim /home/oracle/.bash_profile
export ORACLE_HOSTNAME=master-kww --- linux服务器主机名
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'
四、创建数据库
安装数据库一般有两种方式,图形界面安装(使用dbca)或者静默安装,图形界面安装是不可能了,只能静默安装。 静默安装可以通过 /opt/oracle/product/19c/dbhome_1/assistants/dbca/dbca.rsp
配置安装,也可以用19c提供的 默认配置创建,下面介绍用默认配置的方式创建。 在root用户下运行: /etc/init.d/oracledb_ORCLCDB-19c configure
--- 会创建一个实例名为ORCLCDB的容器数据库( 所以上面第三步配置项用ORCLCDB做实例名),还有有一个ORCLPDB1的可插拔数据库。
[root@MaxwellDBA ~]# cd /etc/init.d
[root@MaxwellDBA init.d]# ls
functions oracle-database-preinstall-19c-firstboot oracledb_ORCLCDB-19c README
[root@MaxwellDBA 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/ORCLCDB1.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@MaxwellDBA init.d]#
[oracle@MaxwellDBA ~]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-JUN-2022 05:54:22
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MaxwellDBA)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 29-JUN-2022 05:28:17
Uptime 0 days 0 hr. 26 min. 5 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/MaxwellDBA/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=MaxwellDBA)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=MaxwellDBA)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORCLCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORCLCDB" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "ORCLCDBXDB" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "e28a0ec2d1cca96de053b1051aac3df7" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "orclpdb1" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@MaxwellDBA ~]$
五、centos8安装注意事项:
1、安装完之后,命令窗口sqlplus输入方向键和回退键会变成乱码,需要安装 rlwrap-0.43-5.el8.x86_64.rpm (在上面的网盘里有此文件) 命令: yum localinstall rlwrap-0.43-5.el8.x86_64.rpm
上面第三步修改的配置文件,最后面三个别名配置项就是安装这个之后配置上去的。
[root@MaxwellDBA home]# yum localinstall rlwrap-0.43-5.el8.x86_64.rpm
Repository extras is listed more than once in the configuration
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Last metadata expiration check: 1:19:33 ago on Wed 29 Jun 2022 04:39:05 AM CST.
Dependencies resolved.
===============================================================================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================================================================
Installing:
rlwrap x86_64 0.43-5.el8 @commandline 123 k
Transaction Summary
===============================================================================================================================================================================================================
Install 1 Package
Total size: 123 k
Installed size: 324 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : rlwrap-0.43-5.el8.x86_64 1/1
Running scriptlet: rlwrap-0.43-5.el8.x86_64 1/1
Verifying : rlwrap-0.43-5.el8.x86_64 1/1
Installed:
rlwrap-0.43-5.el8.x86_64
Complete!
[root@MaxwellDBA home]#
2、sql查询出来的数据中文时显示乱码 上面 第三步操作中配置文件 NLS_LANG 要根据数据库编码配置,可以通过语句查询:select userenv('language') from dual;
3、数据库用户密码有效期默认是180天,建议改成无限期 -- 查询数据库用户密码有效期,可以看到默认是180天 SELECT * FROM dba_profiles s Where s.profile = 'DEFAULT' AND resource_name = 'PASSWORD_LIFE_TIME'
; -- 修改为永不过期 ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED ;
SQL> set pagesize 200
SQL> set line 200
SQL> SELECT * FROM dba_profiles s Where s.profile = 'DEFAULT' AND resource_name = 'PASSWORD_LIFE_TIME';
PROFILE RESOURCE_NAME RESOURCE
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------- --------
LIMIT COM INH IMP
-------------------------------------------------------------------------------------------------------------------------------- --- --- ---
DEFAULT PASSWORD_LIFE_TIME PASSWORD
180 NO NO NO
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED ;
Profile altered.
SQL> SELECT * FROM dba_profiles s Where s.profile = 'DEFAULT' AND resource_name = 'PASSWORD_LIFE_TIME';
PROFILE RESOURCE_NAME RESOURCE
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------- --------
LIMIT COM INH IMP
-------------------------------------------------------------------------------------------------------------------------------- --- --- ---
DEFAULT PASSWORD_LIFE_TIME PASSWORD
UNLIMITED NO NO NO
SQL>
4、如果centos8开了防火墙,还需要关闭防火墙或添加监听端口,添加端口如下: firewall-cmd --zone=public --permanent --add-port=1521/tcp firewall-cmd --zone=public --permanent --add-port=5500/tcp
六、重启服务器后自启动数据库(可选)
1、 oracle用户操作,修改文件: vim /etc/oratab 最后一行,把: ORCLCDB:/opt/oracle/product/19c/dbhome_1: N 改为:ORCLCDB:/opt/oracle/product/19c/dbhome_1: Y
2、 root用户操作,修改centos系统启动脚本: vim /etc/rc.d/rc.local 在最后加入以下两行: 启动监听:su oracle -lc "/opt/oracle/product/19c/dbhome_1/bin/lsnrctl start" 这句要加引号是因为“lsnrctl start”之间有空格 启动数据库:su oracle -lc /opt/oracle/product/19c/dbhome_1/bin/dbstart