相信很多童鞋都有過在Linux上安裝Oracle數據庫的痛苦經歷,其中絕大多數都是環境設置的問題。我給大家推薦一個國外大牛寫的Oracle的安裝腳本 OTK,是用Bash寫的,這東東大大簡化了Oracle安裝過程,而且成功率達到99.9999%以上,只要確保你的Linux系統是干淨的,那麼按照這個教程,保證你會安裝成功。
准備工作
OTK針對各種Linux提供了 安裝文檔,本文使用的RHEL5.5_x86_64位,數據庫版本為11gR2,主要參考這個 文檔。
首先准備阿好如下的安裝文件:
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
oratoolkit-1.0.2.1.5-1.noarch.rpm
下載上述文件並放在/var/tmp/oracle目錄下。最好要把你的YUM源指向你的系統安裝光盤或者ISO文件。
安裝OTK
用root登陸,執行如下命令:
# su - root # cd /var/tmp/oracle # ls -1 oratool* oratoolkit-1.0.2.1.5-1.noarch.rpm # rpm -ivh oratoolkit-1.0.2.1.5-1.noarch.rpm Preparing... ########################################### [100%] 1:oratoolkit ########################################### [100%]
otk已經幫我們建立了oracle用戶,下面需要設置Oracle用戶密碼
# passwd oracle Changing password for user oracle. New UNIX password: BAD PASSWORD: it is based on a dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully.
解決環境依賴
這一步最爽,最為頭疼的環境依賴問題輕松就解決了!首先要驗證下你的系統還差什麼沒有滿足要求,OTK腳本提供了智能的環境是否滿足檢查:
# /opt/oracle/otk/current/bin/installManager swReqCheck osSetup11gR2.cfg ...//省略大部分輸出 20130521_165122: Info: Action swReqCheck of installManager ended with 7 WARNINGS
最後的結論告訴你的系統共有幾個警告(我的系統是7個),你可以在輸出日志中查看到底缺了什麼。下面的一組命令很酷,讓你一下子解決所有的問題:
//先拼裝命令 # REQ_FILE_DIR="/opt/oracle/otk/current/conf/installManager/requirement" # REQ_FILE_PATH="$REQ_FILE_DIR/ora11gR2-redhat-5-x86_64.pkg.lst" # YUM_COMMAND=$(echo "yum install") # YUM_COMMAND+=$(egrep -v "#" $REQ_FILE_PATH | grep 32-bit | awk '{ print " "$1".i[356]86" }') # YUM_COMMAND+=$(egrep -v "#" $REQ_FILE_PATH | grep 64-bit | awk '{ print " "$1".x86_64" }') //用echo看看最終拼裝的命令是什麼樣 # echo $YUM_COMMAND //執行命令 # $YUM_COMMAND //再次執行環境檢查 # /opt/oracle/otk/current/bin/installManager swReqCheck osSetup11gR2.cfg ... 20130521_170131: Info: Action swReqCheck of installManager ended successfully //這次驗證成功了,環境已經滿足Oracle安裝要求
增強sqlplus
OTK提供了一個優化增強的sqlplus環境:
# cd /opt/oracle/otk/current/tools/rlwrap/ # ./configure # make # make install # /usr/local/bin/rlwrap -v rlwrap 0.30
使用installManager提取安裝
切換到/opt/oracle/otk/current/conf/installManager目錄,編輯osSetup11gR2.cfg來配置安裝參數,包括內核參數、目錄創建及所有授權等設置,如果你想默認安裝就無需更改這個文件。
# cd /opt/oracle/otk/current/conf/installManager/ # vi osSetup11gR2.cfg # sdiff -s osSetup11gR2.cfg sample/osSetup11gR2.cfg //對比哪些參數修改過 # /opt/oracle/otk/current/bin/installManager osSetup osSetup11gR2.cfg
把Oracle安裝文件移入資源目錄
otk默認讀取oracle安裝文件的目錄是/var/opt/oracle/repository,otk的swInst實例安裝命令會讀取這個目錄:
# cd /var/tmp/oracle # chown oracle:oinstall * # mv linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip /var/opt/oracle/repository/
定制oracle用戶登錄的PS1變量
這一步沒什麼實際意義,就是定制Oracle用戶登錄的提示符。
# su - oracle ------------------------------------------------------ oraToolKit environment variables ------------------------------------------------------ Installation directory : /opt/oracle/otk Release : 1.0.2.1.5 $RUN directory : /opt/oracle/otk/1.0/bin $LOG_BASE directory : /var/opt/oracle/otk/1.0/log ------------------------------------------------------ <SITE|COMPANY>:oracle@stquist1p:sidNotSet$ grep ^SITE .profile.custom.interactive SITE="<SITE|COMPANY>" <SITE|COMPANY>:oracle@stquist1p:sidNotSet$ vi .profile.custom.interactive <SITE|COMPANY>:oracle@stquist1p:sidNotSet$ grep ^SITE .profile.custom.interactive SITE="KuuYee"//修改這一行,可以顯示你喜歡的內容 <SITE|COMPANY>:oracle@stquist1p:sidNotSet$ exit # su - oracle KuuYee:oracle@stquist1p:sidNotSet$
安裝Oracle數據庫
OTK沒有采用Oracle Universal Installer(OUI),而是用swInst來控制整個安裝過程的:
$ bash $ cd $INSTALL_CONF $ cp sample/swInstEeSrv11gR2-Step1-linux-x86_64.cfg . $ installManager swInst swInstEeSrv11gR2-Step1-linux-x86_64.cfg $ su - # /opt/oracle/eesrv/11.2.0/db1/root.sh # exit
創建數據庫實例
OTK采用dbSetup來創建實例,首先要進入$INSTALL_CONF目錄配置實例參數
$ cd $INSTALL_CONF $ ls -1 dbSetup*.cfg dbSetup-dev.cfg dbSetup-prod.cfg dbSetup-test.cfg $ vi dbSetup-prod.cfg //prod為生產模式 $ sdiff -s dbSetup-prod.cfg sample/dbSetup-prod.cfg DB_NAME="idm_test" | DB_NAME="prod" ORACLE_HOME="$ORACLE_BASE/eesrv/11.2.0/db1" | ORACLE_HOME="$ORACLE_BASE/sesrv/11.1.0/db1" NLS_LANG=".AL32UTF8" | NLS_LANG=".UTF8" SYSTEM_SIZE=1G | SYSTEM_SIZE=512M TEMP_SIZE=2G | TEMP_SIZE=512M UNDO_SIZE=2G | UNDO_SIZE=512M USERS_SIZE=100M | USERS_SIZE=10M LISTENER_PORT="1541" | LISTENER_PORT="1531" MEMORY_TARGET=7G | MEMORY_TARGET=512M MEMORY_MAX_TARGET=7G | MEMORY_MAX_TARGET=512M SGA_TARGET=3G | SGA_TARGET=256M PROCESSES=1000 | PROCESSES=100 $ installManager dbSetup dbSetup-prod.cfg //執行這部之前最好先配置下/etc/hosts文件,看下面說明
本文采用dbSetup-prod.cfg生產環境模式配置,我們看到還有dev(開發環境)和test(測試環境),不過我沒試過,有興趣的童鞋可以試試。我在上面列出了我所作出的配置,原文並沒有修改內存參數,我之所以修改是因為實際環境因為內存設置太小導致運行一段時間數據庫經常掛掉,經過多次的調試而得到的經驗值,這裡需要說明下我的數據庫配置:
OS:VMware虛擬機(RHEL5.5)
CPU:8核
內存:32G
硬盤:200GB
上面用sdiff -s dbSetup-prod.cfg sample/dbSetup-prod.cfg命令可以對比下我的參數修改,左面是我的修改參數,右面是原參數,需要特別說明的是第二個參數ORACLE_HOME,一定要自修修改,原來的參數是$ORACLE_BASE/sesrv/11.1.0/db1,要修改為$ORACLE_BASE/eesrv/11.2.0/db1,別改錯了!
installManager dbSetup dbSetup-prod.cfg命令開始安裝數據庫實例,不過我建議你最好先配置下你的/etc/hosts文件,加入下面的內容:
127.0.0.1 你的hostname
接下來就是漫長的等待,大概需要幾十分鐘,具體根據你的機器配置情況。如果你最後看到如下的輸出:
---------------------------------------------------------------------------------------------------- 20130522_091856: Info: Executing libmiscellaneous.getFooter function 20130522_091856: Info: Terminating installManager execution 20130522_091856: Info: Summary log file: /var/opt/oracle/otk/1.0/log-old/installManager/../installManager.log 20130522_091856: Info: Detailed log file: /var/opt/oracle/otk/1.0/log-old/installManager/dbsetup-20130522_090349.log 20130522_091856: Info: Action dbSetup of installManager ended successfully ----------------------------------------------------------------------------------------------------
Congratulations!你安裝成功了。
下面登陸試試:
NoteOTK默認創建了一個otk用戶,密碼也是otk, sys和system默認密碼是manager
$ bash $ sourceProdEnv $ sqlplus sys/manager@idm_dev as sysdba; 或者 $ sqlplus otk/otk@idm_dev SQL*Plus: Release 11.2.0.1.0 Production on Wed May 22 11:05:16 2013 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
使用appctl管理oracle
OTK提供了一個ctl工具來幫我們管理Oracle實例:
$ ctl status all //查看當前狀態 $ ctl stop all //停止數據庫 $ ctl start all //啟動數據庫
使用backupuManager備份oracle
$ cd $BACKUP_CONF $ vi prod.cfg $ sdiff -s prod.cfg sample/prod.cfg DISK_DEVICE_MOUNT_POINT="/" | DISK_DEVICE_MOUNT_POINT="/backup01" $ backupManager full prod.cfg
定時備份Job
$ crontab -l|head -2 # Example 1: Daily physical database backup # 0 2 * * * [ -d $HOME/../current ] && (ksh -c '. ./.profile >/dev/null; backupManager full <sid_1>.cfg <sid_2>.cfg <sid_n>.cfg >/dev/null') $ crontab -e $ crontab -l|head -2 # Example 1: Daily physical database backup 0 2 * * * [ -d $HOME/../current ] && (ksh -c '. ./.profile >/dev/null; backupManager full prod.cfg >/dev/null')
創建EM管理控制台
otk並沒有幫我們創建EM控制台,對於習慣用Web管理的用戶很不方便,我們需要手工創建:
$ emca -config dbcontrol db -repos recreate STARTED EMCA at May 22, 2013 11:18:41 AM EM Configuration Assistant, Version 11.2.0.0.2 Production Copyright (c) 2003, 2005, Oracle. All rights reserved. Enter the following information: Database SID: idm_dev //輸入sid Listener port number: 1541 //監聽輸入端口 Listener ORACLE_HOME [ /opt/oracle/eesrv/11.2.0/db1 ]: //默認回車 Password for SYS user: //輸入密碼manager Password for DBSNMP user: //輸入密碼manager Password for SYSMAN user: //輸入密碼manager Email address for notifications (optional): //默認回車 Outgoing Mail (SMTP) server for notifications (optional): //默認回車 ----------------------------------------------------------------- You have specified the following settings Database ORACLE_HOME ................ /opt/oracle/eesrv/11.2.0/db1 Local hostname ................ localhost.localdomain Listener ORACLE_HOME ................ /opt/oracle/eesrv/11.2.0/db1 Listener port number ................ 1541 Database SID ................ idm_dev Email address for notifications ............... Outgoing Mail (SMTP) server for notifications ............... ----------------------------------------------------------------- Do you wish to continue? [yes(Y)/no(N)]: yes May 22, 2013 11:19:20 AM oracle.sysman.emcp.EMConfig perform INFO: This operation is being logged at /opt/oracle/cfgtoollogs/emca/idm_dev/emca_2013_05_22_11_18_40.log. May 22, 2013 11:19:21 AM oracle.sysman.emcp.EMReposConfig invoke INFO: Dropping the EM repository (this may take a while) ... May 22, 2013 11:19:23 AM oracle.sysman.emcp.EMReposConfig invoke INFO: Repository successfully dropped May 22, 2013 11:19:23 AM oracle.sysman.emcp.EMReposConfig createRepository INFO: Creating the EM repository (this may take a while) ... May 22, 2013 11:24:27 AM oracle.sysman.emcp.EMReposConfig invoke INFO: Repository successfully created May 22, 2013 11:24:30 AM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository INFO: Uploading configuration data to EM repository (this may take a while) ... //可能會等一會 May 22, 2013 11:25:19 AM oracle.sysman.emcp.EMReposConfig invoke INFO: Uploaded configuration data successfully May 22, 2013 11:25:23 AM oracle.sysman.emcp.util.DBControlUtil configureSoftwareLib INFO: Software library configured successfully. May 22, 2013 11:25:23 AM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary INFO: Deploying Provisioning archives ... May 22, 2013 11:25:45 AM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary INFO: Provisioning archives deployed successfully. May 22, 2013 11:25:45 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole INFO: Securing Database Control (this may take a while) ... May 22, 2013 11:25:58 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole INFO: Database Control secured successfully. May 22, 2013 11:25:58 AM oracle.sysman.emcp.util.DBControlUtil startOMS INFO: Starting Database Control (this may take a while) ... May 22, 2013 11:26:28 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration INFO: Database Control started successfully May 22, 2013 11:26:28 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration INFO: >>>>>>>>>>> The Database Control URL is https://localhost.localdomain:1158/em <<<<<<<<<<< //這個是EM的訪問鏈接 May 22, 2013 11:26:31 AM oracle.sysman.emcp.EMDBPostConfig invoke WARNING: ************************ WARNING ************************ Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted. The encryption key has been placed in the file: /opt/oracle/eesrv/11.2.0/db1/localhost.localdomain_idm_dev/sysman/config/emkey.ora. Please ensure this file is backed up as the encrypted data will become unusable if this file is lost. *********************************************************** Enterprise Manager configuration completed successfully FINISHED EMCA at May 22, 2013 11:26:31 AM OK! 大功告成,相信各位童鞋都安裝成功了,OTK的安裝還是很穩健的,至少我安裝了幾十次都成功了! 最後祝各位童鞋好運! 2013-05-21