在linux下安装oracle的方法以 及自己遇到的一些问题的解决方案
自己准备学习oracle数据库,昨天花了一个晚上在虚拟机上的linux(Fedora 8)上成功安装了oracle 10g,总结自己在安装时遇到的问题以及安装的步骤和大家分享一下。
1.首先,在官网上面下载oracle –xe (rpm)格式的数据库,下载地址如下
http://download.oracle.com/otn/linux/oracle10g/xe/10201/oracle-xe-univ-10.2.0.1-1.0.i386.rpm
2.通过ssh或者其它方式,将源文件复制到linux系统下的home文件下。
3.通过cd /home/ 进去到home目录下。然后用
[root@localhost home]# ls –l
#查看home文件下的是否有oracle-xe-univ-10.2.0.1-1.0.i386.rpm
上面过程先停一下,进入到[oracle@localhost ~]$ 下去创建用户
3. 创建 Oracle 组和用户帐户
接下来,创建用于安装和维护 Oracle 10g的 Linux 组和用户帐户。用户帐户将称为 oracle,而组将称为 oinstall 和 dba。执行以下命令:
[oracle@localhost ~]$ groupadd oinstall
[oracle@localhost ~]$ groupadd dba
[oracle@localhost ~]$ useradd -m -g oinstall -G dba oracle
[oracle@localhost ~]$ id oracle
uid=501(oracle) gid=501(oinstall) groups=501(oinstall),502(dba)
设置 oracle 帐户的口令:输密码的时候都是没有回显的,输完就回车就好。
[oracle@localhost ~]$ passwd oracle
Changing password for user oracle.
New password:
Retype new password:
passwd:all authentication tokens updated successfully.
注意:我在网上看了有些帖子,在这里,有的还需要查看一下内存和修改内核参数等一些硬件是否满足要求,因为考虑到现在的机器绝大部分都满足oracle数据库的安装,这里就不作过多的说明了。
4.前提工作都做好了,下面我们就一起来安装oracle
执行下面命令:
[root@localhost home]# rpm -ivh oracle-xe-univ-10.2.0.1-1.0.i386.rpm
在这里,要注意了可能会出现错误,需要将命令改成下面的,所有建议使用
[root@localhost home]# rpm -ivh oracle-xe-univ-10.2.0.1-1.0.i386.rpm --nodeps –force
然后会进入以下过程
Preparing... ########################################### [100%]
package oracle-xe-univ-10.2.0.1-1.0 is already installed
# rpm -e oracle-xe-univ-10.2.0.1-1.0.i386
# rpm -ivh oracle-xe-univ-10.2.0.1-1.0.i386.rpm
Preparing... ########################################### [100%]
1:oracle-xe-univ ########################################### [100%]
Executing Post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to
configure the database.
配置oracle初始端口及超级用户密码,执行下面命令
[root@localhost home]# /etc/init.d/oracle-xe configure
其两个端口设为默认状态。密码自己设定好
根据提示设置8080、1521端口,还有sys和system的密码,开机是否启动等。
Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to [url]http://127.0.0.1:8080/apex[/url]
5. [root@localhost home]# reboot 重新启动
现在用netstat看看8080和1521是否已经监听了。
[oracle@localhost ~]$ netstat –tnl
如果有
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN
就启动成功
6,接下来就开始配置环境变量
首先通过注销一次,通过上面创建的oracle用户登录系统。进行如下设置
执行命令:
[oracle@localhost ~]$ vi ~/.bash_profile
出现以下画面,红色的是我设置环境变量
# User specific environment and startup programs
export ORACLE_SID=XE
export ORACLE_OWNER=oracle
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:$ORACLE_HOME/bin:/sbin
然后:wq!保存
注意:ORACLE_HOME是oracle的安装路径,如果没有指定的话,默认是在/usr/lib/oracle/目录下的。在配置环境变量时“=”号两边不能有空格,否则配置不会成功。至于ORACLE_HOME,PATH等一些名词是什么意思,你懂的。
好环境变量也就ok了
7.启动oracle数据库
启动数据库实例,分为两步:第一步,启动监听;第二步,启动数据库实例。
一、如何启动数据库实例
1.进入到sqlplus启动实例
[oracle@localhost ~]$ su - oracle --“切换到oracle用户”
Password:
[oracle@localhost ~]$ lsnrctl start --“打开监听”
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 14-OCT-2009 19:06:40
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /home/oracle/product/10g/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /home/oracle/product/10g/network/admin/listener.ora
Log messages written to /home/oracle/product/10g/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC2)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=redhat)(PORT=1522)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC2)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 14-OCT-2009 19:06:40
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/product/10g/network/admin/listener.ora
Listener Log File /home/oracle/product/10g/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC2)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=redhat)(PORT=1522)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost ~]$ sqlplus /nolog --“进入到sqlplus”
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Oct 14 19:06:45 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba --“连接到sysdba”
Connected to an idle instance.
(注意这个地方可能会报错误:oracleorcl: error while loading shared libraries:libaio.so.1:cannot open shared object file: No such file or directory)是因为有个包没有将,在网上下载libaio.so.1的rpm包,下载地址http://liuxiaochun2010.download.csdn.net/,不知道传上去没,如果没有上传成功,在此表示歉意。然后切换到root用户下安装这个两个包libaio-0.3.105-2.x86_64.rpm,libaio-0.3.105-2.i386.rpm。具休是什么原因,谷歌一下吧,这里我也不花时间详细解释了。)
SQL> startup --“启动数据库实例”
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218968 bytes
Variable Size 88082024 bytes
Database Buffers 188743680 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
SQL> shutdown immediate --“关闭数据库实例”
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@redhat ~]$ lsnrctl stop --“关闭监听”
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 14-OCT-2009 19:08:06
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC2)))
The command completed successfully
2.用dbstart和dbshut启动和关闭数据库实例
先启动监听 lsnrctl start
启动实例 dbstart
使用dbstart命令启动数据库比较方便,但是在linux上安装好oracle之后,第一次使用dbstart命令可能会报如下错误:
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/oracle/product/10.2.0/db_1/bin/dbstart ORACLE_HOME
原因:
dbstart和dbshut脚本文件中ORACLE_HOME_LISTNER的设置有问题,分别打开两个文件找到:用vi编辑dbstart,ORACLE_HOME_LISTNER=$1,修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
然后保存退出,此时再运行dbstart,已经不报错了,但是没有任何反应,ps一下进程,没有oracle的进程,说明oracle实例没有正常启动。
此时的原因是在/etc/oratab的设置问题,我们vi一下,发现
zgz:/home/oracle/product/10g:N
最后设置的是"N"(我的环境中只有一个实例,因此只有一行配置语句),我们需要把“N”修改为“Y”。
以上的工作做好之后,dbstart就可以正常使用了:
[oracle@redhat bin]$ lsnrctl start --“启动监听”
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 14-OCT-2009 19:44:53
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /home/oracle/product/10g/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /home/oracle/product/10g/network/admin/listener.ora
Log messages written to /home/oracle/product/10g/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC2)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=redhat)(PORT=1522)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC2)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 14-OCT-2009 19:44:53
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/product/10g/network/admin/listener.ora
Listener Log File /home/oracle/product/10g/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC2)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=redhat)(PORT=1522)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@redhat bin]$ dbstart --“启动数据库实例”
Processing Database instance "zgz": log file /home/oracle/product/10g/startup.log
[oracle@redhat bin]$ dbshut --“关闭数据库实例”
[oracle@redhat bin]$ lsnrctl stop --“关闭监听”
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 14-OCT-2009 19:45:33
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC2)))
The command completed successfully
如何使数据库实例和linux系统一起启动
在/etc/rc.d/rc.local中加入如下语句即可实现同系统启动实例:
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart"
(因为课程比较紧,所以匆匆完稿,中途还借鉴了一些大虾的详解,就此对他们表示感谢。同时文章中有此没有说清楚的地方,还请读者见谅)