在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"
(因爲課程比較緊,所以匆匆完稿,中途還借鑑了一些大蝦的詳解,就此對他們表示感謝。同時文章中有此沒有說清楚的地方,還請讀者見諒)