系统:建议用Oracle官网提供的OEL7.6 (Oracle企业版Linux),有对oracle内核做了好多优化 。
这里用示范的是在CentOS7.6下图形化安装Oracle 12,静默安装另外写一篇文章介绍
图形化安装大概步骤:安装Oracle软件(runInstaller) -> 配置网络监听(netca) -> 创建数据库(dbca) -> 本地Net服务名配置(netca)
https://edelivery.oracle.com/osdc/faces/SoftwareDelivery#!
Oracle安装包:linuxx64_12201_database.zip (到Oracle官网,注册个用户去下载)
想练习的话把example的包也下了“linuxx64_12201_examples.zip”
下面是安装过程:
[root@localhost ~]# groupadd -g 501 oinstall #建一个gid为501的oinstall组
[root@localhost ~]# groupadd -g 502 dba #建一个gid为503的dba组
[root@localhost ~]# useradd -g oinstall -G dba oracle #建用户oracle,且加入主组oinstall和从属组dba,好像古代老婆一个,妾可以很多个。举例,su - oracle后创建的文件所属组是oinstall,newgrp dba切换到从属组dba后创建的文件所属组是dba
[root@localhost ~]# id oracle
uid=1000(oracle) gid=501(oinstall) groups=501(oinstall),502(dba)
[root@localhost ~]# mkdir -p /orasetup /home/app/oracle/product/12.2.0/db_1 #这些连接根据自己需要来定
[root@localhost ~]# chmod -R 775 /orasetup /home/app/oracle/product/12.2.0/db_1
[root@localhost ~]# chown -R oracle:oinstall /orasetup /home/app/oracle/product/12.2.0/db_1
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ vi .bash_profile #设环境变量,下面的alias和export
[oracle@localhost ~]$ cat ./.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias sqlplus='rlwrap sqlplus' #去安装rlwrap,它支持上下左右的键盘滚动以及历史记录快速查询的,默认sqlplus不支持,用list看历史记录也不方便
alias rman='rlwrap rman'
export ORACLE_BASE=/home/app/oracle #oracle基本目录,其它oracle软件都可以装这里
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1 #oracle数据库软件目录
export ORACLE_SID=oral #oracle数据库唯一标识(在单实例里比较重要)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/lib/usr/lib #字典库路径
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$ORACLE_HOME/jdk/bin #bin操作路径
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" #日期显示格式
export NLS_LANG="Simplified Chinese_China".AL32UTF8 #字符集
[oracle@localhost ~]$ source .bash_profile
安装rlwrap
[root@localhost ~]# tar -zxvf rlwrap-0.37.tar.gz
......
[root@localhost ~]# cd rlwrap-0.37
[root@localhost rlwrap-0.37]# ls
aclocal.m4 AUTHORS BUGS ChangeLog completions config.h.in configure configure.ac COPYING doc filters INSTALL Makefile.am Makefile.in NEWS PLEA README src test TODO tools
[root@localhost rlwrap-0.37]# ./configure
checking build system type... Invalid configuration `x86_64-unknown-linux-': machine `x86_64-unknown-linux' not recognized
configure: error: /bin/sh tools/config.sub x86_64-unknown-linux- failed
[root@localhost rlwrap-0.37]# yum install gcc gcc-c++ -y #上面报错,先安装一些常用依赖再试下,哈
......
[root@localhost rlwrap-0.37]# ./configure
......
configure: checking for pty ranges...
checking for tgetent... no
checking for tgetent in -lcurses... yes
checking for readline in -lreadline... no
configure: error:
You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build
this program!
[root@localhost rlwrap-0.37]# yum install *readline* -y #上面还有别的报错,再装依赖
......
[root@localhost rlwrap-0.37]# ./configure
...... #终于正常了
[root@localhost rlwrap-0.37]# make && make install
......
[root@localhost rlwrap-0.37]# rlwrap -v
rlwrap 0.37
设置些系统限制
[root@localhost rlwrap-0.37]# vi /etc/profile #加下面去解除系统限制
......
if [ $USER = "oracle" ] || [ $USER = "grid" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
[root@localhost rlwrap-0.37]# source /etc/profile
[root@localhost rlwrap-0.37]# vi /etc/security/limits.conf #加下面去允许打开的软硬限制。参考下https://www.cnblogs.com/galengao/p/5764693.html
......
oracle soft stack 10240
oracle soft nproc 2047 #noproc表示的是每个用户最大的进程数
oracle hard nproc 16384
oracle soft nofile 1024 #nofile表示的时最多能同时打开的文件数
oracle hard nofile 65536
......
使用xshell或secureCRT连接linux时不支持图形模式,这里用xmanage的Xmanager - Passive去做实验。
1、安装xmanager后运行里面的Passive,右下角会出现一个X的图标
2、在客户端执行下面命令,下面IP是本机的客户端IP,然后执行xhost +,出现下面提示才正常
[root@localhost ~]# xhost +
-bash: xhost: 未找到命令
[root@localhost ~]# yum whatprovides "*/xhost"
已加载插件:ulninfo
ol7_UEKR5/x86_64/filelists_db | 2.7 MB 00:00:02
ol7_latest/x86_64/filelists_db | 15 MB 00:00:12
xorg-x11-server-utils-7.7-20.el7.x86_64 : X.Org X11 X server utilities
源 :ol7_latest
匹配来源:
文件名 :/usr/bin/xhost
[root@localhost ~]# yum install -y xorg-x11-server-utils-7.7-20.el7.x86_64 #根据上面提示安装
[root@localhost ~]# export DISPLAY=150.18.46.138:0.0
[root@localhost ~]# xhost +
access control disabled, clients can connect from any host
安装
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ export DISPLAY=150.18.46.138:0.0
[oracle@localhost ~]$ xhost +
access control disabled, clients can connect from any host
[oracle@localhost ~]$ cd /orasetup
[oracle@localhost orasetup]$ unzip linuxx64_12201_database.zip
......
[oracle@localhost orasetup]$ ls
database linuxx64_12201_database.zip
[oracle@localhost orasetup]$ cd database/
[oracle@localhost database]$ ls
install response rpm runInstaller sshsetup stage welcome.html
[oracle@localhost database]$ ./runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 500 MB. Actual 23761 MB Passed
Checking swap space: must be greater than 150 MB. Actual 2047 MB Passed
Checking monitor: must be configured to display at least 256 colors
>>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,
Continue? (y/n) [n] y
>>> Ignoring required pre-requisite failures. Continuing...
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-08-09_03-14-24PM. Please wait ...
配置安全更新。前面√去掉(如果安装框乱码就搞字体包进去或者先export LANG=en_US英文安装)
安装选项。先仅安装数据库软件
数据库安装选项。现在仅玩下单实例
数据库版本。选企业版安装
安装位置。上面是oracle基目录,下面是oracle产品目录,这2目录在之前oracle用户.bash_profile中配好了,这里直接读取该文件
创建产品清单(如果是第二次安装数据库软件时,需要把该目录下的清册干掉)
操作系统组。各种操作所需的权限组,自己玩,都给dba好了
先决条件检查。如果用的官方OEL系统,直接yum install oracle就ok。由于这里用vmware装的Centos7.6去玩,所以要根据下面的检查结果点开每一个(more details)提示解决
"Checks"部分,1、修改swap大小 2、在/etc/security/limits.conf里加上oracle hard nofile 65536
"OS Kernel Parameters"部分,根据提示修改内核参数,把下面加到/etc/sysctl.conf,然后sysctl -p生效
kernel.sem=250 32000 100 128
fs.file-max=6815744
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048576
fs.aio-max-nr=1048576
"Packages"部分,根据检查用root把它们都yum安装上 ( yum install compat* sysstat* ksh* smartmontools* -y)
修改完成后再点下【Check Again】重新检查下,没报错就继续
安装过程出现下面提示,根据提示用root执行相应脚本
执行完脚本后点OK继续
安装完成,点关闭即可
安装监听 (NETCA)
在oracle用户下输入命令netca
[oracle@localhost ~]$ export DISPLAY=150.18.46.138:0.0
[oracle@localhost ~]$ env | grep -i display
DISPLAY=150.18.46.138:0.0
[oracle@localhost ~]$ xhost +
access control disabled, clients can connect from any host
[oracle@localhost ~]$ netca
选择“监听配置”,下一步
添加监听,下一步
默认监听名称LISTENER,下一步
默认TCP协议,下一步
默认端口1521.下一步
不配置另一个监听,下一步
监听配置完成,下一步
点击完成按钮Finish,完成配置
创建数据库
在用户oracle下输入命令dbca
默认创建数据库,下一步
选择高级配置,下一步
单实例数据库 -> 一般用途(OLTP)或事务处理 -> 下一步
默认,下一步
12C后支持CDB和PDB(即容器数据库Container Database和可插拔数据库Pluggable Database),实例与数据库形成一对多关系
选择存储属性 -> OMF表空间管理 -> 下一步
快速闪回区的存储方式、路径和大小 (做练习,先不开归档)
可以看到已将加载出之前设置的监听程序,下一步
做练习用,先不设安全选项,下一步
练习环境可以打上勾,内存情况请根据实际情况自行设置,下一步
如果共享内存设置超过总内存的一半,需要在系统中设置shm,虚拟内存页大小
vi /etc/fstab -> tmpfs /dev/shm tmpfs defaults,size=12288M 0 0
保存后,umount /dev/shm再mount /dev/shm
这几个选项涉及共享内存(sga/pga)、调整大小注意是进程大小、字符集默认AL32UTF8就好、连接模式选专用、实例方案可选
这里不设置单机版的OEM,为了后期加入到OEM CC中,下一步
自己练习玩的,统一口令好了,下一步
可以查看所有的初始化参数,也可以生成数据库创建脚本来学习(这个脚本主要采用的是RMAN的CLONE技术),下一步
看下详细的配置清单,检查OK后,点击完成开始建库
数据库创建完毕,关闭
本地NET服务名配置
oracle用户下输入netca
选择本地net服务名配置
已经建库了,直接测试即可,下一步
选择库名相同的服务,下一步
用system用户测试,输入密码,测试成功
网络配置
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ cd /home/app/oracle/product/12.2.0/db_1/network/admin
[oracle@localhost admin]$ vim listener.ora
[oracle@localhost admin]$ cat listener.ora
# listener.ora Network Configuration File: /home/app/oracle/product/12.2.0/db_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))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /home/app/oracle/product/12.2.0/db_1)
)
)
[oracle@localhost admin]$
启动下监听程序,下图成功(snrctl stop -> lsnrctl start ->lsnrctl status)
[oracle@localhost admin]$ lsnrctl stop
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-9月 -2019 09:55:38
Copyright (c) 1991, 2016, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
命令执行成功
[oracle@localhost admin]$ lsnrctl start
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-9月 -2019 09:55:44
Copyright (c) 1991, 2016, Oracle. All rights reserved.
启动/home/app/oracle/product/12.2.0/db_1/bin/tnslsnr: 请稍候...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
系统参数文件为/home/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
写入/home/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml的日志信息
监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
监听: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for Linux: Version 12.2.0.1.0 - Production
启动日期 11-9月 -2019 09:55:44
正常运行时间 0 天 0 小时 0 分 0 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 /home/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
监听程序日志文件 /home/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
服务摘要..
服务 "orcl" 包含 1 个实例。
实例 "orcl", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
[oracle@localhost admin]$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 11-9月 -2019 09:55:48
Copyright (c) 1991, 2016, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for Linux: Version 12.2.0.1.0 - Production
启动日期 11-9月 -2019 09:55:44
正常运行时间 0 天 0 小时 0 分 4 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 /home/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
监听程序日志文件 /home/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
服务摘要..
服务 "orcl" 包含 1 个实例。
实例 "orcl", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
[oracle@localhost admin]$
本地net服务名配置
[oracle@localhost admin]$ pwd
/home/app/oracle/product/12.2.0/db_1/network/admin
[oracle@localhost admin]$ vim tnsnames.ora
[oracle@localhost admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /home/app/oracle/product/12.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORAL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED) #采用专用模式
(SERVICE_NAME = orcl)
)
)
[oracle@localhost admin]$
Oracle启动
[oracle@localhost admin]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on 星期三 9月 11 10:02:42 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
连接到:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup nomount
ORACLE 例程已经启动。
Total System Global Area 536870912 bytes
Fixed Size 8794848 bytes
Variable Size 306187552 bytes
Database Buffers 213909504 bytes
Redo Buffers 7979008 bytes
SQL> alter database mount;
数据库已更改。
SQL> alter database open;
数据库已更改。
SQL>