恭喜!您的 Oracle 数据库 11g 第 1 版数据库现在已经就绪,可以使用了。 第 4 部分:配置存储
我们在第 3 部分中创建的数据库使用单一文件系统进行磁盘存储。但为 Oracle 数据库配置存储的方式还有其他许多种。
本部分介绍了为数据库配置磁盘存储的其他方法。尤其是,它描述了如何创建其他文件系统以及如何使用自动存储管理 (ASM)。 对磁盘进行分区
为了使用文件系统或 ASM,您必须有未分配的磁盘分区。该部分将介绍如何创建新文件系统或 ASM 使用的分区。
警告:对磁盘进行错误分区是删除硬盘上所有内容的最可靠、最快捷的方法之一。如果不确定如何分区,请先停下来,找人帮帮您,否则您将冒丢失数据的危险。
此示例使用 /dev/sda(一个没有分区的空磁盘)为整个磁盘创建一个分区。
Ex:
# fdisk /dev/sda
The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30401, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401):
Using default value 30401
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
现在验证新分区:
Ex:
# fdisk -l /dev/sda
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 30401 244196001 83 Linux
对每个要分区的磁盘重复上述步骤。接下来的“文件系统”部分使用了一个单一磁盘分区 /dev/sda1。ASM 示例使用了两张磁盘:/dev/sda1 和 /dev/sdb1。 文件系统
文件系统是为 Oracle 数据库存储数据文件、重做日志和控制文件最常用的方法。文件系统易于实施,并且无需第三方软件来管理。
大多数情况下,文件系统在 Linux 的初始安装过程中创建。但有时必须在初始安装后(如安装新磁盘驱动器后)创建新文件系统。
本部分介绍了如何构建新文件系统以及如何在 Oracle 数据库中使用它。除非另有说明,否则必须以 root 用户身份运行所有命令。 创建文件系统
使用 ext3 创建这个新的文件系统。也可以使用其他文件系统,但 ext3 在系统崩溃时可提供最快的恢复。
Ex:
# mke2fs -j /dev/sda1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30539776 inodes, 61049000 blocks
3052450 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1864 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. 创建挂载点
文件系统必须有一个挂载点,它只是一个空的目录,新文件系统在这里与系统目录树“相连”。挂载点的命名应遵循 Oracle 灵活结构 (OFA) 标准。有关 OFA 标准的更多信息,请参阅 针对 Linux 的 Oracle 数据库安装指南 11g 第 1 版 (11.1)
的 附录 D
。
由于第 1 部分中已经创建了 /u01 目录,本例将使用 /u02。
Ex:
# mkdir /u02
将新文件系统添加到 /etc/fstab
因此新文件系统将在系统启动时自动挂载,您需要向描述新文件系统及其安装位置的 /etc/fstab 文件中添加一行。使用文本编辑器向 /etc/fstab 中添加如下所示的一行。
/dev/sda1 /u02 ext3 defaults 1 2 挂载新文件系统
文件系统挂载后就可以使用了。只有挂载了文件系统,才能在其中存储文件。使用以下命令挂载文件系统并验证它是否可用。
mount /u02
df -h /u02
Ex:
# mount /u02
# df -h /u02
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 230G 188M 218G 1% /u02 创建 Oracle 目录并设置权限
现在,创建一个用于存放您的 Oracle 数据库文件的目录。该示例中使用的目录名遵循数据库的 OFA 标准命名惯例,即 ORACLE_SID=demo1。
mkdir -p /u02/app/oracle/oradata/demo1
chown -R oracle:oinstall /u02/app
chmod -R 775 /u02/app 在新文件系统中创建一个新表空间
新文件系统已可以使用。接下来,在文件系统中创建一个用于存储数据库对象的新表空间。以 SYSTEM 用户身份连接到数据库,然后执行 CREATE TABLESPACE 语句,并在新文件系统中指定数据文件。
Ex:
$ sqlplus
SQL*Plus: Release 11.1.0.6.0 - Production on Sun Nov 4 15:19:00 2007
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create tablespace data1
2 datafile '/u01/app/oracle/oradata/demo1/data1_01.dbf' size 100m
3 extent management local
4 segment space management auto;
Tablespace created.
现在,可以使用此新表空间存储数据库对象,如表和索引。
Ex:
SQL> create table demotab (id number(5) not null primary key,
2 name varchar2(50) not null,
3 amount number(9,2))
4 tablespace data1;
接着,下载与您的内核相对应的 oracleasm 程序包。上例中使用了 oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm 程序包。注意,大多数内核版本的下方都会列出两个或三个驱动程序。例如:
针对内核 2.6.18-8.el5 的驱动程序
* oracleasm-2.6.18-8.el5xen-2.0.4-1.el5.i686.rpm
* oracleasm-2.6.18-8.el5PAE-2.0.4-1.el5.i686.rpm
* oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm
仅选择其中之一。在本例中,还提供了针对 Xen(虚拟机体系结构)、PAE(针对 RAM 超过 4GB 的 32 位系统)和“标准”32 位内核的驱动程序。
接下来,通过以 root 用户身份执行以下命令来安装程序包:
rpm -Uvh oracleasm-kernel_version-asmlib_version.cpu_type.rpm \
oracleasmlib-asmlib_version.cpu_type.rpm \
oracleasm-support-asmlib_version.cpu_type.rpm
Ex:
# rpm -Uvh oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm \
> oracleasm-support-2.0.4-1.el5.i386.rpm \
oracleasmlib-2.0.3-1.el5.i386.rpm
Preparing... ########################################### [100%]
1:oracleasm-support ########################################### [ 33%]
2:oracleasm-2.6.18-8.el5 ########################################### [ 67%]
3:oracleasmlib ########################################### [100%] 配置 ASMLib
使用 ASMLib 之前,必须运行配置脚本来准备驱动程序。以 root 用户身份运行以下命令,并响应如下示例中所显示的提示。
# /etc/init.d/oracleasm configure
Configuring the Oracle ASM library driver.
This will configure the on-boot properties of the Oracle ASM library
driver. The following questions will determine whether the driver is
loaded on boot and what permissions it will have. The current values
will be shown in brackets ('[]'). Hitting without typing an
answer will keep that current value. Ctrl-C will abort.
Default user to own the driver interface []: oracle
Default group to own the driver interface []: dba
Start Oracle ASM library driver on boot (y/n) [n]: y
Fix permissions of Oracle ASM disks on boot (y/n) [y]: y
Writing Oracle ASM library driver configuration: [ OK ]
Loading module "oracleasm": [ OK ]
Mounting ASMlib driver filesystem: [ OK ]
Scanning system for ASM disks: [ OK ]
接下来,告诉 ASM 驱动程序您要使用的磁盘。Oracle 建议每个磁盘仅包含一个分区。有关创建分区的示例,请参见本部分起始处的“对磁盘进行分区”。
通过以 root 用户身份运行以下命令来标记 ASMLib 使用的磁盘:
/etc/init.d/oracleasm createdisk DISK_NAME device_name
提示:DISK_NAME 应由大写字母组成。
Ex:
# /etc/init.d/oracleasm createdisk VOL1 /dev/sda1
Marking disk "/dev/sdb1" as an ASM disk: [ OK ]
# /etc/init.d/oracleasm createdisk VOL2 /dev/sdb1
Marking disk "/dev/sdb1" as an ASM disk: [ OK ]Verify that ASMLib has marked the disks: # /etc/init.d/oracleasm listdisks
VOL1
VOL2 创建 ASM 实例
ASM 作为独立的 Oracle 实例运行,可以使用 Oracle Universal Installer 创建和配置它。安装完 ASMLib 并标记磁盘后,就可以创建 ASM 实例了。
以 oracle 身份登录并启动 runInstaller:
$ ./runInstaller