解除预约
# sg_persist --out --release --param-rk=abc123 --prout-type=3 /dev/sdc
安装必要的工具
sg_persist 命令为 SCSI Reservation 提供了所有必要的功能,它包含在 sg3_utils 包中。
# yum install sg3_utils
查看预订
输出表明服务器被密钥 abc123 保留,类型为 3(独占访问):
# sg_persist -r /dev/sdc IET VIRTUAL-DISK 0001 Peripheral device type: disk PR generation=0x6, Reservation follows: Key=0xabc123 scope: LU_SCOPE, type: Exclusive Access
查看注册
在下面显示的示例中,尚未注册任何预订密钥。
# sg_persist /dev/sdc >> No service action given; assume Persistent Reserve In command >> with Read Keys service action IET VIRTUAL-DISK 0001 Peripheral device type: disk PR generation=0x4, there are NO registered reservation keys
什么是 SCSI 预留(SCSI reservation)
SCSI 预留是一种机制,它允许 SCSI 启动器为独占访问保留 LUN,并防止其他启动器进行更改。
该功能通常用于集群中。
这篇文章详细阐述了 CentOS/RHEL 系统中 SCSI 预留的基本用法。
SCSI 预留包含两个阶段:首先,发起方必须注册一个预留密钥,然后在主机需要独占访问时使用相同的预留密钥继续预留设备。
让我们看看如何使用 SCSI 预留和 SCSI 预留的必要功能。
确认预订
在保留了 /dev/sdc1 的 node1 上,它能够挂载磁盘。
# mount /dev/sdc1 /mnt # mount | grep mnt /dev/sdc1 on /mnt type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered) # umount /mnt
同时,它无法访问 node2 上的同一个磁盘
# mount /dev/sdc1 /mnt mount: mount /dev/sdc1 on /mnt failed: Invalid exchange
dmesg 显示保留冲突
# dmesg | tail [6902380.608058] sd 11:0:0:1: [sdc] tag#16 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK [6902380.608060] sd 11:0:0:1: [sdc] tag#16 CDB: Read(10) 28 00 00 1f ff 80 00 00 08 00 [6902380.608061] blk_update_request: critical nexus error, dev sdc, sector 2097024 [6902380.608064] Buffer I/O error on dev sdc1, logical block 261872, async page read [6902380.609007] sd 11:0:0:1: reservation conflict [6902380.609011] sd 11:0:0:1: [sdc] tag#14 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK [6902380.609013] sd 11:0:0:1: [sdc] tag#14 CDB: Read(10) 28 00 00 00 08 00 00 00 01 00 [6902380.609015] blk_update_request: critical nexus error, dev sdc, sector 2048 [6902380.609523] sd 11:0:0:1: reservation conflict [6902380.609526] blk_update_request: critical nexus error, dev sdc, sector 0
on It Road.com
代表给定密钥保留已注册的 LUN
# sg_persist --out --reserve --param-rk=abc123 --prout-type=3 /dev/sdc IET VIRTUAL-DISK 0001 Peripheral device type: disk
-prout-type 参数指定了预订类型,来自联机帮助页,有效类型包括:
- 1:写独占
- 3:独占访问
- 5:写独占-仅限注册人
- 6 : 独家访问 - 仅限注册人
- 7:写独占-所有注册人
- 8 : 独家访问 - 所有注册人
取消注册预订密钥
# sg_persist --out --register --param-rk=abc123 /dev/sdc
注册预约密钥
保留密钥必须是十六进制字符串,长度最多为 8 个字节,这里我们以 abc123 为例。
# sg_persist --out --register --param-sark=abc123 /dev/sdc
下面的输出显示了一个 SCSI LUN,其中注册了 2 个保留密钥(或者 2 个主机)。
# sg_persist /dev/sdc >> No service action given; assume Persistent Reserve In command >> with Read Keys service action IET VIRTUAL-DISK 0001 Peripheral device type: disk PR generation=0x6, 2 registered reservation keys follow: 0xabc123 0x123abc
日期:2020-09-17 00:14:41 来源:oir作者:oir