【Oracle学习01】Oracle12c图形化安装及问题处理
Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系型数据库管理系统。本文介绍在CentOS6下图形化安装Oracle12c。
Oracle官方文档:https://www.oracle.com/index.htmlhttps://docs.oracle.com/en/database/oracle/oracle-database/index.htmlhttps://docs.oracle.com/en/database/oracle/oracle-database/12.2/install-and-upgrade.html
Oracle12c安装要求:硬件: 空闲Disk >8G, 内存>2G,若安装 Oracle Grid>8G。
操作系统: Linux 7.2: 3.10.0-327.el7.s390x or later, Linux 6.6: 2.6.32-504.el6.s390x or later软件包依赖: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/cwlin/supported-red-hat-enterprise-linux-6-distributions-for-x86-64.html#GUID-3B53A308-3EC2-4173-98A0-0FFD68994E90
1. CentOS环境准备
1.1 准备CentOS6环境
准备CentOS6环境,若是没有可以用VirutalBox来创建一台CentOS虚机。
创建步骤见: VirtualBox创建CentOS6.6虚机
OS | Hostname | IP | 硬件 |
---|---|---|---|
CentOS6.6 | db01 | 192.168.56.103 | 4G内存,磁盘30G(至少内存2G,空闲磁盘>8G) |
1.2 Oracle软件下载
下载Oracle12.2.0.1.0版本,选择Linux x86-64安装包。(下载需要Oracle账号)。
下载地址: https://www.oracle.com/database/technologies/oracle12c-linux-12201-downloads.html
检查下载文件:
$cksum oracle_linuxx64_12201_database.zip
4170261901 3453696911 oracle_linuxx64_12201_database.zip
上面输出信息中校验码为 4170261901 , 文件大小为3453696911,和官方相同。
2. 安装介绍
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tutorials.htmlhttps://docs.oracle.com/en/database/oracle/oracle-database/12.2/install-and-upgrade.html
2.1 OUI介绍
oracle 安装使用OUI(Oracle Universal Installer )。
OUI介绍:https://docs.oracle.com/cd/E2685401/em.121/e37799/ch1introduction.htm#OUICG107
https://oracle-base.com/articles/misc/oui-silent-installationshttps://www.2cto.com/database/201110/107339.html 深入理解OUI
2.2 安装的三种模式
OUI 三种模式(Modes of Installation):
Interactive Mode
Suppressed-Interactive Mode
Silent Mode
1) OUI图形化安装
Oracle Universal Installer (OUI)图形化安装。Interactive Mode。
2)静默安装
静默安装 Silent Mode 。在无图形界面或命令行批量部署时可静默(Silent Mode)安装 oracle ,用命令行创建db,配置netca等,快速完成oracle部署。
$ORACLE_HOME/runInstaller -h
./runInstaller [-silent] [-noconfig] -responseFile responsefilename
3)克隆安装
若是有配置相同的机器需要安装,这时可以进行clone安装。
3. 安装的前期准备
安装的前期准备/先决条件。
3.1 配置/etc/hosts文件
检查主机名和网络并且配置/etc/hosts文件,依你真实情况请填写 IP地址 主机名
$hostname #db01
#填写 IP地址 主机名
$vim /etc/hosts
192.168.56.103 db01
3.2.配置YUM源(可略)
可配置本地yum源或用国内阿里云,163yum源。
配置国内yum源:
参见: 配置国内yum源
配置本地YUM源:
配置YUM源解决程序依赖的问题
a 挂载光盘镜像
b 进入到光盘镜像中的Package目录中将所有的软件包复制到我们预设的目录下
#把光盘中rpm文件cp到本地
mkdir /yums
cd /media/CentOS_6.6_Final/Packages/
cp * /yums
cd /yums
rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
rpm -ivh createrepo-0.9.9-22.el6.noarch.rpm
##创建Repo
createrepo .
创建yum.local.repo
cd /etc/yum.repos.d/
mkdir backup; mv ./* backup/
#创建yum.local.repo
vi yum.local.repo
[local]
name=yum local repo
baseurl=file:///yums
gpgcheck=0
enable=1
yum clean all
3.3 安装ORACLE依赖软件包
yum install -y bc
yum install -y compat-libcap1*
yum install -y compat-libcap*
yum install -y binutils
yum install -y compat-libstdc++-33
yum install -y elfutils-libelf
yum install -y elfutils-libelf-devel
yum install -y gcc
yum install -y gcc-c++
yum install -y glibc-2.5
yum install -y glibc-common
yum install -y glibc-devel
yum install -y glibc-headers
yum install -y ksh libaio
yum install -y libaio-devel
yum install -y libgcc
yum install -y libstdc++
yum install -y libstdc++-devel
yum install -y make
yum install -y sysstat
yum install -y unixODBC
yum install -y unixODBC-devel
yum install -y binutils*
yum install -y compat-libstdc*
yum install -y elfutils-libelf*
yum install -y gcc*
yum install -y glibc*
yum install -y ksh*
yum install -y libaio*
yum install -y libgcc*
yum install -y libstdc*
yum install -y make*
yum install -y sysstat*
yum install -y libXp*
yum install -y glibc-kernheaders
yum install -y net-tools-*
检查软件包安装情况:
$rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" \
bc compat-libcap1* compat-libcap* binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc-2.5 glibc-common glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel binutils* compat-libstdc* elfutils-libelf* glibc* ksh* libaio* libgcc* libstdc* sysstat* libXp* glibc-kernheaders net-tools-* \
| grep not | grep -v grep | awk '{print "yum install -y " $2 }'
#结果,缺少的软件包就会列出来,如下。
...
yum install -y glibc-2.5
yum install -y gcc*
3.4 修改LINUX内核文件
vi /etc/sysctl.conf
kernel.shmmax = 277495689510912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.file-max = 6815744
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_probes = 6
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_timestamps = 0
fs.aio-max-nr = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
sysctl -p 生成系统参数
3.5 修改limits.conf
添加下列参数到/etc/security/limits.conf
vi /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
oracle hard memlock 134217728
oracle soft memlock 134217728
3.6 修改/etc/pam.d/login
添加下列条目到/etc/pam.d/login
vim /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
3.7 修改环境变量
vim /etc/profile
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
source /etc/profile
3.8 创建文件目录和用户
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle
mkdir -p /u01/app/oracle
mkdir -p /u01/oraInventory
chown -R oracle.oinstall /u01
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle
#设置Linux中oracle用户密码
passwd oracle # oracleoracle
id oracle
#usermod -a -G GroupName UserName
#usermod -a -G oracle oracle
3.9 配置ORACLE用户环境变量
su - oracle
vim .bash_profile
export EDITOR=vi
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export INVENTORY_LOCATION=/u01/oraInventory
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG="American_america.zhs16gbk"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
umask 022
source .bash_profile
3.10 上传软件并且解压
将下载的linuxx6412201database.zip上传到Linux系统/home/oracle目录下解压,解压后目录为database。
cd /u01/
unzip linuxx64_12201_database.zip
4. 图形化安装Oracle
4.1 登录CentOS界面
LINUX用户切换有两种方案,第一种是登出现有用户进行用户切换。第二种很简单 重新启动你的虚拟机 在登录界面选择oracle用户登录即可。(用户oracle,密码是节3中设置的linux下oracle密码。)
4.2 安装Oracle软件
进入database目录,执行runInstaller,图形化安装Oracle软件。
cd /u01/database
./runInstaller
选择Single instance database installation。
弹出这个后,以root权限执行两个脚本,执行完以后点击ok。
4.3 创建监听
执行netca创建监听,一路next,最后点Finish。
cd database
./netca
#若是图形出不来,可root登录一个窗口,运行一下语句。
#export DISPLAY=:0.0
察看监听
su - oracle
$lsnrctl stop
$lsnrctl start
$lsnrctl status
$cat /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
$cat /u01/app/oracle/product/12.2.0/db_1/network/admin/tnsnames.ora
4.4 创建数据库
用dbca创建数据库。
$cd database
$dbca
选择Advanced configuration。
密码太简单会提示,可选yes略过。
Finish。
点击close后完成。恭喜你数据库安装成功!!!
5. 检查服务
5.1 检查监听
环境变量
$su - oracle
$env |grep oracle -i
USER=oracle
LD_LIBRARY_PATH=/u01/app/oracle/product/12.2.0/db_1/lib
ORACLE_SID=orcl
ORACLE_BASE=/u01/app/oracle
TNS_ADMIN=/u01/app/oracle/product/12.2.0/db_1/network/admin
MAIL=/var/spool/mail/oracle
PATH=/u01/app/oracle/product/12.2.0/db_1/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin:/home/oracle/bin
PWD=/home/oracle
HOME=/home/oracle
LOGNAME=oracle
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1
启动监听
$lsnrctl stop
$lsnrctl start
$lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 23-NOV-2019 16:07:52
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.103)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 23-NOV-2019 10:07:05
Uptime 0 days 6 hr. 0 min. 46 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/db01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.103)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 2 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
#
$nc -z 192.168.56.103 1521
Connection to 192.168.56.103 port 1521 [tcp/ncube-lm] succeeded!
$tnsping ORCL@192.168.56.103
5.2 配置文件
连接oracle可能会出错,很可能是listener.ora配置有问题,正确的如下。
listener.ora文件:
cat /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
tnsnames.ora
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
6. 访问数据库
6.1 SQLPlus连接 Oracle
#本机
$sqlplus / as sysdba
$
$sqlplus sys/oracle@orcl(网络服务名) as sysdba
SQL> select status from v$instance;
STATUS
------------------------
OPEN
6.2 Navicat 远程连接oracle
Navicat 可让用户简单地管理 MySQL、MariaDB、MongoDB、SQL Server、SQLite、Oracle 和 PostgreSQL 的数据。
官网: https://www.navicat.com.cn/products/
1)安装Navicat
下载地址:https://www.navicat.com.cn/download/navicat-premium
2)修改Oracle hosts
#IP要和服务器IP一致 ,名称一致
vim /etc/hosts
192.168.56.103 db01
#有可能mac机器也要配置host,待测试。
#sudo scutil --set HostName TaoMacBookPro
说明:有时Navicat 远程连接失败,一种可能原因是没有配置/etc/host。
3)配置Navicat
mac上的navicat不需要配置tnsnames.ora。
7. 安装问题处理
Q1: 安装oracle图形界面出不来,出错DISPLAY environment variable not set!。
A1: 可能要export DISPLAY=:0.0。
root登录一个窗口,运行一下语句。
#export DISPLAY=:0.0
echo 'export DISPLAY=:0.0'>>/etc/profile
source /etc/profile
#xhost +
#su - oracle
然后就在这个窗口运行oracle的安装程序。
Q2:runInstaller出错,错误Linux PRVF-0002 : Could not retrieve local nodename
A2:runInstaller 出错,可能是要配置/etc/hosts。
1. ifconfig 得到ip 192.168.56.103
2. hostname得到名字db01。
$ hostname
db01
3. 然后设置 自己的 地址:vim /etc/hosts 。为hostname相应的地址
#当前的ip 和hostname
192.168.56.103 db01
4. 继续安装
Q3: 监听器没有启动,连接oracle失败。
A3:启动lsnrctl start即可。
1. su oracle
2. lsnrctl start
#停止监听器命令
3. lsnrctl stop
#查看监听器命令.
4. lsnrctl status
Q4: 远程访问oracle,出错 ORA-12541: TNS:no listener
A4:很可能是 listener.ora配置只配置了hostname,即把db01名字,改为ip。(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
su - oracle
cd /u01/app/oracle/product/12.2.0/db_1/network/admin
cp listener.ora listener.ora.backup
#配置listener 增加IP。开始是hostname
vim listener.ora
#
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
重启lsnrctl:
#重启
lsnrctl stop
lsnrctl start
lsnrctl status
Q5: 远程访问oracle,出错 ORA-12541: TNS:no listener
A5:若listener.ora配置正确,也可能是tnsnames.ora配置不正确。
$nc -z 192.168.56.103 1521
$tnsping ORCL
$tnsping ORCL@192.168.56.103
##正确的配置类似.
cat tnsnames.ora
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
也可以用netmgr图形化配置。
su - oracle
netmgr
Q6: 连接oracle,出错ORA-27101: shared memory realm does not exist
A6: 原因常是非正常关停oracle引起,如直接断电关机引起。可尝试强制startup force。
connect / as sysdba
startup force
参考
https://docs.oracle.com/en/database/oracle/oracle-database/index.html
https://www.navicat.com.cn/products
Oracle 网络配置与管理 https://www.cnblogs.com/ios9/p/7594717.htm
Oracle网络配置 https://blog.csdn.net/newbie_907486852/article/details/80720084
命令行安装Oracle12c https://blog.csdn.net/sl1992/article/details/80457935#42_255