oracle linux7 redhat7 创建udev规则 如何在RHEL7中配置和创建Oracle ASM磁盘 Udev重新加载规则。Oracle中的UDEV SCSI规则配置 为Oracle ASM手动配置设备持久性 groupadd -g 50001 oinstall groupadd -g 50002 dba groupadd -g 50003 oper groupadd -g 50004 asmadmin groupadd -g 50005 asmoper groupadd -g 50006 asmdba useradd -u 60001 -g oinstall -G dba,asmdba,oper oracle useradd -u 60002 -g oinstall -G asmadmin,asmdba,asmoper,oper,dba grid echo oracle|passwd --stdin oracle echo oracle|passwd --stdin grid [root@yxdb81 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.9 (Maipo) fdisk /dev/sdb /dev/sdb1 [root@yxdb81 ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc [root@yxdb81 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 5G 0 disk sr0 11:0 1 1024M 0 rom sdc 8:32 0 10G 0 disk sda 8:0 0 20G 0 disk ├─sda2 8:2 0 19G 0 part │ ├─ol-swap 252:1 0 2G 0 lvm [SWAP] │ └─ol-root 252:0 0 17G 0 lvm / └─sda1 8:1 0 1G 0 part /boot [root@yxdb81 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdb 1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7 1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7 [root@yxdb81 ~]# which scsi_id /usr/bin/which: no scsi_id in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) [root@yxdb81 ~]# /usr/lib/udev/scsi_id --whitelisted --device=/dev/sdb 1ATA VBOX HARDDISK VBdc9899a6-862a29c7 [root@yxdb81 ~]# /usr/lib/udev/scsi_id --help Usage: scsi_id [OPTION...] DEVICE SCSI device identification. -h --help Print this message --version Print version of the program -d --device= Device node for SG_IO commands SG_IO命令的设备节点 -f --config= Location of config file -p --page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83) -s --sg-version=3|4 Use SGv3 or SGv4 -b --blacklisted Treat device as blacklisted -g --whitelisted Treat device as whitelisted 将设备视为白名单 -u --replace-whitespace Replace all whitespace by underscores 用下划线替换所有空白 -v --verbose Verbose logging -x --export Print values as environment keys -u --replace-whitespace Replace all whitespace by underscores 用下划线替换所有空白 -d --device= Device node for SG_IO commands SG_IO命令的设备节点 -g --whitelisted Treat device as whitelisted 将设备视为白名单 [root@yxdb81 ~]# cd /etc/udev/rules.d/ [root@yxdb81 rules.d]# vim 99-oracleasm.rules KERNEL="sd?1",SUBSYSTEM="block",PROGRAM="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" cat 99-oracleasm.rules KERNEL=="sd?1",SUBSYSTEM=="block",PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT=="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" udevadm control --reload-rules udevadm trigger tail -f /var/log/messages Jun 10 03:31:43 yxdb81 libvirtd: 2024-06-09 19:31:43.190+0000: 1237: error : virNetlinkEventCallback:784 : nl_recv 返回出错信息: 没有可用的缓冲区空间 Jun 10 03:31:43 yxdb81 systemd-udevd: invalid KERNEL operation Jun 10 03:31:43 yxdb81 systemd-udevd: invalid rule '/etc/udev/rules.d/99-oracleasm.rules:1' 测试 [root@yxdb81 rules.d]# udevadm test /dev/sdb/sdb1 [root@yxdb81 rules.d]# ls /dev/asm* ls: 无法访问/dev/asm*: 没有那个文件或目录 解决: cat 99-oracleasm.rules KERNEL=="sd?1",SUBSYSTEM=="block",PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT=="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" KERNEL PROGRAM SUBSYSTEM RESULT 这四个字段中间的符号是两个等号 == [root@yxdb81 rules.d]# ls /dev/asm* /dev/asm-disk1 [root@yxdb81 rules.d]# ls /dev/asm* -las 0 lrwxrwxrwx. 1 root root 4 6月 10 03:41 /dev/asm-disk1 -> sdb1 测试 [root@yxdb81 rules.d]# ll /dev/asm-disk1 lrwxrwxrwx. 1 root root 4 6月 10 03:41 /dev/asm-disk1 -> sdb1 [root@yxdb81 rules.d]# mkfs.xfs /dev/asm-disk1 meta-data=/dev/asm-disk1 isize=256 agcount=4, agsize=327616 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0, sparse=0 data = bsize=4096 blocks=1310464, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@yxdb81 rules.d]# mount /dev/asm-disk1 /mnt [root@yxdb81 rules.d]# ls /mnt [root@yxdb81 rules.d]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part /mnt sr0 11:0 1 1024M 0 rom sdc 8:32 0 10G 0 disk sda 8:0 0 20G 0 disk ├─sda2 8:2 0 19G 0 part │ ├─ol-swap 252:1 0 2G 0 lvm [SWAP] │ └─ol-root 252:0 0 17G 0 lvm / └─sda1 8:1 0 1G 0 part /boot 类型 part 分区 disk 磁盘 rom 镜像 lsblk -f | grep sd ,得到目前创建的磁盘对应关系 [root@yxdb81 rules.d]# lsblk -f | grep sd sdb └─sdb1 xfs 44492a80-4562-4885-90eb-77a11f06ebd2 /mnt sdc sda ├─sda2 LVM2_member FozNzB-mhh2-BvLe-tRz6-8dER-sRfW-MKrhsh └─sda1 xfs 43a8643c-fdeb-4f69-a7c4-9a6a85a58fbd /boot 一、udev方式创建asm磁盘,采用uuid需要添加多块磁盘。大致流程如下 1、获取需要绑定为ASM Disk的磁盘uuid 2、新建/etc/udev/rules.d/99-oracle-asmdevices.rules,增加.... 3、重启start_udev服务 二、/etc/udev/rules.d/99-oracle-asmdevices.rules创建 1、获取需要绑定为ASM Disk的磁盘uuid,比如我们要使用/dev/asm-diskaa作为ASM磁盘,那么uuid,下面实际文件中有: [grid@shfpdb02 ~]$ /sbin/scsi_id -g -u -d /dev/asm-diskaa 369ce37410023334d07db5f9700000019 2、重启服务: [root@rac1 ~]# start_udev Starting udev: [ OK ] [root@yxdb81 rules.d]# /usr/lib/udev/scsi_id -g -u -d /dev/asm-disk1 1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7 磁盘的uuid是唯一的..不管名称有什么变化. 查看创建的磁盘组,查询可得 select name,state from v$asm_diskgroup; set line 9999 select group_number,disk_number ,path from v$asm_disk; vi /etc/udev/rules.d/99-oracle-asmdevices.rules [root@shfpdb02 grid]# cat /etc/udev/rules.d/99-oracle-asmdevices.rules KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="369ce37410023334d0029d52900000000", NAME="asm-diskb", OWNER="grid", GROUP="asmadmin", MODE="0660" KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="369ce37410023334d0029f6d900000001", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660" KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="369ce37410023334d002a0ae000000002", NAME="asm-diskd", OWNER="grid", GROUP="asmadmin", MODE="0660" BUS == SUBSYSTEM 磁盘类型 block scsi /重新加载udev规则配置文件 [grid@shfpdb02 ~]$ udevadm control --reload-rules //start_udev命令可以重新启动udev服务,udev服务重新读取配置文件,在/dev/下创建真实设备的设备名称 [grid@shfpdb02 ~]$ start_udev // 使规则生效,生成udev设备文件 [grid@shfpdb02 ~]$ udevadm trigger [root@yxdb81 rules.d]# udevadm info --query=all --name=sdb P: /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb N: sdb S: disk/by-id/ata-VBOX_HARDDISK_VBdc9899a6-862a29c7 S: disk/by-path/pci-0000:00:0d.0-ata-2.0 E: DEVLINKS=/dev/disk/by-id/ata-VBOX_HARDDISK_VBdc9899a6-862a29c7 /dev/disk/by-path/pci-0000:00:0d.0-ata-2.0 E: DEVNAME=/dev/sdb E: DEVPATH=/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb E: DEVTYPE=disk E: ID_ATA=1 E: ID_ATA_FEATURE_SET_PM=1 E: ID_ATA_FEATURE_SET_PM_ENABLED=1 E: ID_ATA_SATA=1 E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1 E: ID_ATA_WRITE_CACHE=1 E: ID_ATA_WRITE_CACHE_ENABLED=1 E: ID_BUS=ata E: ID_MODEL=VBOX_HARDDISK E: ID_MODEL_ENC=VBOX\x20HARDDISK\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20 E: ID_PART_TABLE_TYPE=dos E: ID_PATH=pci-0000:00:0d.0-ata-2.0 E: ID_PATH_TAG=pci-0000_00_0d_0-ata-2_0 E: ID_REVISION=1.0 E: ID_SERIAL=VBOX_HARDDISK_VBdc9899a6-862a29c7 E: ID_SERIAL_SHORT=VBdc9899a6-862a29c7 E: ID_TYPE=disk KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="369ce37410023334d002a0ae000000002", NAME="asm-diskd", OWNER="grid", GROUP="asmadmin", MODE="0660" [root@yxdb81 rules.d]# /usr/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/sdc 1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81 KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660" udevadm control --reload-rules udevadm trigger Jun 10 04:41:55 yxdb81 systemd-udevd: unknown key 'BUS' in /etc/udev/rules.d/99-oracleasm.rules:4 KERNEL=="sd*", SUBSYSTEM=="scsi", PROGRAM=="/usr/lib/udev/scsi_id/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660" udevadm control --reload-rules udevadm trigger ll /dev/asm* [root@yxdb81 rules.d]# cat 99-oracleasm.rules KERNEL=="sd?1",SUBSYSTEM=="block",PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT=="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660",NAME="sdc" [root@yxdb81 rules.d]# lsblk -f|grep sd sdb └─sdb1 xfs 44492a80-4562-4885-90eb-77a11f06ebd2 /mnt sdc xfs bfdc08e4-5105-4352-be64-9ce6edff8cc4 /data sda ├─sda2 LVM2_member FozNzB-mhh2-BvLe-tRz6-8dER-sRfW-MKrhsh └─sda1 xfs 43a8643c-fdeb-4f69-a7c4-9a6a85a58fbd /boot [root@yxdb81 rules.d]# lsblk |grep sd sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part /mnt sdc 8:32 0 10G 0 disk /data sda 8:0 0 20G 0 disk ├─sda2 8:2 0 19G 0 part └─sda1 8:1 0 1G 0 part /boot centos6配置 KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="369ce37410023334d0029d52900000000", NAME="asm-diskb", OWNER="grid", GROUP="asmadmin", MODE="0660" centos7配置 KERNEL=="sd?1",SUBSYSTEM=="block",PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT=="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" #uuid方式 KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660",NAME="sdc" raw方式 KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$name", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660",NAME="sdc" KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660" [root@yxdb81 rules.d]# ll /dev/asm* lrwxrwxrwx. 1 root root 4 6月 10 05:01 /dev/asm-disk1 -> sdb1 lrwxrwxrwx. 1 root root 3 6月 10 05:01 /dev/asm-diskc -> sdb 程序 udevadm monitor 可以用于将驱动程序核心事件和 udev 事件处理的计时可视化。 udevadm monitor udevadm monitor --env 显示完整的事件环境 KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$kernel", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660" [root@yxdb81 rules.d]# ll /dev/asm* lrwxrwxrwx. 1 root root 4 6月 10 05:08 /dev/asm-disk1 -> sdb1 lrwxrwxrwx. 1 root root 3 6月 10 05:08 /dev/asm-diskc -> sdc udevadm control --reload-rules udevadm trigger ll /dev/asm* KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/%k", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660" [root@yxdb81 rules.d]# ll /dev/asm* lrwxrwxrwx. 1 root root 4 6月 10 05:12 /dev/asm-disk1 -> sdb1 lrwxrwxrwx. 1 root root 3 6月 10 05:12 /dev/asm-diskc -> sdc 创建asm方式很多主要有以下几种 1、Faking方式 2、裸设备方式 3、udev方式(它下面有两种方式) 3.1 uuid方式. 3.2 raw方式(裸设备方式) 4、asmlib方式(oracleasm) 创建asm磁盘,前提条件是需要准备以下 1、A disk or partition from a storage array //一个磁盘或者是磁盘阵列的分区 2、An entire disk or the partitions of a disk //是一个完整的磁盘或是一个磁盘的分区 3、Logical volumes //一个磁盘的逻辑卷 4、Network-attached files (NAS) //NAS(Network-attached storage,网络连接存储) 参考资料 https://documentation.suse.com/zh-cn/sles/12-SP5/html/SLES-all/cha-udev.html KERNEL 事件设备的内部(内核)名称。 SUBSYSTEM 事件设备的子系统,如 SUBSYSTEM=usb(用于与 USB 设备有关的所有事件)。 PROGRAM 让 udev 执行外部程序。程序必须返回退出码零,才能成功。RESULT 键可使用程序的输出(打印到 stdout)。 RESULT 匹配上次 PROGRAM 调用的输出字符串。在与 PROGRAM 键相同的规则中包含该键,或在后面的一个中。 [root@yxdb81 ~]# ls /dev/asm* /dev/asm-disk1 /dev/asm-diskc [root@yxdb81 ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdd [root@yxdb81 ~]# cd /etc/udev/rules.d/ [root@yxdb81 rules.d]# vim 99-oracleasm.rules [root@yxdb81 rules.d]# /usr/lib/udev/scsi_id -g -u -d /dev/sdd 1ATA_VBOX_HARDDISK_VB3f0a91ad-228180b4 [root@yxdb81 rules.d]# !vim vim 99-oracleasm.rules cat 99-oracleasm.rules KERNEL=="sd?1",SUBSYSTEM=="block",PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent",RESULT=="1ATA_VBOX_HARDDISK_VBdc9899a6-862a29c7",SYMLINK+="asm-disk1",OWNER="oracle",GROUP="dba",MODE="0660" #KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$name", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660",NAME="sdc" KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/%k", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660" KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/%k", RESULT=="1ATA_VBOX_HARDDISK_VB3f0a91ad-228180b4", SYMLINK+="asm-%k", OWNER="oracle", GROUP="dba", MODE="0660" #KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$kernel", RESULT=="1ATA_VBOX_HARDDISK_VB942cf2e0-5db7df81", SYMLINK+="asm-diskc", OWNER="oracle", GROUP="dba", MODE="0660" \[root@yxdb81 rules.d]# udevadm control --reload-rules [root@yxdb81 rules.d]# udevadm trigger [root@yxdb81 rules.d]# ll /dev/asm* lrwxrwxrwx. 1 root root 4 6月 10 05:18 /dev/asm-disk1 -> sdb1 lrwxrwxrwx. 1 root root 3 6月 10 05:18 /dev/asm-diskc -> sdc lrwxrwxrwx. 1 root root 3 6月 10 05:18 /dev/asm-sdd -> sdd [root@yxdb81 rules.d]# lsblk -f |grep sd sdd sdb └─sdb1 xfs 44492a80-4562-4885-90eb-77a11f06ebd2 sdc xfs bfdc08e4-5105-4352-be64-9ce6edff8cc4 sda ├─sda2 LVM2_member FozNzB-mhh2-BvLe-tRz6-8dER-sRfW-MKrhsh └─sda1 xfs 43a8643c-fdeb-4f69-a7c4-9a6a85a58fbd /boot [root@yxdb81 rules.d]# mkfs.xfs /dev/asm-sdd meta-data=/dev/asm-sdd isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0, sparse=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@yxdb81 rules.d]# mkdir /sdd [root@yxdb81 rules.d]# mount /dev/asm-sdd /sdd/ [root@yxdb81 rules.d]# lsblk |grep sd sdd 8:48 0 1G 0 disk /sdd sdb 8:16 0 5G 0 disk └─sdb1 8:17 0 5G 0 part sdc 8:32 0 10G 0 disk sda 8:0 0 20G 0 disk ├─sda2 8:2 0 19G 0 part └─sda1 8:1 0 1G 0 part /boot
菜鸟的自白