准备工作
oracle下载:【Oracle下载地址】
比如我下面使用的就是这两个文件
安装Xmanager6工具
1、安装依赖包(中间部分日志省略)
[root@*** ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*.i686 elfutils-libelf-devel gcc gcc-c++ glibc*.i686 glibc
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 205 kB 00:00:00
(3/4): updates/7/x86_64/primary_db | 6.4 MB 00:00:00
(4/4): base/7/x86_64/primary_db
.
.
.
Dependency Updated:
cpp.x86_64 0:4.8.5-36.el7_6.2 elfutils.x86_64 0:0.172-2.el7 elfutils-libelf.i686 0:0.172-2.el7 elfutils-libelf.x86_64 0:0.172-2.el7 elfutils-libs.i686 0:0.172-2.el7 elfutils-libs.x86_64 0:0.172-2.el7 glibc-common.x86_64 0:2.17-260.el7_6.5
glibc-devel.x86_64 0:2.17-260.el7_6.5 glibc-headers.x86_64 0:2.17-260.el7_6.5 libgcc.i686 0:4.8.5-36.el7_6.2 libgcc.x86_64 0:4.8.5-36.el7_6.2 libgomp.x86_64 0:4.8.5-36.el7_6.2 libstdc++.i686 0:4.8.5-36.el7_6.2 libstdc++.x86_64 0:4.8.5-36.el7_6.2
zlib.i686 0:1.2.7-18.el7 zlib.x86_64 0:1.2.7-18.el7
Complete!
2、创建oracle用户和组
[root@*** ~]# groupadd dba
[root@*** ~]# groupadd oinstall
[root@*** ~]# groupadd oper
[root@*** ~]# useradd -g oinstall -G dba,oper oracle
[root@*** ~]# echo "123456" | passwd --stdin oracle #oracle
Changing password for user oracle.
passwd: all authentication tokens updated successfully.
参数说明:
dba组用于管理数据库
oinstall组用于安装数据库
-g 表示这个用户的主组
-G 标识这个用户的其它组
注意:dba、oinstall都可以自己命名;一个用户只能有一个主组,可以属于多个组。
3、创建目录,上传oracle文件,如果rz命令未安装,参考【Linux:-bash: rz: command not found】
[root@*** ~]# mkdir -p /opt/oracle/product/12/db
[root@*** ~]# cd /opt/oracle/
[root@*** oracle]# rz -e
[root@*** oracle]# ls
linuxamd64_12102_database_1of2.zip linuxamd64_12102_database_2of2.zip product
4、设置权限,将目录 /opt/oracle 中所有文件的所有者和组更改为用户 oracle 和组oinstall
[root@*** oracle]# chown -R oracle:oinstall /opt/oracle/
You have new mail in /var/spool/mail/root
[root@*** oracle]# chmod -R 775 /opt/oracle
5、修改内核参数,sysctl -p使更改生效。
增加:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4098955264
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
[root@*** oracle]# vi /etc/sysctl.conf
[root@*** oracle]# sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4098955264
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
6、修改limits.conf,vi /etc/security/limits.conf,该文件修改即时生效,如果没有生效,重新登录即可。增加:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
修改文件,vi /etc/pam.d/login,增加:
session required pam_limits.so
7、修改profile文件:vi /etc/profile,Login shell 启动时才会运行 /etc/profile 这个脚本,该文件中设置的变量是全局变量。增加:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536a
else
ulimit -u 16384 -n 65536
fi
fi
8、修改环境变量:vi ~oracle/.bash_profile,增加:
RACLE_BASE=/opt/oracle
ORACLE_HOME=$ORACLE_BASE/product/12/db
ORACLE_SID=oracle
export ORACLE_BASE ORACLE_HOME ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH
export PATH
9、重启系统。
[root@*** oracle]# reboot
10、进入oracle目录,解压文件
[root@*** ~]# cd /opt/oracle
[root@*** oracle]# su oracle
[oracle@*** oracle]$ unzip linuxamd64_12102_database_1of2.zip
.
.
.
[oracle@*** oracle]$ unzip linuxamd64_12102_database_2of2.zip
.
.
.
11、设置为英文字符集环境
[oracle@*** oracle]$ export LANG="en_US"
12、使用Xmanager添加Xstart,怎么样安装使用Xmanager6的教程可以直接在网上找。
执行命令:/usr/bin/xterm -ls -display $DISPLAY
如果连接出现问题,参考:【Xmanager6运行错误】
正常连接:
13、在Xstart窗口中运行以下命令
[root@*** ~]# cd /opt/oracle/database/
[root@*** database]# su oracle
[oracle@*** database]$ ls
install response rpm runInstaller sshsetup stage welcome.html
[oracle@*** database]$ ./runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 500 MB. Actual 23974 MB Passed
Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed
Checking monitor: must be configured to display at least 256 colors. Actual 16777216 Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-07-25_10-48-31AM. Please wait ...[oracle@*** database]$
如果遇到Check if the DISPLAY variable is set错误,请参考:【Linux:Check if the DISPLAY variable is set.】
14、进入安装页面,取消I wish...的选中,点击Next,弹出框直接选择Yes
15、Installation Option(安装选项),我这里选择Install database software only
16、 Grid Installation Options(数据库安装选项),选择单机的就好了
17、Product Languages(产品语言),默认为English
18、Database Edition(数据库版本)
19、 Installation Location(安装路径)
20、Create Inventory(创建库存)
默认路径出现错误,它是第4步分配权限导致的,解决办法:在路径中增加/oracle
21、 Operating System Groups(操作系统组)
22、Prerequis ite Checks(先决条件检查)
以上问题解决:
【Swap Size解决方法】
【Linux:OS Kernel Parameters : shmmax】
【Linux:Package:ksh】
【Linux: Package:libaio-devel-0.3.109 (x86_64)】
23、Summary(总结)
24、Install Product(产品安装),Finish(完成)页直接点Close就可以了。
25、启动数据图形化界面装数据库
[oracle@*** database]$ dbca
26、选择配置
27、选择数据库模板
28、配置数据库容器
29、配置Orale EM
30、数据库账号密码设置,密码Oracle推荐的标准:长度至少应为8个字符,必须至少包含一个大写字符、一个小写字符和一个数字。
31、监听器配置
32、配置数据库存储方式
33、数据库配置:示例方案和数据库安全配置
34、初始化参数:内存、块、连接数量、字符集、连接模式
35、创建配置
36、校验通过,直接跳转Summary页面
37、Progress Page
运行root.sh文件
Enter the full pathname of the local bin directory: [/usr/local/bin]:时,直接按Enter键
[root@*** ~]# cd /opt/oracle/product/12/db/
[root@*** db]# ls
addnode bin cfgtoollogs css dbs demo dv install javavm jlib log network odbc opmn ord perl precomp racg rest slax sqlpatch suptools usm xdk
apex ccr clone ctx dc_ocm diagnostics has instantclient jdbc ldap md nls olap oracore oui plsql QOpatch rdbms root.sh sqldeveloper sqlplus sysman utl
assistants cdata crs cv deinstall dmu hs inventory jdk lib mgw oc4j OPatch oraInst.loc owm plugins R relnotes scheduler sqlj srvm ucp wwg
[root@*** db]# ./root.sh
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /opt/oracle/product/12/db
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.
运行完root.sh后,点掉Database Configuration ...弹窗,最后的Finish点击Close。
启动与关闭
1)、切换用户
[root@*** oracle]# su - oracle
Last login: Thu Jul 25 22:42:14 CST 2019 from 40.76.65.78 on pts/0
Last failed login: Fri Jul 26 09:24:09 CST 2019 from 121.239.47.214 on ssh:notty
There were 7 failed login attempts since the last successful login.
2)、查看监听及数据库状态(HOST为oracle服务器ip,此处用星号代替)
[oracle@*** ~]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2019 10:38:05
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= *.*.*.*)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
3)、启动监听
[oracle@*** ~]$ lsnrctl start
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2019 10:39:17
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Starting /opt/oracle/product/12/db/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.1.0.2.0 - Production
System parameter file is /opt/oracle/product/12/db/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/***/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=*.*.*.*)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*.*.*.*)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 26-JUL-2019 10:39:19
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/12/db/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/***/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=*.*.*.*)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
4)、 以 DBA 身份进入 sqlplus
[oracle@*** ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Fri Jul 26 10:40:41 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected.
SQL>
5)、启动db
SQL> startup
ORACLE instance started.
Total System Global Area 2466250752 bytes
Fixed Size 2927384 bytes
Variable Size 671089896 bytes
Database Buffers 1778384896 bytes
Redo Buffers 13848576 bytes
Database mounted.
Database opened.
6)、关闭db,关闭需要一定时间,稍微耐心等待下。
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
关闭db的其他命令及含义:
shutdown normal:不允许任何用户创建新的连接,等待已连接用户完成事务和会话后,生成检查点并关闭数据文件,启动时不需要实例恢复;
shutdown transactional:不允许任何用户创建新的连接,等待已连接用户完成事务,不等待会话结束,生成检查点并关闭数据文件,启动时不需要实例恢复;
shutdown immediate:不允许任何用户创建新的连接,已连接用户未提交的事务回滚,不等待会话结束,生成检查点并关闭数据文件,启动时不需要实例恢复;
shutdown abort:不允许任何用户创建新的连接,已连接用户未提交事务不回滚,不等待会话结束,不生成检查点,不关闭数据文件,启动时需要实例恢复,数据库异常时,以上3个命令不能关闭db时考虑使用这个命令。
根据不同需求使用不同命令关闭db。
7)、关闭监听
SQL> quit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@*** ~]$ lsnrctl stop
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2019 11:20:43
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*.*.*.*)(PORT=1521)))
The command completed successfully
以上就是Linux安装oracle数据库的步骤。
创建用户及连接,参考【Linux创建oracle用户、连接数据库】
如果有写的不对的地方,请大家多多批评指正,非常感谢!