Redhat linux下安裝oracle 10g
安裝redhat5時要獨立分配磁碟給SWAP,空間大小應該是記憶體大小*2,最好使用記憶體>1G的機器。
系統檢查命令:
# grep MemTotal /proc/meminfo ――檢查記憶體大小
# grep SwapTotal /proc/meminfo ――檢查交換分區大小swap
# df -k /tmp ――要求/tmp 400MB
# grep "model name" /proc/cpuinfo ――cpu檢查
# cat /etc/issue ――作業系統檢查
# uname –r ――系統核心檢查
當前為root超級使用者下進行操作:
1、由於orcale10不支援 redhat as5 需要修改/etc/redhat-realease 將 Red
Hat Enterprise Linux Server release 5 (Tikanga) 改為Red Hat Enterprise
Linux Server release 4 (Tikanga) ,安裝完成後再將其修改回來
2、修改/etc/hosts 檔案將127.0.0.1改為本機IP地址 否則網路檢查通不過
3、檢查安裝所需的軟體包,如果提示依賴性錯誤,先按照提示內容安裝所需軟體包後繼續
setarch-2*
make-3*
glibc-2*
libaio-0*
compat-libstdc++-33-3*
compat-gcc-34-3*
compat-gcc-34-c++-3*
gcc-4*
libXp-1*
openmotif-2*
compat-db-4*
4、修改 /etc/sysctl.conf 核心設定檔,增加/修改以下項目,如沒有自己添加
kernel.shmall = 2097152 # 可以使用的共用記憶體的總量。
kernel.shmmax = 2147483648 # 最大共用記憶體段大小。
kernel.shmmni = 4096 # 整個系統共用記憶體段的最大數目。
kernel.sem = 250 32000 100 128 # 每個訊號對象集的最大訊號對象數;系統範圍內最大訊號對象數;每個訊號對象支援的最大運算元;系統範圍內最大訊號對象集數。
fs.file-max = 65536 # 系統中所允許的檔案控制代碼最大數目。
net.ipv4.ip_local_port_range = 1024 65000 # 應用程式可使用的IPv4連接埠範圍。
net.core.rmem_default = 1048576 # 通訊端接收緩衝區大小的預設值
net.core.rmem_max = 1048576 # 通訊端接收緩衝區大小的最大值
net.core.wmem_default = 262144 # 通訊端發送緩衝區大小的預設值
net.core.wmem_max = 262144 # 通訊端發送緩衝區大小的最大值
運行下面的命令使得核心參數生效:
/sbin/sysctl –p
註:核心參數並非必須修改,可以根據自己實際情況而定。
5、增加下面的內容到檔案 /etc/security/limits.conf 檔案中:
soft nproc 2047
hard nproc 16384
soft nofile 1024
hard nofile 65536
6、增加下面的內容到檔案 /etc/pam.d/login 中:
session required /lib/security/pam_limits.so
session required pam_limits.so
7、因為SELINUX對oracle有影響,所以把secure linux設成無效,編輯檔案 /etc/selinux/config :
SELINUX=disabled
當然你也可以用圖形介面下的工具 (系統 > 管理 > 安全層級和防火牆). 選擇SELinux頁面並且設為無效.
8、新增組和使用者:
groupadd oinstall
groupadd dba
useradd -m -g oinstall -G dba oracle
passwd oracle 自行設定密碼
9、建立Oracle的安裝目錄,並把許可權付給oracle使用者:
例:
mkdir -p /u01/app/oracle/product/10.2.0/db_1
chown -R oracle.oinstall /u01
10、配置環境變數(/etc/profile或.bash_profile),增加一下內容
# Oracle Settings
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin ; export PATH
修改後使用source /etc/profile或.bash_profile 命令使配置生效
11、設定安裝語言設定
登陸oracle使用者
因為中文安裝會有亂碼所以設定用英文安裝 export LC_ALL=en_US
12、開始安裝
進入oracle安裝目錄中,執行./runInstaller
如果提示……/.oui許可權不夠,進入install目錄,執行
chmod u+x .oui
chmod u+x unzip
後再執行./runInstaller便會出現安裝介面
在安裝過程中選擇進階安裝,並將資料庫語言選中文字元集選simple chinese 16GBK---gbk編碼集,在linux下無法識別gbk編號,查詢後中文顯示為亂碼
安裝快完成好的時候,會出現提示,必須以root 的身份執行兩個指令碼
13、安裝完成後
資料庫建立完成後,修改vi /etc/oratab,把orcl:/opt/oracle/oracle/product/10g:N那一行最後的N改成Y,
在/etc/rc.d/rc.local中加入如下:(注意:引號不能缺少,否則導致系統無法啟動)
su - oracle -c “lsnrctl start”
su - oracle -c “dbstart”
如果安裝後出現錯誤,進行卸載後重裝,卸載命令如下:
$./runInstaller -silent -deinstall -removeallfiles -removeAllPatches "REMOVE_HOMES={$ORACLE_HOME}" –responseFile
Linux系統下Oracle的自動啟動服務建立
同時將Oracle自動啟動加到了我的機器中,下面將過程分享一下
一、使用root使用者修改/etc/oratab 檔案:
$ vi /etc/oratab
orcl:/oracle/app/product/10.2.0/db_1:N
改為:
orcl:/oracle/app/product/10.2.0/db_1:Y
也就是將最後的N改為Y
二、使用Oracle使用者修改$ORACLE_HOME/bin/dbstart檔案:
# su - oracle
$ cd $ORACLE_HOME/bin
$ vi dbstart
找到 ORACLE_HOME_LISTNER=.....這行, 修改成
ORACLE_HOME_LISTNER=/u01/app/oracle/product/10.1.0/db_1
或者直接修改成:
ORACLE_HOME_LISTNER=$ORACLE_HOME
三、測試回合 dbshut, dbstart 看能否啟動Oracle 服務及listener服務:
1.修改dbstart和dbshut的記錄檔的許可權:
$su - root
#cd $ORACLE_HOME
#chown oracle:oinstall startup.log
#chown oracle:oinstall shutdown.log
註:startup.log 和shutdown.log 可能沒有,當你運行 ./dbstart 和 ./dbshut 之後才自動建立。
2.執行相應的指令碼進行測試
#su - oracle
$cd $ORACLE_HOME/bin
$./dbstart (./dbshut)
$ ps -efw | grep ora_
$ lsnrctl status
$ ps -efw | grep LISTEN | grep -v grep
四:建立服務
$su - root
# cd /etc/rc.d/init.d/
# vi oradbstart
複製如下指令碼1或者指令碼2內容到oradbstart檔案:
注意點:
(1) #開始的行不能少,否則後面運行chkconfig命令會報錯:oradbstart 服務不支援chkconfig
(2) 根據自己的環境修改環境變數配置部分(藍色字型位置)
(3) 從windows下面儲存的如下指令碼內容,通過ISO複製到linux,再將指令碼複製到oradbstart檔案中後
,在終端下用vi oradbstart命令開啟,一些行後面可能有類似^M的字元,將其刪除,否則在運行後面
的chkconfig命令後,在/etc/rc.d/rcN.d目錄(N為運行層級)下產生的S99oradbstart檔案是空的,可以
用vi查看S99oradbstart檔案,內容應該和/etc/rc.d/init.d/oradbstart檔案內容相同才是正確的
(第三種情況是我在xp下使用虛擬機器VMWARE安裝linux,並將如下指令碼儲存成文字檔,然後製作成ISO
檔案,然後把ISO裡面的檔案的內容複寫到oradbstart時遇到的,這種情況一些行後面類似^M的字元,
用gredit無法看到,只有使用vi才能看到)
--指令碼1(資料庫、監聽、dbconsole、sqlplus)
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for Oracle Databases
# /etc/rc.d/init.d/dbstart
export ORACLE_BASE=/u01/app/oracle/
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
touch /var/lock/Oracle
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl start"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl stop"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
rm -f /var/lock/Oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac
exit 0
--指令碼2(只啟動資料庫和監聽)
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for Oracle Databases
# /etc/rc.d/init.d/oradbstart
export ORACLE_BASE=/u01/app/Oracle/
export ORACLE_HOME=/u01/app/Oracle/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
case "$1" in
start)
su Oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/Oracle
echo "OK"
;;
stop)
echo -n "Shutdown Oracle: "
su Oracle -c $ORACLE_HOME/bin/dbshut
rm -f /var/lock/Oracle
echo "OK"
;;
*)
echo "Usage: 'basename $0' start|stop"
exit 1
esac
exit 0
儲存退出。
開啟終端執行:
$su - root
#chown oracle.oinstall /etc/rc.d/init.d/oradbstart
#chmod 775 /etc/rc.d/init.d/oradbstart
然後執行:
chkconfig --add oradbstart
chkconfig --list oradbstart
chkconfig --list oradbstart運行結果:
oradbstart 0:off 1:off 2:off 3:on 4:on 5:on 6:off
或者運行如下命令
chkconfig --level 345 oradbstart on
五.檢查:
根據上面的運行結果,當相應的運行層級為on時(例如:5:on),在對應的/etc/rc.d/rcN.d(例如:和
5:on對應的是:/etc/rc.d/rc5.d)下面會產生一個檔案:S99oradbstart,使用vi S99oradbstart開啟
該檔案,可以看到該檔案的內容和/etc/rc.d/init.d/oradbstart內容相同,表示配置成功,其實
S99oradbstart是一個到/etc/rc.d/init.d/oradbstart的連結,我們可以使用file命令來查看:
$file /etc/rc.d/rc5.d/S99oradbstart
S99oradbstart:symbolic link to '../init.d/oradbstart
$ps -ef | grep oracle 查看Oracle相關的進程是否啟動了
六.一點說明:
指令檔中的:# chkconfig: 345 99 10
指出3,4,5層級啟動這個服務,99是在相應的/etc/rc.d/rcN.d(N為前面指定的層級,這裡是345)目錄
下產生的連結檔案的序號(啟動優先順序別)S99oradbstart,10為在除前面指出的層級對應
的/etc/rc.d/rcN.d(N為除345之外的層級)目錄產生的連結檔案的序號(服務停止的優先順序別)
K10oradbstart。
命令說明:
ps:監控後台進程
-e 顯示所有進程。
-f 全格式。
-h 不顯示標題。
-l 長格式。
-w 寬輸出。
grep:是linux下用於搜尋輸出內容中所含內容的一個命令。
1.例如我要搜尋名為aaa.txt中的一串字元"bbb",可以用
cat aaa.txt|grep bbb
2.我要搜尋目前的目錄含有bb的檔案,可以用
ls |grep bb
例:ps -efw | grep LISTEN | grep -v grep:查看含有LISTEN的監聽,除去含有grep的監聽。
chkconfig:功能說明:檢查,設定系統的各種服務。
語 法:chkconfig [--add][--del][--list][系統服務] 或 chkconfig [--level <等級代號>][系
統服務][on/off/reset]
補充說明:這是Red Hat公司遵循GPL規則所開發的程式,它可查詢作業系統在每一個執行等級中會執行
哪些系統服務,其中包括各類常駐服務。
參 數:
--add 增加所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啟動的敘述檔案內增
加相關資料。
--del 刪除所指定的系統服務,不再由chkconfig指令管理,並同時在系統啟動的敘述檔案內刪除
相關資料。
--list 列出所指定的系統服務。
--level<等級代號> 指定讀系統服務要在哪一個執行等級中開啟或關畢。
註:runlevel可以認為是系統狀態,形象一點,您可以認為runlevel有點象微軟的windows作業系統中
的Normal,safemode,和Command prompt only。進入每個runlevel都需要啟動或關閉相應的一系列服
務(services),這些服務(services)以初始化指令碼的方式放置於目錄/etc/rc.d/rc?.d/或者/etc/rc?.d
下面(?代表runlevel的對應序號)。
在大多數的linux發行版本中,通常有8個runlevel
Runlevel System State
0 Halt the system
1 Single user mode
2 Basic multi user mode
3 Multi user mode
5 Multi user mode with GUI
6 Reboot the system
S, s Single user mode
多數的案頭的linux系統預設的runlevel是5,使用者登陸時是圖形介面;
而多數的伺服器版本的linux系統預設的runlevel是3,使用者登陸時是字元介面;
runlevel 1和2除了調試之外很少使用;
runlevel s和S並不是直接給使用者使用,而是用來為Single user mode作準備。
一個錯誤的解決
環境變數已經配好,但是仍報錯:
[oracle@dg1 ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
export EDITOR=vi
export ORACLE_SID=dg1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export PATH=/u01/app/oracle/product/10.2.0/db_1/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
export PATH=$ORACLE_HOME/bin:$PATH
umask 022
解決方案:
[oracle@dg1 ~]$ sqlplus /nolog
bash: sqlplus: command not found
[oracle@dg1 ~]$ ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
ln: creating symbolic link `/usr/bin/sqlplus' to `/bin/sqlplus': Permission deni ed
[oracle@dg1 ~]$ su - root
Password:
[root@dg1 ~]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
[root@dg1 ~]# su - oracle
[oracle@dg1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon May 11 12:51:24 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 79694068 bytes
Database Buffers 83886080 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL>