第 4章 . 数据库服务

本章包含配置红帽企业 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 服务范例使用三个脚本,它们必须被放置在 /home/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. 通过点击「主菜单」 => 「系统设置」 => 「服务器设置」 => 「群集」,或在 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 服务。