How to create ASM filesystem(ACFS) in Oracle 11gR2

on

本文描述如何创建ACFS文件系统,前提要求:
1. Oracle 11gR2数据库。
2. 如果是11.2.0.1数据库那么操作系统只支持Linux和Windows,如果是11.2.0.2数据库那么增加支持的操作系统有AIX和Solaris。
3. 已经安装Grid Infrastructure,单机即可(但是ACFS在Oracle Restart环境中会有些限制,详见【备注1】)。
4. 已经创建了ASM实例以及ASM磁盘组,实例中ASM实例名为+ASM,磁盘组为ORADG。

[sourcecode language=”sql”]SQL> alter diskgroup oradg add volume acfsvol size 1G;
alter diskgroup oradg add volume acfsvol size 1G
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15221: ASM operation requires compatible.asm of 11.2.0.0.0 or higher[/sourcecode]

如上的错误表示如果要在ASM磁盘组上创建ACFS Volume,必须要求ASM磁盘组的属性COMPATIBLE.ASM在11.2以上。
如果ASM磁盘组是使用asmca图形化工具创建的,那么compatible.asm默认设置就已经为11.2,但如果是使用CREATE DISKGROUP这个SQL命令创建的,那么默认设置则为10.1,需要手动修改。

[sourcecode language=”sql” toolbar=”false”]SQL> alter diskgroup oradg set attribute ‘COMPATIBLE.ASM’=’11.2’;[/sourcecode]

如果要创建ACFS Volume,还必须要求ASM磁盘组的COMPATIBLE.ADVM属性也在11.2以上,此属性默认为空。

[sourcecode language=”sql”]SQL> alter diskgroup oradg set attribute ‘compatible.advm’=’11.2’;
alter diskgroup oradg set attribute ‘compatible.advm’=’11.2’
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15242: could not set attribute compatible.advm
ORA-15238: 11.2 is not a valid value for attribute compatible.advm
ORA-15477: cannot communicate with the volume driver

SQL> host oerr ora 15477
15477, 00000, "cannot communicate with the volume driver"
// *Cause: An attempt was made to communicate with the volume driver.
// *Action: Check that the ASM volume driver is loaded. If so, check the alert
// log to identify the reason for failure and take necessary action
// to prevent such failures in the future.
//[/sourcecode]

如上的错误表示ASM volume driver没有加载。需要使用root用户手工加载。

# /app/grid/bin/acfsload start -s

然后再次修改ASM磁盘组的COMPATIBLE.ADVM属性,并创建ACFS Volume。

[sourcecode language=”sql”]SQL> alter diskgroup oradg set attribute ‘compatible.advm’=’11.2′;

Diskgroup altered.

SQL> alter diskgroup oradg add volume acfsvol size 1G;

Diskgroup altered.

SQL> select VOLUME_DEVICE from V$ASM_VOLUME where VOLUME_NAME=’ACFSVOL’;

VOLUME_DEVICE
——————————————————————————–
/dev/asm/acfsvol-351[/sourcecode]

创建并注册文件系统,然后使用mount.acfs命令挂载文件系统,以下命令需要用root用户执行。

# mkdir -p /app/oracle/acfsmounts/oradg_acfsvol 
# /sbin/mkfs -t acfs -n ACFSVOL1 /dev/asm/acfsvol-351
mkfs.acfs: version                   = 11.2.0.1.0.0
mkfs.acfs: on-disk version           = 39.0
mkfs.acfs: volume                    = /dev/asm/acfsvol-351
mkfs.acfs: volume size               = 1073741824
mkfs.acfs: Format complete.
# /sbin/acfsutil registry -a -f /dev/asm/acfsvol-351 /app/oracle/acfsmounts/oradg_acfsvol
acfsutil registry: mount point /app/oracle/acfsmounts/oradg_acfsvol successfully added to Oracle Registry
# mount.acfs -o all
#df -k | grep acfs
/dev/asm/acfsvol-351   1048576     39192   1009384   4% /app/oracle/acfsmounts/oradg_acfsvol
# chown oracle:dba /app/oracle/acfsmounts/oradg_acfsvol 

创建成功以后,可以用oracle用户在该文件系统下创建测试文件。

$ dd if=/dev/zero of=/app/oracle/acfsmounts/oradg_acfsvol/testfile bs=8192 count=100
100+0 records in
100+0 records out
819200 bytes (819 kB) copied, 0.0270009 seconds, 30.3 MB/s
$ ls -l /app/oracle/acfsmounts/oradg_acfsvol/testfile
-rw-r--r-- 1 oracle dba 819200 Aug 12 19:18 /app/oracle/acfsmounts/oradg_acfsvol/testfile

