• Oracle udev 绑定磁盘(转)


    scsi_id命令发出一个SCSI INQUIRY指令给设备,访问vital product data (VPD)页0x83的数据,那里包含设备的WWID和其他的信息,或者页0x80的数据,那里包含单元序列号(unit serial number)。 scsi_id命令的执行结果(一长串字符)是设备的WWID,当前映射到/dev/sdc(/sys/block/sdc)。每一条到设备的路径和设备上的每一个分区的WWID都是相同的。设备的WWID不会改变,即使将其他的设备添加到系统或者从系统中删除。但是,映射到/dev/sdc的设备可能会改变。这就是为什么需要创建一个静态的设备名。可以根据WWID创建设备名。


    一、 如何获取设备WWID
    (1) Redhat 5 Enterprise Linux 如下:
    #/sbin/scsi_id -g -u -s /dev/sdb
    Or
    #/sbin/scsi_id -g -u -s /block/sdb
    Shell脚本
    # for i in `cat /proc/partitions | awk {'print $4'} |grep sd`; do echo "### $i: `scsi_id -g -u -s /block/$i`"; done

    (2) Redhat 6 Enterprise Linux 如下:
    #/sbin/scsi_id -g -u /dev/sdb
    Or
    #/sbin/scsi_id -g -u /block/sdb
    Or
    #/sbin/scsi_id --whitelist [--replace-whitespace] [ --device=] /dev/sdb
    Shell脚本
    # for i in `cat /proc/partitions | awk {'print $4'} |grep sd`; do echo "### $i: `scsi_id --whitelist --replace-whitespace /dev/$i`"; done

    二、 写入udev .rules

    (1) 对于整个盘的绑定写入 99-oracle-asmdevices.rules (文件名,测试可以随便命令)

    RHEL5
    for i in b c d e f ;
    do
    echo "KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="`/sbin/scsi_id -g -u -s /dev/sd$i`", NAME="asm-disk$i", OWNER="grid", GROUP="asmadmin", MODE="0660"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules
    done

    RHEL6
    for i in b c d e f ;
    do
    echo "KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="`/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i`", NAME="asm-disk$i", OWNER="grid", GROUP="asmadmin", MODE="0660"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules
    done

    Kernel [2.6.32] and later
    KERNEL=="sdc", BUS=="scsi", PROGRAM=="/sbin/scsi_id -gud /dev/$name" RESULT=="1ATA_VBOX_HARDDISK_VB93327385-145dda10", SYMLINK+="asmdisk/asm-crs1", OWNER="grid", GROUP="asmadmin", MODE="0660"
    OR
    KERNEL=="sdc", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name" RESULT=="1ATA_VBOX_HARDDISK_VB93327385-145dda10", SYMLINK+="asmdisk/asm-crs1", OWNER="grid", GROUP="asmadmin", MODE="0660"

    (2) 对于磁盘子分区的绑定
    Redhat Enterprise Linux 5 用如下参数
    KERNEL=="sd?[1-2]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="1ATA_VBOX_HARDDISK_VBaef9fa71-c32978c8", NAME="asm-ocr%n", OWNER="grid", GROUP="asmdba", MODE="0660"

    Redhat Enterprise Linux 6 用如下参数
    KERNEL=="sd?[1-2]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VBaef9fa71-c32978c8", NAME="asm-ocr%n", OWNER="grid", GROUP="asmdba", MODE="0660"
    Or
    KERNEL=="sdb1", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -d /dev/$parent" RESULT=="1ATA_VBOX_HARDDISK_VB8383313d-441fd502", NAME="asm-crs1", OWNER="grid", GROUP="asmadmin", MODE="0660"

    (3) 只改权限
    [root@rac01 oracle]# cat /etc/udev/rules.d/99-asm-multipath.rules
    PROGRAM="/bin/chown oracle:oinstall /dev/mapper/back_mpath1p1"
    PROGRAM="/bin/chown oracle:oinstall /dev/mapper/back_mpath2p1"
    PROGRAM="/bin/chown oracle:oinstall /dev/mapper/data_mpath1p1"
    PROGRAM="/bin/chown oracle:oinstall /dev/mapper/data_mpath2p1"

    三、 udev管理
    # udevadm -h
    # udevadm control -h
    # udevadm control --reload-rules
    #############################################
    SUSE Linux 使用UDEV配置ASMdisk
    #############################################
    vzwc1:~ # uname -a
    Linux vzwc1 3.0.76-0.11-default #1 SMP Fri Jun 14 08:21:43 UTC 2013 (ccab990) x86_64 x86_64 x86_64 GNU/Linux
    vzwc1:~ # cat /etc/issue
    Welcome to SUSE Linux Enterprise Server 11 SP3 (x86_64) - Kernel (l).

    添加编辑/etc/scsi_id.config 文件
    options=--whitelisted --replace-whitespace

    添加编辑/etc/udev/rules.d/99-oracle-asmdevices.rules
    for i in b c d e f g h i
    do
    echo "KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="`/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i`", NAME="asm-disk$i", OWNER="grid", GROUP="asmadmin", MODE="0660""
    done

    vzwc1:~ # cat /etc/udev/rules.d/99-oracle-asmdevices.rules
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB0221f2e9-f408ff4f", NAME="asm-diskb", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB49eb0a29-3c952001", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB4aa82271-74ee0a90", NAME="asm-diskd", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB2f97c868-e1906340", NAME="asm-diske", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VBf82d24e5-0f7a2eaf", NAME="asm-diskf", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB6a27197b-c6c40e34", NAME="asm-diskg", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB9b039565-b8786d7f", NAME="asm-diskh", OWNER="grid", GROUP="asmadmin", MODE="0660"
    KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB06b0cef7-cc3e6c40", NAME="asm-diski", OWNER="grid", GROUP="asmadmin", MODE="0660"

    启动udev
    vzwc1:~ # /etc/init.d/boot.udev status
    vzwc1:~ # /etc/init.d/boot.udev restart
    Restarting udevd:

    SUSE和RedHat系列不同,需要使用udevadm test测试,例如 udevadm test /sys/block/sdb
    建议配置完成后重启

    vzwc1:~ # fdisk -l
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0002a75e

    Device Boot Start End Blocks Id System
    /dev/sda1 2048 8386559 4192256 82 Linux swap / Solaris
    /dev/sda2 * 8386560 8787967 200704 83 Linux
    /dev/sda3 8787968 83886079 37549056 83 Linux
    vzwc1:~ # ll /dev/sd*
    brw-rw---- 1 root disk 8, 0 Dec 30 13:56 /dev/sda
    brw-rw---- 1 root disk 8, 1 Dec 30 13:56 /dev/sda1
    brw-rw---- 1 root disk 8, 2 Dec 30 13:56 /dev/sda2
    brw-rw---- 1 root disk 8, 3 Dec 30 13:56 /dev/sda3
    vzwc1:~ #
    vzwc1:~ # l /dev/asm-disk*
    brw-rw---- 1 grid asmadmin 8, 16 Dec 30 13:56 /dev/asm-diskb
    brw-rw---- 1 grid asmadmin 8, 32 Dec 30 13:56 /dev/asm-diskc
    brw-rw---- 1 grid asmadmin 8, 48 Dec 30 13:56 /dev/asm-diskd
    brw-rw---- 1 grid asmadmin 8, 64 Dec 30 13:56 /dev/asm-diske
    brw-rw---- 1 grid asmadmin 8, 80 Dec 30 13:56 /dev/asm-diskf
    brw-rw---- 1 grid asmadmin 8, 96 Dec 30 13:56 /dev/asm-diskg
    brw-rw---- 1 grid asmadmin 8, 112 Dec 30 13:56 /dev/asm-diskh
    brw-rw---- 1 grid asmadmin 8, 128 Dec 30 13:56 /dev/asm-diski
    #############################################
    案例一则:IBM multipath多路径+VCS双机+udev方式+LVM
    #############################################
    1、查看多路径
    AEP11:/etc/multipath # multipath -ll | grep IBM
    3600507680c800091180000000000022e dm-2 IBM ,2145
    3600507680c800091180000000000022d dm-1 IBM ,2145
    3600507680c800091180000000000022c dm-0 IBM ,2145
    2、配置多路径别名
    备注:因机器上无/etc/multipath.conf(不明原因),从其他主机(OS版本不同)拷贝/etc/multipath.conf,仅用multipath.conf配置文件中的别名部分配置,如下所示:
    AEP11:/etc/multipath # cat /etc/multipath.conf
    multipaths {
    multipath {
    wwid 3600507680c800091180000000000022c
    alias aep_diska
    }
    multipath {
    wwid 3600507680c800091180000000000022d
    alias aep_diskb
    }
    multipath {
    wwid 3600507680c800091180000000000022e
    alias aep_diskc
    }
    }

    重新生成多路径设备:
    multipath -F
    multipath -v2

    3、查看重新生成的多路径设备
    AEP11:~ # multipath -ll | grep aep
    aep_diskc (3600507680c800091180000000000022e) dm-2 IBM ,2145
    aep_diskb (3600507680c800091180000000000022d) dm-1 IBM ,2145
    aep_diska (3600507680c800091180000000000022c) dm-0 IBM ,2145

    4、udev方式绑定多路径
    AEP11:~ # cat /etc/udev/rules.d/99-aep-devices.rules
    KERNEL=="dm*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="3600507680c800091180000000000022c", NAME="aep_diska"
    KERNEL=="dm*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="3600507680c800091180000000000022d", NAME="aep_diskb"
    KERNEL=="dm*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="3600507680c800091180000000000022e", NAME="aep_diskc"

    备注:如加权限,则可类似如下:
    KERNEL=="dm*", SUBSYSTEM=="block", PROGRAM=="/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="3600507680c800091180000000000022c", NAME="aep_diska", OWNER="grid", GROUP="asmadmin", MODE="0660"

    -- 重新加载配置文件
    AEP11:~ # udevadm control --reload-rules
    -- 使规则生效,生成udev设备文件
    AEP11:~ # udevadm trigger

    5、查看绑定的设备:
    # ls -lrt /dev/aep_disk*

    6、创建pv
    AEP11:~ # pvcreate /dev/aep_disk{a,b,c}
    AEP11:~ # pvs

    注意:因操作的主机AEP11是双机,所以除去步骤6创建pv之外,其他步骤都需在主备机上操作。

  • 相关阅读:
    flex产生水平滚动条
    js中的类
    typescript
    vue练习
    vue-cli2脚手架搭建
    Luogu P1970 花匠
    Luogu P1311 选择客栈
    Luogu P1016 旅行家的预算
    Luogu P1144 最短路计数
    Luogu P1091 合唱队形
  • 原文地址:https://www.cnblogs.com/lucifa/p/10547228.html
Copyright © 2020-2023  润新知