Oracle ASM Filter Driver介绍

1. 概述

在安装完Oracle 12c RAC后,想对OCR所在的磁盘进行破坏性测试,发现了一个Oracle 12c比较有用的特性,就是Oracle ASM Filter Driver,简写为Oracle ASMFD,先来看一看这个特性的好处:

$ dd if=/dev/zero of=/dev/mapper/asm-ocr3 bs=1024k count=50
$ kfed read /dev/mapper/asm-ocr3 | more
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          2 ; 0x003: 0x02
kfbh.block.blk:                       0 ; 0x004: blk=0
kfbh.block.obj:              2147483650 ; 0x008: disk=2
kfbh.check:                   676930498 ; 0x00c: 0x285923c2
kfbh.fcn.base:                     4115 ; 0x010: 0x00001013
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
……

在对OCR所在的磁盘进行dd清理后,发现该盘的磁盘头依然正确,没有被清理掉,这其实就是Oracle ASMFD在起作用。
Oracle ASMFD是个内核模块,会对向Oracle ASM盘写入的IO进行校验,如果IO不是由Oracle产生的,那么向ASM盘写入的IO就会被忽略,这个特性可以很好地保护由于系统管理员或DBA的疏忽而导致的格式化错误。在Oracle 12c之前,弄错盘而导致数据库出故障的案例还是很多的。

2. ASMFD启用后的情况

默认情况下,Oracle 12c RAC安装后,Oracle ASMFD就是默认启用状态

$ asmcmd afd_state
ASMCMD-9526: The AFD state is 'LOADED' and filtering is 'ENABLED' on host 'it12ctest01'
$  asmcmd afd_lsdsk
---------------------------------------------------------------------------
Label                     Filtering   Path
===========================================================================
CRSDG1                      ENABLED   /dev/mapper/asm-ocr2
CRSDG2                      ENABLED   /dev/mapper/asm-ocr1
CRSDG3                      ENABLED   /dev/mapper/asm-ocr3
GIRMDG1                     ENABLED   /dev/mapper/asm-disk1

Oracle ASMFD主要是由oracleafd这个内核模块起作用。

# lsmod | grep ora
oracleacfs           4597925  0
oracleadvm            776830  0
oracleoks             654476  2 oracleacfs,oracleadvm
oracleafd             205543  0

查看ASM磁盘,DiskGroup使用的磁盘名是带AFD前缀的路径

3. 如何关闭Oracle ASMFD