查看ACFS文件系统信息。

# /sbin/acfsutil info fs 
/app/oracle/acfsmounts/oradg_acfsvol
    ACFS Version: 11.2.0.1.0.0
    flags:        MountPoint,Available
    mount time:   Thu Aug 12 19:06:33 2010
    volumes:      1
    total size:   1073741824
    total free:   968667136
    primary volume: /dev/asm/acfsvol-351
        label:                 ACFSVOL1
        flags:                 Primary,Available,ADVM
        on-disk version:       39.0
        allocation unit:       4096
        major, minor:          252, 179713
        size:                  1073741824
        free:                  968667136
        ADVM diskgroup         ORADG
        ADVM resize increment: 268435456
        ADVM redundancy:       unprotected
        ADVM stripe columns:   4
        ADVM stripe width:     131072
    number of snapshots:  0
    snapshot space usage: 0

在ASM卷被打开的时候,无法直接shutdown ASM实例,会报ORA-15487错误。

[sourcecode language=”sql” toolbar=”false”]SQL> shutdown immediate
ORA-15487: cannot shutdown the ASM instance with an open ASM volume[/sourcecode]

可以使用umount命令卸载ACFS文件系统。

# /bin/umount -t acfs -a

如果挂载文件系统时报错,那么可能是因为ACFS Volume没有激活,Volume的状态可以从V$ASM_VOLUME.STATE字段获得,显示为“ENABLED”才表示已激活。

# mount.acfs /dev/asm/acfsvol-351 /app/oracle/acfsmounts/oradg_acfsvol
mount.acfs: CLSU-00100: Operating System function: open64 (/dev/asm/acfsvol-351) failed with error data: 2
mount.acfs: CLSU-00101: Operating System error message: No such file or directory
mount.acfs: CLSU-00103: error location: OOF_1
mount.acfs: ACFS-02017: Failed to open volume /dev/asm/acfsvol-351. Verify the volume exists.

如果Volume状态显示为DISABLE,可以使用如下命令,激活Volume。
[sourcecode language=”sql” toolbar=”false”]SQL>alter diskgroup ORADG enable volume ‘ACFSVOL’;[/sourcecode]

本文创建使用的是SQL命令行方式创建ACFS卷,用asmcmd也可以完成,可以参看官方文档 | Surachart的文章

而如果选用图像化界面的话,可以用asmca或者OEM来完成,下图是asmca界面,在其中查看命令行写法也很方便。

【备注1】
在当前版本的Oracle Restart环境(也就是Standalone Grid Infrastructure)中,以下操作不会自动运行。
1. 加载Oracle ACFS drivers
2. 加载存在于ACFS mount registry中的Oracle ACFS文件系统

应对于第一个问题,我们可以通过以下方法让操作系统在启动的时候自动加载Oracle ACFS drivers。

创建/etc/init.d/acfsload文件,让其在操作系统启动时自动运行。

# cat /etc/init.d/acfsload
#!/bin/sh
# chkconfig: 2345 30 21
# description: Load Oracle ACFS drivers at system boot
/app/grid/bin/acfsload start -s

# chmod u+x /etc/init.d/acfsload
# chkconfig --add  acfsload
# chkconfig --list  acfsload   
acfsload        0:off   1:off   2:on    3:on    4:on    5:on    6:off

对于第二个问题,由于ACFS文件系统能够正确加载,必须要求ASM实例启动成功,并且相应的ASM磁盘组正确加载,这份依赖性在集群环境中是通过创建Oracle ACFS registry resource (ora.registry.acfs)来实现的,但是在Standalone环境中,我们无法保证这份依赖性,因此只能通过创建以下脚本用root用户手动挂载ACFS文件系统(如果你们有更好的方法请告诉我)。

# cat /usr/local/sbin/mountacfs 
su - grid -c "asmcmd volenable -G oradg -a"
mount.acfs -o all

2 Comments Add yours

  1. Rain@DNA says:

    不知ACFS有什么好的应用案例,一直觉得它没什么用啊~

  2. kamus says:

    我想Oracle的目标就是现在的ocfs,gpfs,vcfs,gfs,qfs能做什么,acfs就能做什么,它就是一个cluster filesystem。

Leave a Reply to Rain@DNA Cancel reply

Your email address will not be published. Required fields are marked *