第 4章. 資料庫服務

這個章節含有關於設定 Red Hat Enterprise Linux 以使得資料庫服務能被高度存取的指示。

注請注意
 

下列的說明呈現範例資料庫設定指示,請注意每一種資料庫產品的較新版本都會有不同處,因此這裡所提供的資訊也許無法直接適用。

4.1. 設定一個 Oracle 服務

一個資料庫服務可以伺服高度存取的資料給資料庫應用程式,然後該應用程式便可以提供網路存取給資料庫用戶端系統, 例如網頁伺服器。 假如該服務發生容錯移轉的現象,應用程式將會透過新的叢集系統存取共用的資料庫資料。 通常都會指派一個 IP 位址給可被網路存取的資料庫服務,該位址將會隨著服務一起容錯移轉以維持用戶端透通式的存取。

這裡提供為一個 Oracle 資料庫設定叢集服務的一個範例,雖然服務程式碼所使用的變數取決於特定的 Oracle 設定,這個例子也許會幫助設定個別環境的一個服務,請參考 第 4.2 節 以取得關於增進服務效能的資訊。

在以下的例子中:

建立一致的使用者/群組設定,以提供每一部叢集系統適當地存取 Oracle 服務,例如:

mkdir /users
groupadd -g 900 dba
groupadd -g 901 oinstall
useradd -u 901 -g 901 -d /users/oracle -m oracle
usermod -G 900 oracle

這個 Oracle 服務的範例使用必須放置在 /users/oracle 中並且由 Oracle 管理帳號 所擁有的三個程式碼,可以使用這個 oracle 程式碼來啟動與停止 Oracle 服務。 當您新增服務時,請指定這個程式碼。 這個程式碼將會呼叫其他的 Oracle 範例程式碼,startdbstopdb 程式碼將會啟動與停止資料庫的運作。 請注意一個應用程式有許多種方式 可用來與一個 Oracle 資料庫互動。

下列為 oracle 程式碼的一個範例,可使用來啟動、停止與檢查 Oracle 服務的狀態。

#!/bin/sh
#
# Cluster service script to start, stop, and check status of oracle
#

cd /users/oracle

case $1 in
start)
    su - oracle -c ./startdb
    ;;
stop)
    su - oracle -c ./stopdb
    ;;
status)
    status oracle
    ;; 
esac

下列為 startdb 程式碼的一個範例,可使用來啟動 Oracle 資料庫伺服器:

#!/bin/sh
#

#
# Script to start the Oracle Database Server instance.
#
########################################################################
#
# ORACLE_RELEASE
#
# Specifies the Oracle product release.
#
########################################################################

ORACLE_RELEASE=9.2.0

########################################################################
#
# ORACLE_SID
#
# Specifies the Oracle system identifier or "sid", which is the name of
# the Oracle Server instance.
#
########################################################################

export ORACLE_SID=TEST

########################################################################
#
# ORACLE_BASE
#
# Specifies the directory at the top of the Oracle software product and
# administrative file structure.
#
########################################################################

export ORACLE_BASE=/u01/app/oracle

########################################################################
#
# ORACLE_HOME
#
# Specifies the directory containing the software for a given release.
# The Oracle recommended value is $ORACLE_BASE/product/<release>
#
########################################################################

export ORACLE_HOME=/u01/app/oracle/product/${ORACLE_RELEASE}

########################################################################
#
# LD_LIBRARY_PATH
#
# Required when using Oracle products that use shared libraries.
#
########################################################################

export LD_LIBRARY_PATH=${ORACLE_HOME}/lib:$LD_LIBRARY_PATH

########################################################################
#
# PATH
#
# Verify that the users search path includes $ORACLE_HOME/bin 
#
########################################################################

export PATH=$PATH:${ORACLE_HOME}/bin

########################################################################
#
# This does the actual work.
#
# Start the Oracle Server instance based on the initSID.ora
# initialization parameters file specified.
# 
########################################################################

/u01/app/oracle/product/9.2.0/bin/sqlplus << EOF
sys as sysdba
spool /home/oracle/startdb.log
startup pfile = /u01/app/oracle/product/9.2.0/admin/test/scripts/init.ora open;
spool off
quit;
EOF

exit

下列為 stopdb 程式碼的一個範例,可使用來停止 Oracle 資料庫伺服器:

#!/bin/sh
#
#
# Script to STOP the Oracle Database Server instance.
#
######################################################################
#
# ORACLE_RELEASE
#
# Specifies the Oracle product release.
#
######################################################################