如果需要dd格式化ASM盘,比如:重装RAC时,就需要将ASMFD关闭,这样才能格式化掉ASM磁盘,否则就无法格式化。
关闭ASMFD的步骤如下:

  • 停止CRS
  • 卸载ACFS
  • # /oracle/app/grid/bin/acfsload stop
    # lsmod | grep ora
    oracleafd             205543  0
    
  • 禁用ASMFD
  • # /oracle/app/grid/bin/asmcmd afd_filter -d
    # /oracle/app/grid/bin/asmcmd afd_state
    ASMCMD-9526: The AFD state is 'LOADED' and filtering is 'DISABLED' on host 'it12ctest01'
    
  • 清理Label
  • $ asmcmd afd_lsdsk
    -----------------------------------------------------------------------
    Label                     Filtering   Path
    =======================================================================
    CRSDG1                     DISABLED   /dev/mapper/asm-ocr2
    CRSDG2                     DISABLED   /dev/mapper/asm-ocr1
    CRSDG3                     DISABLED   /dev/mapper/asm-ocr3
    GIRMDG1                    DISABLED   /dev/mapper/asm-disk1
    $ ls -ltr /dev/oracleafd/disks/
    total 16
    -rwxrwx--- 1 grid oinstall 21 May 16 16:14 CRSDG1
    -rwxrwx--- 1 grid oinstall 21 May 16 16:14 CRSDG2
    -rwxrwx--- 1 grid oinstall 21 May 16 16:14 CRSDG3
    -rwxrwx--- 1 grid oinstall 22 May 16 16:20 GIRMDG1
    # /oracle/app/grid/bin/asmcmd afd_unlabel CRSDG1 -f
    # /oracle/app/grid/bin/asmcmd afd_unlabel CRSDG2 -f
    # /oracle/app/grid/bin/asmcmd afd_unlabel CRSDG3 -f
    # /oracle/app/grid/bin/asmcmd afd_unlabel GIRMDG1 -f
    # ls -ltr /dev/oracleafd/disks/
    total 0
    
  • deconfigure asmfd
  • # /oracle/app/grid/bin/asmcmd afd_deconfigure
    AFD-632: Existing AFD installation detected.
    AFD-634: Removing previous AFD installation.
    AFD-635: Previous AFD components successfully removed.
    Modifying resource dependencies - this may take some time.
    # ls -ltr /dev/oracleafd/disks/
    ls: cannot access /dev/oracleafd/disks/: No such file or directory
    
  • 启动CRS
  • 启动CRS后,观察ASM的磁盘,已经变成了正常路径

    这时侯,就可以对磁盘进行正常的dd格式化处理。

    4. 如何启用Oracle ASMFD

    启用Oracle ASMFD的过程也比较简单,如下:

  • 检查ASM 磁盘搜索路径
  • $ asmcmd dsget
    parameter:/dev/mapper/asm*, AFD:*
    profile:/dev/mapper/asm*,AFD:*
    

    这里已经带AFD:*了,如果检查出来不带AFD:*,需要设置如下:

    $ asmcmd dsset '/dev/mapper/asm*','AFD:*'
    
  • 检查node
  • $ olsnodes -a
    it12ctest01     Hub
    it12ctest02     Hub
    
  • 停止两个节点的CRS
  • 启用ASMFD
  • # /oracle/app/grid/bin/asmcmd afd_configure
    AFD-627: AFD distribution files found.
    AFD-634: Removing previous AFD installation.
    AFD-635: Previous AFD components successfully removed.
    AFD-636: Installing requested AFD software.
    AFD-637: Loading installed AFD drivers.
    AFD-9321: Creating udev for AFD.
    AFD-9323: Creating module dependencies - this may take some time.
    AFD-9154: Loading 'oracleafd.ko' driver.
    AFD-649: Verifying AFD devices.
    AFD-9156: Detecting control device '/dev/oracleafd/admin'.
    AFD-638: AFD installation correctness verified.
    Modifying resource dependencies - this may take some time.
    

    检查启用后状态

    $ asmcmd afd_state
    ASMCMD-9526: The AFD state is 'LOADED' and filtering is 'ENABLED' on host 'it12ctest01'
    SQL> SELECT SYS_CONTEXT('SYS_ASMFD_PROPERTIES', 'AFD_STATE') FROM DUAL;
     
    SYS_CONTEXT('SYS_ASMFD_PROPERTIES','AFD_STATE')
    -------------------------------------------------
    CONFIGURED
    $ ls -ltr /dev/oracleafd/disks/
    total 0
    $ lsmod | grep ora
    oracleafd             205543  1
    oracleacfs           4597925  0
    oracleadvm            776830  0
    oracleoks             654476  2 oracleacfs,oracleadvm
    
  • 设置LABEL
  • 由于当前的几块盘已经给ASM管理了,所以需要带上—migrate,这个命令只需要在1个节点上执行即可。

    $ asmcmd afd_label 'CRSDG1' '/dev/mapper/asm-ocr1' --migrate
    $ asmcmd afd_label 'CRSDG2' '/dev/mapper/asm-ocr2' --migrate
    $ asmcmd afd_label 'CRSDG3' '/dev/mapper/asm-ocr3' --migrate
    $ asmcmd afd_label 'GIRMDG1' '/dev/mapper/asm-disk1' --migrate
    $ ls -ltr /dev/oracleafd/disks/
    total 16
    -rw-r--r-- 1 grid oinstall 21 May 22 11:05 CRSDG1
    -rw-r--r-- 1 grid oinstall 21 May 22 11:06 CRSDG2
    -rw-r--r-- 1 grid oinstall 21 May 22 11:06 CRSDG3
    -rw-r--r-- 1 grid oinstall 22 May 22 11:06 GIRMDG1
    
  • 重启CRS
  • 这时侯,磁盘又处理Oracle ASMFD的保护之下

    $ dd if=/dev/zero of=/dev/mapper/asm-ocr3 bs=1024k count=50
    50+0 records in
    50+0 records out
    52428800 bytes (52 MB) copied, 0.0456157 s, 1.1 GB/s
    $ kfed read /dev/mapper/asm-ocr3 | more
    kfbh.endian:                          1 ; 0x000: 0x01
    kfbh.hard:                          130 ; 0x001: 0x82
    kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
    kfbh.datfmt:                          2 ; 0x003: 0x02
    kfbh.block.blk:                       0 ; 0x004: blk=0
    kfbh.block.obj:              2147483650 ; 0x008: disk=2
    kfbh.check:                   676930498 ; 0x00c: 0x285923c2
    kfbh.fcn.base:                     4115 ; 0x010: 0x00001013
    kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
    kfbh.spare1:                          0 ; 0x018: 0x00000000
    kfbh.spare2:                          0 ; 0x01c: 0x00000000
    ……
    

    本篇文章已于2017年5月22日,发布于Oracle一体机用户组,关迎关注:

    关于紫砂壶

    感悟技术人生
    此条目发表在Oracle基础知识分类目录,贴了标签。将固定链接加入收藏夹。