在日常工作中我们经常遇到配置存储的多路径聚合。多路径的目的是,当主机HBA卡、线缆、交换机或者存储设备的控制器故障等原因造成一条物理路径失效时,服务器可以将通过此物理路径的I/O转移到其他正常的物理路径上面,应用程序不会觉察到这种改变,从而提高系统的可用性,同时多路径冗余I/O也可以实现I/O的负载均衡,提高系统性能,但主要还是一种容错机制。下面是我使用Linux 自带的Multipath软件做多路径聚合的过程。
一、当存储映射新的LUN给服务器后,fdisk -l无法识别,需要使用下面命令,host1和host2是HBA卡的实际文件夹路径(/sys/class/host/host*)
识别命令:
echo 1 > /sys/class/fc_host/host1/issue_lip
echo 1 > /sys/class/fc_host/host8/issue_lip
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host8/scan
使用fdisk -l可以看到有四个磁盘。实际上这只是磁盘的路径而不是磁盘。
二、识别到的/dev/sd*并不是磁盘,而是路径,需要使用多路径软件multipath,将路径虚拟为一个磁盘。
1、安装多路径软件
yum -y install device-mapper-multipath
配置开机启动
systemctl enable multipathd.service
拷贝配置文件
cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/
2、查看新映射LUN的wwid
本地磁盘:
[root@ysyk_resources multipath]# /usr/lib/udev/scsi_id --whitelist --device=/dev/sda
36d4ae520a2229700179cc3741957982c
LUN路径:
[root@ysyk_resources multipath]# /usr/lib/udev/scsi_id --whitelist --device=/dev/sdb
36000d3100152fa000000000000000004
[root@ysyk_resources multipath]# /usr/lib/udev/scsi_id --whitelist --device=/dev/sdc
36000d3100152fa000000000000000004
[root@ysyk_resources multipath]# /usr/lib/udev/scsi_id --whitelist --device=/dev/sdd
36000d3100152fa000000000000000004
[root@ysyk_resources multipath]# /usr/lib/udev/scsi_id --whitelist --device=/dev/sde
36000d3100152fa000000000000000004
[root@ysyk_resources multipath]#
3、编辑multipath.conf
defaults {
user_friendly_names yes
find_multipaths yes
}
#
defaults {
user_friendly_names yes
polling_interval 10
checker_timeout 120
queue_without_daemon no
flush_on_last_del yes
}
##黑名单标记所有本地磁盘,multipaths标记所有路径
blacklist {
wwid 36d4ae520a2229700179cc3741957982c
}
multipaths {
multipath {
wwid 36000d3100152fa000000000000000004
alias data01
}
multipath {
#如果有其他LUN再添加即可
}
}
#devices {
# device {
# vendor "COMPAQ "
# product "HSV110 (C)COMPAQ"
# path_grouping_policy multibus
# path_checker readsector0
# path_selector "round-robin 0"
# hardware_handler "0"
# failback 15
# rr_weight priorities
# no_path_retry queue
# }
# device {
# vendor "COMPAQ "
# product "MSA1000 "
# path_grouping_policy multibus
# }
#}
4、查看多路径
[root@ysyk_resources ~]# systemctl restart multipathd
[root@ysyk_resources multipath]# multipath -ll
May 14 15:25:16 | /etc/multipath.conf line 6, duplicate keyword: defaults
data01 (36000d3100152fa000000000000000004) dm-1 COMPELNT,Compellent Vol
size=20T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=1 status=active
|- 1:0:19:1 sdb 8:16 active ready running
|- 1:0:23:1 sdc 8:32 active ready running
|- 8:0:21:1 sde 8:64 active ready running
`- 8:0:23:1 sdd 8:48 active ready running
[root@ysyk_resources multipath]#
三、格式化分区:
[root@ysyk_resources ~]# mkfs.ext4 -T largefile /dev/mapper/data01
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=512 blocks, Stripe width=512 blocks
20971520 inodes, 5368709120 blocks
268435456 blocks (5.00%) reserved for the super user
First data block=0
163840 block groups
32768 blocks per group, 32768 fragments per group
128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
2560000000, 3855122432
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
四、查看uuid
[root@ysyk_resources ~]# blkid
/dev/sda1: UUID="a857b07d-bb4f-42eb-95e9-f205fd39350f" TYPE="ext4"
/dev/sda2: UUID="3d73a9d0-c4db-4e4c-8b5d-2b78306fe1d1" TYPE="swap"
/dev/sda3: UUID="pezhpr-9joV-Rt6H-Jl1s-a2bk-Kja8-JSSd8L" TYPE="LVM2_member"
/dev/mapper/cl00-lv: UUID="3d0980f8-26ec-4e36-a4df-b68372922cc7" TYPE="xfs"
/dev/mapper/data01: UUID="c4182d79-93a1-49bd-b4aa-dba4517a4d42" TYPE="ext4"
[root@ysyk_resources ~]#
五、挂载磁盘
[root@ysyk_resources ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 9 12:14:28 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl00-lv / xfs defaults 0 0
UUID=a857b07d-bb4f-42eb-95e9-f205fd39350f /boot ext4 defaults 1 2
UUID=3d73a9d0-c4db-4e4c-8b5d-2b78306fe1d1 swap swap defaults 0 0
UUID=c4182d79-93a1-49bd-b4aa-dba4517a4d42 /opt/data01 ext4 defaults 0 0
~
[root@ysyk_resources ~]# mount -a
[root@ysyk_resources ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl00-lv 550G 5.6G 545G 2% /
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 144K 32G 1% /dev/shm
tmpfs 32G 18M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 477M 144M 304M 33% /boot
tmpfs 6.3G 24K 6.3G 1% /run/user/0
/dev/mapper/data01 20T 20K 19T 1% /opt/data01
[root@ysyk_resources ~]#