ORACLE_RELEASE=9.2.0

######################################################################
#
# ORACLE_SID
#
# Specifies the Oracle system identifier or "sid", which is the name 
# of the Oracle Server instance.
#
######################################################################

export ORACLE_SID=TEST

######################################################################
#
# ORACLE_BASE
#
# Specifies the directory at the top of the Oracle software product
# and administrative file structure.
#
######################################################################

export ORACLE_BASE=/u01/app/oracle

######################################################################
#
# ORACLE_HOME
#
# Specifies the directory containing the software for a given release.
# The Oracle recommended value is $ORACLE_BASE/product/<release>
#
######################################################################

export ORACLE_HOME=/u01/app/oracle/product/${ORACLE_RELEASE}

######################################################################
#
# LD_LIBRARY_PATH
#
# Required when using Oracle products that use shared libraries.
#
######################################################################

export LD_LIBRARY_PATH=${ORACLE_HOME}/lib:$LD_LIBRARY_PATH

######################################################################
#
# PATH
#
# Verify that the users search path includes $ORACLE_HOME/bin 
#
######################################################################

export PATH=$PATH:${ORACLE_HOME}/bin

######################################################################
#
# This does the actual work.
#
# STOP the Oracle Server instance in a tidy fashion.
# 
######################################################################

/u01/app/oracle/product/9.2.0/bin/sqlplus << EOF
sys as sysdba
spool /home/oracle/stopdb.log
shutdown abort;
spool off
quit;
EOF

exit

4.1.1. Oracle 與 叢集設定工具

如要使用 叢集設定工具 來新增一項 Oracle 服務,請執行下列的指令:

  1. 如要啟動 叢集設定工具,請選擇 『主選單』 => 『系統設定』 => 『伺服器設定』 => Cluster, 或者在 shell 提示符號下輸入 redhat-config-cluster 指令,預設將會出現 叢集狀態工具

  2. 請從 叢集狀態工具 程式選單中選取 『叢集』 => 『設定』 來啟動 叢集設定工具

  3. 點選 『服務』 標簽頁。

  4. 新增 Oracle 服務。

    • 點選 新增 的按鈕,將會出現 『服務』 的對話窗。

      圖形 4-1. 新增一個 Oracle 服務

    • 為 Oracle 服務輸入一個 『服務名稱』。

    • 請選擇一個 『容錯移轉網域』,或者使其保留為 None

    • 請輸入要透過 init 程式碼的 status 功能來檢查 Oracle 服務使用狀況的秒數。

    • 請輸入一個 『使用者程式碼』,例如 /home/oracle/oracle

    • 點選 確定

  5. 新增一個 Oracle 服務的 IP 位址。

    • 選取 Oracle 服務再點選 新增子程式

    • 選取 新增服務的 IP 位址,再點選 確定,將會出現 『服務 IP 位址』 的對話窗。

    • 請輸入一個 『IP 位址』。

    • 請輸入一個 『網路遮罩』,或者是將它保留為 None

    • 請輸入一個 『廣播位址』,或者是將它保留為 None

    • 點選 確定

  6. 為 Oracle 服務與管理檔案新增一個裝置。

    • 選取 Oracle 服務再點選 新增子程式

    • 選取 『新增裝置』,再點選 確定,將會出現 『裝置』 對話窗。

    • 請輸入 『裝置特殊檔案』(例如 /dev/sdb5)。

    • 請在 『掛載點』 欄位輸入 /u01

    • 請在 『檔案系統類型』 中選取檔案系統類型,或者是將它保留空白。

    • 請輸入任何掛載點 『選項』,包括 rw(讀取/寫入)。

    • 選取或取消選取 『強制卸載』。

    • 點選 確定

  7. 為 Oracle 資料庫檔案新增一個裝置。

    • 選取 Oracle 服務再點選 新增子程式

    • 選取 『新增裝置』,再點選 確定,將會出現 『裝置』 對話窗。

    • 輸入 『裝置特殊檔案』(例如 /dev/sdb6)。

    • 請在 『掛載點』 欄位輸入 /u02

    • 請在 『檔案系統類型』 中選取檔案系統類型,或者是將它保留空白。

    • 請輸入任何掛載點 『選項』,包括 rw(讀取/寫入)。

    • 選取或取消選取 『強制卸載』。

    • 點選 確定

  8. 選擇 『檔案』 => 『儲存』 來儲存 Oracle 服務。