Device Mapper Multipath(DM-Multipath)可以将服务器节点和存储阵列之间的多条I/O链路配置为一个单独的设备。这些I/O链路是由不同的线缆、交换机、控制器组成的SAN物理链路。Multipath将这些链路聚合在一起,生成一个单独的新的设备。
1.DM-Multipath概览:
(1)数据冗余
DM-Multipath可以实现在active/passive模式下的灾难转移。在active/passive模式下,只有一半的链路在工作,如果链路上的某一部分(线缆、交换机、控制器)出现故障,DM-Multipath就会切换到另一半链路上。
(2)提高性能
DM-Multipath也可以配置为active/active模式,从而I/O任务以round-robin的方式分布到所有的链路上去。通过配置,DM-Multipath还可以检测链路上的负载情况,动态地进行负载均衡。
DM-Multipath的存储阵列的支持情况可以查看multipath.conf.default。对于支持列表中没有的存储,可以在multipath的配置文件multipath.conf中自行添加。
2.DM-Multipath的组成:
(1)dm-multipath内核模块实现I/O重定向、支持failover以及链路的聚合
(2)mutilpath命令查看和配置multipath设备。它一般由/etc/rc.sysinit启动,也会在系统发现新的块设备时由udev启动,或者由initramfs在系统启动时执行。
(3)multipathd后台进程监控链路。当链路失效或者恢复时,它会发起链路组的切换。它实现了对multipath设备的动态修改。不过multipath.conf修改后,它需要重新启动。
(4)kpartx命令根据设备上分区表创建device mapper设备。当需要在DM-MP设备上使用基于DOS的分区时,这个命令是必须。
不使用DM-Multipath,每一条从服务器到存储的链路都被系统识别为一个单独的设备。DM-Multipath可以在这些底层的设备之上创建一个单一的multipath设备,实现对这些链路的组织和管理。
3.Multipath设备的标志符
每一个multipath设备都有一个WWID(World Wide Identifier),这个id是全球唯一而且不可更改的。默认情况下,multipath设备的名称被设置为它的WWID。不过也可以在配置文件中使用_friendly_names选项,为设备取一个别名,别名为mpath[n]。
例如,一台服务器节点有2块HBA卡,通过一台没有划分zone的交换机,连接到2个磁盘阵列控制器,服务器系统中会发现4个设备:/dev/sda、/dev/sdb、/dev/sdc、/dev/sdd。DM-Multipath会按照配置文件在这些底层设备上创建一个拥有一个唯一WWID号的multipath设备。如果配置文件中_friendly_names选项被设置为yes,则这个multipath设备会被命名为mpath[n]。
当新的设备被DM-Multipath接管之后,新的设备文件会在/dev/目录下3个不同的地方出现:/dev/mapper/mpath[n]、/dev/mpath/mpath[n]、/dev/dm-[n]。
(1)/dev/mapper/目录下的文件,是早在系统启动的过程中就创建了。访问multipath设备时就使用这些文件,例如创建lvm;
(2)/dev/mpath/目录下的文件,是为了可以方便的在同一个目录下查看所有的multipath设备。这个文件由udev创建。如果系统在启动过程中需要访问multipath设备,不要使用这些文件。不用在这些设备文件上建立lvm;
(3)/dev/dm-[n]只为了内部使用目的,永远不要对这些文件进行操作。
4.统一multipath设备的命名
当配置文件中_friendly_names被设置为yes,在该服务器节点上这个设备名是唯一而且确定的,但是不能保证在使用这些链路的其它服务器节点上的multipath设备的名称能够相互保持一致。如果只是建立lvm,那么这个问题不会有什么影响。但是如果希望不同服务器节点上的multipath设备的名称能够统一,必须使用下面其中一种方法:
(1)在配置文件中的multipaths段使用alias选项为设备设置别名,并在不同的服务器上保持一致;
(2)如果希望不同服务器上multipath设备的user-friendly名称保持一致,首先在一台服务器上建立所有multipath设备,然后把bindings文件拷贝到所有其它系统统一命名的服务器。binds文件的位置是/var/lib/multipath/bindings。在配置文件可以使用bindings_file参数修改bindings文件的位置。
5.Multipath设备上建立lv
创建multipath设备之后,可以像使用物理设备文件一样在multipath设备上建立pv。例如,假定multipath设备为/dev/mapper/mpath0,使用
pvscreate /dev/mapper/mpath0
即可将mpath0建立为物理卷。同样可以继续建立卷族和逻辑卷。
当在配置为active/passive模式的multipath设备上建立逻辑卷时,需要在lvm的配置文件lvm.conf中增加过滤器,将multipath设备下层的设备添加到过滤列表中。这时因为DM-Multipath会自动切换数据链路,当遇到failover和failback的情况时,如果下层的设备没有在配置文件中过滤,lvm会扫描这些passive状态下的数据链路。Passive状态的链路改变到active状态需要执行一些命令,所以lvm就会在这个时候报错。
为了过滤所有的SCSI设备,在lvm.conf中的devices段,添加下面的配置:
filter = [ "r/disk/", "r/sd.*/", "a/.*/"
6.部署DM-Multipath
6.1开始部署
(1)编辑/etc/multipath.conf,注释掉下面几行:
devnode_blacklist {
devnode "*"
}
(2)multipath的默认配置已经集成在系统之中,不需要在/etc/multipath.conf中重新配置。
path_grouping_policy的默认值为failover。在原始配置中default段设置了multipath设备的默认名称是mpath[n]的形式,如果没有这一段配置(即_friendly_names=yes),设备的默认名称是它的WWID号。
(3)保存配置文件并退出。
(4)执行下列命令:
modprobe dm-multipath
sevice multipathd start
multipath -v2
注:multipath -v2会打印出已经聚合的数据链路。
(5)使用 chkconfig multipathd on,让multipath服务开机自动启动。
6.2排除本地scsi磁盘
很多系统都安装有本地scsi磁盘,DM-Multipath是不建议在这些磁盘上使用的。可以按照下面的步骤取消对本地scsi磁盘的映射。
(1)使用 multipath -v2 确认本地磁盘的信息。如下面的示例(sda为本地scsi磁盘):
[root@localhost ~]# multipath -v2
create: SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1
[size=33 GB][features="0"][hwhandler="0"]
\_ round-robin 0
\_ 0:0:0:0 sda 8:0 [---------
device-mapper ioctl cmd 9 failed: Invalid argument
device-mapper ioctl cmd 14 failed: No such device or address
create: 3600a0b80001327d80000006d43621677
[size=12 GB][features="0"][hwhandler="0"]
\_ round-robin 0
\_ 2:0:0:0 sdb 8:16
\_ 3:0:0:0 sdf 8:80
create: 3600 a0b80001327510000009a436215ec
[size=12 GB][features="0"][hwhandler="0"]
\_ round-robin 0
\_ 2:0:0:1 sdc 8:32
\_ 3:0:0:1 sdg 8:96
create: 3600a0b80001327d800000070436216b3
[size=12 GB][features="0"][hwhandler="0"]
\_ round-robin 0
\_ 2:0:0:2 sdd 8:48
\_ 3:0:0:2 sdh 8:112
create: 3600a0b80001327510000009b4362163e
[size=12 GB][features="0"][hwhandler="0"]
\_ round-robin 0
\_ 2:0:0:3 sde 8:64
\_ 3:0:0:3 sdi 8:128
(2)为了防止DM-Multipath对/dev/sda做映射,编辑/etc/multipath.conf中的devnode_blacklist段。可以使用devnode的方式过滤sda,不过系统中sda的命名不一定是固定的,所以最好使用wwid的方式。从上面的输出中可以看到/dev/sda的wwid为“SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1”,在配置文件添加:
devnode_blacklist{
wwid SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1
}
(3)执行下面的命令使配置生效,并重新打印multipath设备列表。
multipath -F
multipath -v2
6.3在DM-Multipath中增加新的设备类型
DM-Multipath支持大部分的存储阵列。默认的配置,可以查看multipath.conf.default文件。
如果希望添加默认不支持的存储设备,可以在/etc/multipath.conf中添加相应的信息。例如在配置为鉴中添加HP Open-V:
devices {
device {
vendor "HP"
product "OPEN-V"
getuid_callout "/sbin/scsi_id -g -u -p0x80 -s /block/%n"
}
}
7.DM-Multipath配置文件
7.1概览
DM-Multipath的配置文件分为以下几个部分:
devnode_blacklist
不使用DM-Multipath的设备列表。默认的情况下,所有的设备都在列表中。启用DM-Multipath的时候一般会将devnote_blacklist段注释掉;
defaults
DM-Multipath的默认通用配置;
multipaths
单独配置每一个multipath设备的属性。这些配置会覆盖在defaults段和devices段的配置;
devices
单独配置每一个存储控制器。这些配置会覆盖defaults段的配置。如果使用的存储控制器不被DM-Multipath支持,那么就需要为这种类型的控制器加一个devices subsection。
DM-Multipath确定multipath设备的属性时,会首先使用multipaths段的内容,然后是devices段,最好读取defaults段。
7.2 配置 blacklist
devnode_blacklist指定了系统在配置multipath设备时不使用的设备,默认情况所有的设备都在这个列表中。注释掉默认的一行之后,可以在列表中加入某一种类型的设备或者某一特定的设备。禁用设备有2种方法:
(1)使用wwid:
可以使用wwid指定特定的设备,如:
blacklist {
wwid 26353900f02796769
}
(2)使用设备名:
如:
devnode_blacklist {
devnode "^sd[a-z]"
}
这一段配置会禁用所有的SCSI磁盘设备。虽然可以使用这种方法禁用单一特定的设备,但是并不建议这样做。因为除非是使用了udev固定了设备的设备名,则设备的名称在每次重启之后是有可能发生变化的。
因为一些设备并不支持DM-Multipath,所以下面列出的设备是默认禁用的:
blacklist {
devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
devnode "^hd[a-z]"
devnode "^cciss!c[0-9]d[0-9]*"
}
_________________________---------------------------------------------------------------------------------------------------
device-mapper-multipathing,需要完全的升级操作系统。早期的红帽企业Linux 4
不包含这个功能。编辑文件/etc/multipath.conf。在文件头部注释掉如下内容:
devnode_blacklist {
devnode "*"
}
如下例:
# devnode_blacklist {
# devnode "*"
# }
取消文件 /etc/multipath.conf中这段的注释,这段内容能让 device-mapper multipathing 不用扫描所有的设备。 etc/multipath.conf file:
defaults {
multipath_tool "/sbin/multipath -v0"
udev_dir /dev
polling_interval 10
default_selector "round-robin 0"
default_path_grouping_policy multibus
default_getuid_callout "/sbin/scsi_id -g -u -s /block/%n"
default_prio_callout "/bin/true"
default_features "0"
rr_wmin_io 100
failback immediate
}
devnode_blacklist {
wwid 26353900f02796769
devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
devnode "^hd[a-z][[0-9]*]"
devnode "^cciss!c[0-9]d[0-9]*[p[0-9]*]"
}
这段设置了默认的 device-mapper 的动作,并且去出了通常不会有多路径的设备,如IDE硬盘和软盘。默认的hd*设备的黑名单存在这一个排印错误。需要修改。
devnode "^hd[a-z][[0-9]*]"
把上行修改为如下:
devnode "^hd[a-z][0-9]*"
为了实现简单的failover功能,下例中,defaults 组中的默认的 default_path_grouping_policy 选项被设置成为 failover。
defaults {
multipath_tool "/sbin/multipath -v0"
udev_dir /dev
polling_interval 10
default_selector "round-robin 0"
default_path_grouping_policy failover
default_getuid_callout "/sbin/scsi_id -g -u -s /block/%n"
default_prio_callout "/bin/true"
default_features "0"
rr_wmin_io 100
failback immediate
}
退出编辑并保存设置,执行如下命令
modprobe dm-multipath
modprobe dm-round-robin
service multipathd start
multipath -v2
命令 multipath -v2 能显示多路径,从而能知道那些设备工作在多路径下。如果没有所有输出,确认所有的SAN连接被正确的设置,系统有没有正确的开启多路径功能。执行如下命令确认多路径服务有无启动。
chkconfig multipathd on
设备的设备名会被生成,/dev/dm-#,#指代的是多路径组,如果/dev/sda是唯一的多路径设备,/dev/dm-0将会是
/dev/sda和/dev/sdb的多路径设备。注意:fdisk不能用于设备/dev/dm-#,使用fdisk只能操作基础磁盘,要在设备映射多路
径映射设备上创建/dev/dm-#分区的操作. 执行一下命令。
kpartx -a /dev/dm-#
注意: dmsetup ls ?target=multipath
是个协助侦测系统上多路径设备的命令。如果在多路径设备数据库中没有发现硬件,请查看文章“How can I add moreproducts
into the mutipathing database?”
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
代码: |
struct linear_c { struct dm_dev *dev; sector_t start; }; |
代码: |
1) 0 1024 linear /dev/sda 204 1024 512 linear /dev/sdb 766 1536 128 linear /dev/sdc 0 2) 0 2048 striped 2 64 /dev/sda 1024 /dev/sdb 0 3) 0 4711 mirror core 2 64 nosync 2 /dev/sda 2048 /dev/sdb 1024 |
代码: |
dmsetup create 设备名 映射表文件 /* 根据指定的映射表创建一个逻辑设备 */ dmsetup reload 设备名 映射表文件 /* 为指定设备从磁盘中读取映射文件,重新构建映射关系 */ dmsetup remove 设备名 /* 删除指定的逻辑设备 */ |
代码: |
static int linear_map(struct dm_target *ti, struct bio *bio, union map_info *map_context) { struct linear_c *lc = (struct linear_c *) ti->private; bio->bi_bdev = lc->dev->bdev; bio->bi_sector = lc->start + (bio->bi_sector - ti->begin); return 1; } |
dmsetup help [-c|-C|--columns] devmap_name major minor dmsetup manages logical devices that use the device-mapper driver. Devices are created by loading a table that specifies a target for each sector (512 bytes) in the logical device. The first argument to dmsetup is a command. The second argument is the logical device name or uuid. Invoking the command as devmap_name is equivalent to -c|-C|--columns device_name [-u uuid] [--notable | --table [device_name] [-c|-C|--columns] [device_name] [--noheadings] [--separator separator] [-o fields] [-O|--sort sort_fields] [device_name] [--target target_type] [--exec command] [--tree [-o options]] [-f|--force] device_name device_name new_name device_name [--target target_type] [device_name] [--target target_type] [device_name] device_name [event_nr] Each line of the table specifies a single target and is of the form: There are currently three simple target types available together with more complex optional ones that implement snapshots and mirrors. destination_device start_sector # A table to join two disks together # A table to stripe across the two disks, 0 2056320 striped 2 32 /dev/hda 0 /dev/hdb 0
dmsetup create device_name [-u uuid] [--notable | --table | table_file]
dmsetup remove [-f|--force] device_name
dmsetup remove_all [-f|--force]
dmsetup suspend [--nolockfs] [--noflush] device_name
dmsetup resume device_name
dmsetup load device_name [--table | table_file]
dmsetup clear device_name
dmsetup reload device_name [--table | table_file]
dmsetup rename device_name new_name
dmsetup message device_name sector message
dmsetup ls [--target target_type] [--exec command] [--tree [-o options]]
dmsetup info [device_name]
dmsetup info -c|-C|--columns [--noheadings] [--separator separator] [-o fields] [-O|--sort sort_fields] [device_name]
dmsetup deps [device_name]
dmsetup status [--target target_type] [device_name]
dmsetup table [--target target_type] [device_name]
dmsetup wait device_name [event_nr]
dmsetup mknodes [device_name]
dmsetup targets
dmsetup version
dmsetup setgeometry device_name cyl head sect start
devmap_name major:minor Description
dmsetup info -c --noheadings -j major -m minor. Options
Commands
| table_file] Creates a device with the given name. If table_file or
is supplied, the table is loaded and made live. Otherwise a table is read from standard input unless --notable is used. The optional uuid can be used in place of device_name in subsequent dmsetup commands. If successful a device will appear as /dev/device-mapper/
State: SUSPENDED|ACTIVE, READ-ONLY
Tables present: LIVE and/or INACTIVE
Open reference count
Last event sequence number (used by
wait)
Major and minor device number
Number of targets in the live table
UUID
info
| table_file]
Loads or table_file into the inactive table slot for device_name. If neither is supplied, reads a table from standard input.
message
device_name sector message
Send message to target. If sector not needed use 0.
mknodes
[device_name]
Ensure that the node in /dev/mapper for device_name is correct. If no device_name is supplied, ensure that all nodes in /dev/mapper correspond to mapped devices currently loaded by the device-mapper kernel driver, adding, changing or removing nodes as necessary.
remove
Attempts to remove all device definitions i.e. reset the driver. Use with care! From version 4.8.0 onwards, if devices can't be removed because uninterruptible processess are waiting for I/O to return from them, adding --force will replace the table with one that fails all I/O, which might allow the process to be killed. This also runs
mknodes afterwards.
rename
Sets the device geometry to C/H/S.
status
Suspends a device. Any I/O that has already been mapped by the device but has not yet completed will be flushed. Any further I/O to that device will be postponed for as long as the device is suspended. If there's a filesystem on the device which supports the operation, an attempt will be made to sync it first unless --nolockfs is specified. Some targets such as recent (October 2006) versions of multipath may support the --noflush option. This lets outstanding I/O that has not yet reached the device to remain unflushed.
table
Table Format
logical_start_sector num_sectors target_type target_args
Creates a striped area.
e.g. striped 2 32 /dev/hda1 0 /dev/hdb1 0 will map the first chunk (16k) as follows:
LV chunk 1 -> hda1, chunk 1
LV chunk 2 -> hdb1, chunk 1
LV chunk 3 -> hda1, chunk 2
LV chunk 4 -> hdb1, chunk 2
etc.
error Errors any I/O that goes to this area. Useful for testing or for creating devices with holes in them.
Examples
0 1028160 linear /dev/hda 0
1028160 3903762 linear /dev/hdb 0
# and add the spare space from
# hdb to the back of the volume
2056320 2875602 linear /dev/hdb 1028160
你可能感兴趣的:(Linux,mannual)