注意:以下命令使用 root 用戶操作
安裝依賴包
主要思路為配置 oracle yum 倉庫,直接使用 yum 命令來安裝依賴包,避免手工逐個的安裝依賴包。
配置 yum 倉庫以下載 orcale 依賴包
注意:這里是CentOS 6.X 的 oracle 依賴倉庫,其他版本不同的。
導入 GPG Keys
wget https://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle --no-check-certificate
安裝 oracle 依賴
yum install oracle-rdbms-server-11gR2-preinstall
設置 hostname
打開文件 /etc/sysconfig/network,并修改 HOSTNAME。
vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=oracle.buzheng.org
打開 /etc/host, 添加服務器本機IP地址 指向到 HOSTNAME
vi /etc/hosts192.168.1.15 oracle.buzheng.org oracle
oracle 用戶設置
當安裝好 oracle 依賴之后, oracle 用戶已經創建好了,不需要手工創建 oracle 用戶和相關的用戶組。
修改 oracle 用戶密碼
[root@oracle ~]# passwd oracle更改用戶 oracle 的密碼 。新的 密碼:重新輸入新的 密碼:passwd: 所有的身份驗證令牌已經成功更新。
修改系統限制
在文件 /etc/security/limits.d/90-nproc.conf 中添加如下的最后一行
[root@oracle ~]# vi /etc/security/limits.d/90-nproc.conf# Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning.* soft nproc 1024root soft nproc unlimited* - nproc 16384
修改 SELinux 為 permissive 模式
修改文件 /etc/selinux/config 如下所示
[root@oracle ~]# vi /etc/selinux/config# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=permissive# SELINUXTYPE= can take one of these two values:# targeted - Targeted processes are protected,# mls - Multi Level Security protection.SELINUXTYPE=targeted
重啟機器
[root@oracle]# reboot
創建 oracle 安裝目錄,并授權
[root@oracle]# mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1[root@oracle]# chown -R oracle:oinstall /u01[root@oracle]# chmod -R 775 /u01
授權 oracle 用戶能夠訪問 X Server
[root@oracle]# xhost + # 要在主機上運行,不能是遠程 shell
注意:以下命令使用 oracle 用戶操作
配置 oracle 安裝環境變量
切換到 oracle 用戶, 編輯 .bash_profile 文件, 如下所示, 添加環境配置。
[root@oracle]# su oracle[oracle@oracle]# vi .bash_profile# Oracle SettingsTMP=/tmp; export TMPTMPDIR=$TMP; export TMPDIRORACLE_HOSTNAME=oracle.buzheng.org; export ORACLE_HOSTNAMEORACLE_UNQNAME=orcl; export ORACLE_UNQNAMEORACLE_BASE=/u01/app/oracle; export ORACLE_BASEORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOMEORACLE_SID=orcl; export ORACLE_SIDPATH=/usr/sbin:$PATH; export PATHPATH=$ORACLE_HOME/bin:$PATH; export PATHLD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATHCLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH export PATH
下載 oracle 安裝文件,解壓縮后安裝
下載 oracle
打開 oracle 下載頁面,http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html , 下載下面兩個文件到 /home/oracle
linux.x64_11gR2_database_1of2.ziplinux.x64_11gR2_database_2of2.zip
解壓縮文件并運行
unzip linux.x64_11gR2_database_1of2.zipunzip linux.x64_11gR2_database_2of2.zipcd database./runInstaller
若為中文系統,安裝界面會出現中文亂碼,需要先將環境變為英文,在安裝
export LANG=en_US./runInstaller
沒有截圖, 安裝步驟大致包括以下幾步:
圖性界面安裝最后會提示以ROOT 執行下面兩個腳本
[root@oracle ~]# /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInventory.Adding read,write permissions for group.Removing read,write,execute permissions for world.Changing groupname of /u01/app/oraInventory to oinstall.The execution of the script is complete.
[root@oracle ~]# /u01/app/oracle/product/11.2.0/dbhome_1/root.sh Running Oracle 11g root.sh script...The following environment variables are set as: ORACLE_OWNER= oracle ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1Enter the full pathname of the local bin directory: [/usr/local/bin]: Copying dbhome to /usr/local/bin ... Copying oraenv to /usr/local/bin ... Copying coraenv to /usr/local/bin ...Creating /etc/oratab file...Entries will be added to the /etc/oratab file as needed byDatabase Configuration Assistant when a database is createdFinished running generic part of root.sh script.Now product-specific root actions will be performed.Finished product-specific root actions.
出現的問題
1, 當環境變量中的 ORACLE_SID 與 安裝時實際配置不一致時,會導致 startup 出錯,出錯信息如下:
ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initDB11G.ora'
2, 如果遠程客戶端連接是報錯:ora-12514 tns 監聽程序當前無法識別連接描述符中請求的服務,則需要配置 listener.ora,添加如下節點:
SID_LIST_LISTENER = (SID_LIST= (SID_DESC = (SID_NAME = orcl) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) ) )
好了,到此已經安裝完成,通過訪問 web 管理界面可驗證。下面步驟也很重要,請繼續。
注意:以下命令使用 root 用戶操作
配置防火墻規則,開放偵聽端口
將 1521(你配置的 oracle 偵聽端口) 端口添加到防火墻規則,以便遠程用戶能順利的訪問到 oracle 服務。
iptables -I INPUT 4 -m state --state NEW -p tcp --dport 1521 -j ACCEPTservice iptables saveservice iptables reload
設置 oracle 自動啟動
完成 oracle 安裝后,我們可以通過命令啟動停止數據庫,但是當機器重啟時并不能隨機器啟動,這也給我們帶來了一些不便,下面記錄了,如何將 oralce 加入服務中,并隨機機器啟動。
修改配置文件 /etc/oratab
修改 /etc/oratab 的最后一行的最后一個字符,將 N 修改為 Y。此舉主要是為了使 oracle 的 dbstart 命令能在系統啟動時能運行。如下所示:
[root@oracle ~]# vi /etc/oratab## This file is used by ORACLE utilities. It is created by root.sh# and updated by the Database Configuration Assistant when creating# a database.# A colon, ':', is used as the field terminator. A new line terminates# the entry. Lines beginning with a pound sign, '#', are comments.## Entries are of the form:# $ORACLE_SID:$ORACLE_HOME:<N|Y>:## The first and second fields are the system identifier and home# directory of the database respectively. The third filed indicates# to the dbstart utility that the database should , "Y", or should not,# "N", be brought up at system boot time.## Multiple entries with the same $ORACLE_SID are not allowed.##orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
創建 /etc/init.d/oracle
在 /etc/init.d/下創建文件 oracle,此為 oracle 自啟動腳本。內容如下:
#!/bin/sh# chkconfig: 345 61 61# description: Oracle 11g R2 AutoRun Servimces# /etc/init.d/oracle## Run-level Startup script for the Oracle Instance, Listener, and# Web InterfaceORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"ORA_OWNR="oracle"# if the executables do not exist -- display errorif [ ! -f "$ORACLE_HOME/bin/dbstart" ]thenecho "Oracle startup: cannot start"exit 1fi# parameter: start, stop, restartcase "$1" instart)# Oracle listener and instance startupsu $ORA_OWNR -s /bin/bash $ORACLE_HOME/bin/dbstart $ORACLE_HOMEecho "Oracle Start Succesful!OK.";;stop)# Oracle listener and instance shutdownsu $ORA_OWNR -s /bin/bash $ORACLE_HOME/bin/dbshut $ORACLE_HOMEecho "Oracle Stop Succesful!OK.";;restart)$0 stop$0 start;;*)echo $"Usage: `basename $0` {start|stop|restart}"exit 1esacexit 0
賦予啟動腳本執行權限并鏈接好:
# chmod 750 /etc/init.d/oracle# ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle# ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle
啟動腳本設置好了之后,可以使用 service 命令來啟動停止 oracle 了,這時候 oracle 已經是系統服務了。
service oracle startservice oracle stopservice oracle restart
設置 oracle 服務為自啟動
# chkconfig --add oracle# chkconfig --level 345 oracle on
總結
好了,重啟機器試試吧。以上就是這篇文章的全部內容了,希望本文的內容對大家學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點
疑難解答