CENTOS8 安装 Oracle

首先,环境配置

oracle数据库对环境要求很高,docker我没找到一个用起来顺手的,所以有了自己安装的想法。

在网上找到的一个一键配置oracle环境的shell:
https://wwr.lanzoui.com/iXKBBu3uoda
这个shell只是方便环境配置,会自动帮你创建账号、文件夹、权限、环境变量。

chmod 777 oraclePreInstallCheck.sh
./oraclePreInstallCheck.sh

因为CENTOS8自带rpm,所以就不需要下载rpm了。

然后检查依赖包是否安装:

rpm -q binutils compat-libstdc++ elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel bc

如果发现没有安装的依赖,需要手动安装,到下面这个网址搜索:

https://centos.pkgs.org/
搜索到软件后,找到binary package,这是已编译好的包,也可以选择源码包Source Package。
image

复制这个地址,然后输入命令,就开始安装了。如果有报错的请自行百度。

rpm -ivh http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/elfutils-libelf-devel-static-0.182-3.el8.x86_64.rpm

注意:compat-libstdc++ 这个包的名字改了,所以检查程序没有匹配得到,现在是2021年,我搜索出来的名字是Compat-libstdc++-33

依赖安装完毕后,终于

开始安装Oracle

然后解压在官网下载的安装包,我这里下载的是11.2G XE的版本

下载链接:https://download.oracle.com/otn/linux/oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip

unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip

解压后的文件目录

[root@centos8-1 ~]# tree

├── Disk1
│   ├── oracle-xe-11.2.0-1.0.x86_64.rpm
│   ├── response
│   │   └── xe.rsp
│   └── upgrade
│       └── gen_inst.sql

开始安装

[root@centos8-1 Disk1]# rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:oracle-xe-11.2.0-1.0             ################################# [100%]
Executing post-install steps...

You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

安装后进行配置:

[root@centos8-1 ~]# /etc/init.d/oracle-xe configure

Oracle Database 11g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 11g Express
Edition.  The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts.  Press <Enter> to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:   #默认端口8080没什么用,随意

Specify a port that will be used for the database listener [1521]:               #默认数据库监听端口

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of
different passwords for each database account.  This can be done after
initial configuration:
Confirm the password:

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y   #是否开机启动

Starting Oracle Net Listener...Done
Configuring database...grep: /u01/app/oracle/product/11.2.0/xe/config/log/*.log: No such file or directory
grep: /u01/app/oracle/product/11.2.0/xe/config/log/*.log: No such file or directory
Done
/bin/chmod: cannot access '/u01/app/oracle/diag': No such file or directory
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.

最后进行配置变量:

vim /etc/profile

文件尾加入以下配置

ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/xe
ORACLE_SID=XE                                     #这里特别注意,XE一定要大写,与tnsnames.ora文件内容一致,否则在使用oracle时会报ORA-01034的错误
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

保存后执行:

source /etc/profile

ok,安装基本完成,如果需要开防火墙的:

firewall-cmd --zone=public --add-port=1521/tcp --permanent    #(--permanent永久生效,没有此参数重启后失效)

firewall-cmd --reload   #重新载入

然后需要修改文件

[root@bogon ~]# cd  /u01/app/oracle/product/11.2.0/xe/dbs/
[root@bogon dbs]# cp init.ora initXE.ora
[root@bogon dbs]# vim initXE.ora
db_name='ORCL'  #这个需要改成XE或者自己的实例名
memory_target=1G
processes = 150
audit_file_dest='<ORACLE_BASE>/admin/orcl/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='<ORACLE_BASE>/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='<ORACLE_BASE>'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control1, ora_control2)
compatible ='11.2.0'

然后使用sqlplus登录

[root@bogon ~]# sqlplus / as sysdba;

SQL*Plus: Release 11.2.0.2.0 Production on Thu Sep 16 17:08:47 2021

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

SQL> startup;

如果这里连上就成功了
如果显示报错:

ORA-01031: insufficient privileges

那么需要重启一下。

[root@bogon ~]# su - oracle
上一次登录:四 9月 16 17:06:12 CST 2021pts/0 上
[oracle@bogon ~]$ sqlplus /nolog
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

这里我理解是因为没有重启系统,导致oracle账号没有更新环境变量,那么更新它就完了。

[oracle@bogon ~]$ vim /etc/profile
[oracle@bogon ~]$ source /etc/profile
[oracle@bogon ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.2.0 Production on Thu Sep 16 17:12:01 2021

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

现在连上了,开始重启

SQL> conn / as sysdba
Connected.
SQL> startup mount;
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> shutdown Immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  768294912 bytes
Fixed Size                  2230448 bytes
Variable Size             457181008 bytes
Database Buffers          306184192 bytes
Redo Buffers                2699264 bytes
Database mounted.
SQL> alter database open;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  768294912 bytes
Fixed Size                  2230448 bytes
Variable Size             457181008 bytes
Database Buffers          306184192 bytes
Redo Buffers                2699264 bytes
Database mounted.
Database opened.
SQL> exit

大功告成!

最后创建用户、获取权限都不再这里阐述了。

oracle的使用方式实在是对开发人员太不友好了,可能配置一次就不想再配置了。对比mysql、mssql哪个不是一装就完事呢。所以说oracle能够走到今天这一步还是有很多优点的,能够让大家忍受那些安装配置出现的令人抓狂的错误。如果oracle今后能够优化一下这方面的内容还是值得期待的。但是现在看来19版也不过如此。在我看来如果不是客户要求,可能永远都不会用这玩意儿。

posted @ 2021-09-06 11:54  昨天的小冉  阅读(2793)  评论(2编辑  收藏  举报