之前我们介绍了如何使用 ASMLIB 为 Oracle ASM 创建了一致的磁盘。
但是有一些 Linux 发行版无法使用 ASMLIB 内核驱动程序。
因此,我们必须使用 udev(Linux 设备管理器)为 Oracle ASM 创建一致的磁盘。
在本文中,我们将介绍如何使用 udev 创建一致的磁盘。
更多: zhilu jiaocheng
配置udev
此方法不适用于磁盘分区,因此,我在我们的虚拟机中添加了 3 个相同大小的虚拟磁盘。
[root@testserver ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000b53f3 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdc: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdd: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_testserver-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_testserver-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@testserver ~]#
在所有 3 个磁盘中创建分区。
[root@testserver ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x76935e66. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): Using default value 261 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@testserver ~]# [root@testserver ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x55ffa8e2. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): Using default value 261 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@testserver ~]# [root@testserver ~]# fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xb2a8a4c8. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): Using default value 261 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@testserver ~]#
加载更新的块设备分区表如下:
[root@testserver ~]# /sbin/partprobe /dev/sdb1 [root@testserver ~]# /sbin/partprobe /dev/sdc1 [root@testserver ~]# /sbin/partprobe /dev/sdd1
使用 scsi_id 获取每个磁盘的唯一 SCSI ID。
[root@testserver ~]# /sbin/scsi_id -g -u -d /dev/sdb 36000c291381e5b565048efead9df75e7 [root@testserver ~]# /sbin/scsi_id -g -u -d /dev/sdc 36000c2973befa14808a2717562022211 [root@testserver ~]# /sbin/scsi_id -g -u -d /dev/sdd 36000c29e5e39da397c14ad10ed2dd557 [root@testserver ~]#
如果我们使用的是虚拟机,则上述语句可能会返回 NULL,因为默认情况下 VMWare 不向磁盘提供 SCSI ID。
要启用此功能,请关闭 VM 并在虚拟机的 .vmx 文件中添加以下行。
之后重新启动 VM 并再次尝试上述命令。
disk.EnableUUID = "TRUE"
为 Oracle ASM 磁盘所有者创建操作系统用户和组。
[root@testserver ~]# groupadd -g 601 oinstall [root@testserver ~]# groupadd -g 602 dba [root@testserver ~]# groupadd -g 603 oper [root@testserver ~]# groupadd -g 604 asmadmin [root@testserver ~]# groupadd -g 605 asmoper [root@testserver ~]# groupadd -g 606 asmdba [root@testserver ~]# [root@testserver ~]# useradd -u 601 -g oinstall -G asmadmin,asmdba,asmoper grid [root@testserver ~]# passwd grid Changing password for user grid. New password: BAD PASSWORD: it is WAY too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully. [root@testserver ~]#
通过使用磁盘的 UUID 创建 asm-disks 来创建 udev 规则。
[root@testserver ~]# echo options=-g >> /etc/scsi_id.config [root@testserver ~]# cat >> /etc/udev/rules.d/99-oracle-asmdevices.rules << EOF > KERNEL=="sd?1", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -d /dev/$parent", RESULT=="36000c291381e5b565048efead9df75e7",NAME="asm-disk1", OWNER="grid", GROUP="asmadmin", MODE="0660" > KERNEL=="sd?1", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -d /dev/$parent", RESULT=="36000c2973befa14808a2717562022211", NAME="asm-disk2", OWNER="grid", GROUP="asmadmin", MODE="0660" > KERNEL=="sd?1", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -d /dev/$parent", RESULT=="36000c29e5e39da397c14ad10ed2dd557", NAME="asm-disk3", OWNER="grid", GROUP="asmadmin", MODE="0660 > EOF [root@testserver ~]#
使用以下命令测试 udev 规则。
[root@testserver ~]# udevadm test /block/sdb/sdb1 run_command: calling: test udevadm_test: version 147 This program is for debugging only, it does not run any program, specified by a RUN key. It may show incorrect results, because some values may be different, or not available at a simulation run. parse_file: reading '/lib/udev/rules.d/10-console.rules' as rules file parse_file: reading '/etc/udev/rules.d/99-vmware-scsi-udev.rules' as rules file udev_rules_new: rules use 28908 bytes tokens (2409 * 12 bytes), 17584 bytes buffer udev_rules_new: temporary index used 17920 bytes (896 * 20 bytes) udev_device_new_from_syspath: device 0x7f69aded4b30 has devpath '/devices/pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/block/sdb/sdb1' udev_device_new_from_syspath: device 0x7f69adedc470 has devpath '/devices/pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/block/sdb/sdb1' ... udevadm_test: run: 'socket:/org/kernel/dm/multipath_event' udevadm_test: run: '/bin/sh -c 'echo 180 >/sys$DEVPATH/timeout'' [root@testserver ~]#
对 /dev/sdc1 和 /dev/sdd1 重复上述命令。
[root@testserver ~]# udevadm test /block/sdb/sdc1 [root@testserver ~]# udevadm test /block/sdb/sdd1
重启udev。
[root@testserver ~]# udevadm control --reload-rules [root@testserver ~]# /sbin/start_udev Starting udev: [ OK ] [root@testserver ~]#
检查我们的 asm 磁盘。
[root@testserver ~]# ls -al /dev/asm-disk* brw-rw----. 1 grid asmadmin 8, 17 Apr 11 22:10 /dev/asm-disk1 brw-rw----. 1 grid asmadmin 8, 33 Apr 11 22:05 /dev/asm-disk2 brw-rw----. 1 grid asmadmin 8, 49 Apr 11 22:05 /dev/asm-disk3 [root@testserver ~]#
udev 配置完成。
现在我们有 3 个磁盘,它们将在系统重新启动期间保持一致,并可用作 Oracle ASM 磁盘。
配置环境
我们已经为 Linux 虚拟机配置了一些未使用的空间。
我们将使用这个未使用的空间来创建一致的磁盘。
服务器配置:
CPU | 2.4 GHz(单核) |
内容 | 1 GB |
操作系统 | CentOS 6.7 |
存储: | |
/dev/sda | 20 GB 用于交换和 Linux |
/dev/sdb | 2 GB 用于 asm-disk1 |
/dev/sdc | 2 GB 用于 asm-disk2 |
/dev/sdd | 2 GB 用于 asm-disk3 |
日期:2020-09-17 00:16:36 来源:oir作者:oir