multipath简单使用

一、安装multipath软件

1.检查是否安装多路径软件multipath
[root@test ~]# rpm -aq | grep device-mapper-multipath
device-mapper-multipath-0.4.9-133.0.1.el7.x86_64
device-mapper-multipath-libs-0.4.9-133.0.1.el7.x86_64

2.安装multipath
[root@test ~]# yum install device-mapper-multipath -y

3.将多路径软件添加至内核模块中
[root@test ~]# modprobe dm-multipath
[root@test ~]# modprobe dm-round-robin

4.检查内核添加情况
[root@test ~]# lsmod |grep multipath
dm_multipath           32768  1 dm_round_robin
dm_mod                131072  3 dm_multipath,dm_log,dm_mirror

5.查看sici_id
[root@test ~]# /usr/lib/udev/scsi_id -g -u /dev/sdb
14f504e46494c45526e49436251612d324e6e332d66324e77
or
[root@test ~]# udevadm info --query=all --name=/dev/sdb
[root@ora1 ~]# udevadm info --query=all --name=/dev/sdb | grep ID_SERIAL
E: ID_SERIAL=14f504e46494c45526e49436251612d324e6e332d66324e77


[root@ora1 ~]# /usr/lib/udev/scsi_id -g -u /dev/sdc
14f504e46494c45526b30577669742d7032534a2d76516d44
or
[root@ora1 ~]# udevadm info --query=all --name=/dev/sdc | grep ID_SERIAL
E: ID_SERIAL=14f504e46494c45526b30577669742d7032534a2d76516d44

这里要有一点要注意的,就是要获取某个设备的wwid时,必须先确保用fdisk –l等看到这个设备

6.lsblk查看原存储架构
[root@ora1 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
sda      8:0    0   50G  0 disk 
├─sda2   8:2    0   48G  0 part /
└─sda1   8:1    0    2G  0 part [SWAP]

二、客户端配置

1.安装iscsi并开启服务
yum -y install iscsi-initiator-utils
systemctl start iscsi
systemctl enable iscsi

2.发现iSCSI目标
[root@pg2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.56.137:3260
192.168.56.137:3260,1 iqn.2006-01.com.openfiler:tsn.02a40dffbe17
192.168.56.139:3260,1 iqn.2006-01.com.openfiler:tsn.02a40dffbe17
192.168.56.137:3260,1 iqn.2006-01.com.openfiler:tsn.655987a824f5
192.168.56.139:3260,1 iqn.2006-01.com.openfiler:tsn.655987a824f5
192.168.56.137:3260,1 iqn.2006-01.com.openfiler:tsn.03d92452c811
192.168.56.139:3260,1 iqn.2006-01.com.openfiler:tsn.03d92452c811
192.168.56.137:3260,1 iqn.2006-01.com.openfiler:tsn.05fbb45bacf1
192.168.56.139:3260,1 iqn.2006-01.com.openfiler:tsn.05fbb45bacf1




[root@pg2 ~]# fdisk -l 

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b639e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    79693823    39845888   83  Linux
/dev/sda2        79693824    83886079     2096128   82  Linux swap / Solaris


3.挂载共享盘
[root@pg2 ~]# iscsiadm -m node -p 192.168.56.137:3260 -l
[root@pg2 ~]# iscsiadm -m node -p 192.168.56.137:3260 -l
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.02a40dffbe17, portal: 192.168.56.137,3260] (multiple)
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.655987a824f5, portal: 192.168.56.137,3260] (multiple)
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.03d92452c811, portal: 192.168.56.137,3260] (multiple)
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.05fbb45bacf1, portal: 192.168.56.137,3260] (multiple)
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.02a40dffbe17, portal: 192.168.56.137,3260] successful.
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.655987a824f5, portal: 192.168.56.137,3260] successful.
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.03d92452c811, portal: 192.168.56.137,3260] successful.
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.05fbb45bacf1, portal: 192.168.56.137,3260] successful.
.


[root@pg2 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b639e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    79693823    39845888   83  Linux
/dev/sda2        79693824    83886079     2096128   82  Linux swap / Solaris

Disk /dev/sdc: 2013 MB, 2013265920 bytes, 3932160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 2013 MB, 2013265920 bytes, 3932160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdd: 3053 MB, 3053453312 bytes, 5963776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sde: 4060 MB, 4060086272 bytes, 7929856 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdf: 2013 MB, 2013265920 bytes, 3932160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdg: 2013 MB, 2013265920 bytes, 3932160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdh: 3053 MB, 3053453312 bytes, 5963776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdi: 4060 MB, 4060086272 bytes, 7929856 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


4.注销单个节点
首先解除挂载,然后注销
iscsiadm -m node –T iqn.1997-05.com.test:raid -p 192.168.56.137:3260  –u

5.注销所有连接
iscsiadm -m node --logoutall=all

6.查看target记录
iscsiadm -m node

7.查看所有iscsi连接
iscsiadm -m session

8.删除target
iscsiadm -m node -o delete -T iqn.1997-05.com.test:raid -p 192.168.56.137:3260


三、启动服务

[root@pg2 ~]# /usr/lib/udev/scsi_id -g -u /dev/sdb
14f504e46494c455273526c5666382d427931672d42633257
[root@pg2 ~]# /usr/lib/udev/scsi_id -g -u /dev/sdd
14f504e46494c45525165745934692d337139312d32427555
[root@pg2 ~]# /usr/lib/udev/scsi_id -g -u /dev/sdi
14f504e46494c45526c4f646f63452d4a5577352d48665731

1.启动服务并设置开机自启
[root@test ~]# systemctl enable multipathd --now

blacklist {
 ##       wwid    3600508b1001c044c39717726236c68d5
}

2.手动创建/etc/multipath.conf配置文件并写入如下内容:
defaults {
    user_friendly_names       yes
    polling_interval            10
    queue_without_daemon    no
    flush_on_last_del          yes
    checker_timeout 120
}


devices {
    device {
        vendor                 "3par8400"
        product                "HP"
        path_grouping_policy    asmdisk
        no_path_retry           30
        prio                    hp_sw
        path_checker            tur
        path_selector           "round-robin 0"
        hardware_handler       "0"
        failback                15
        }
}


multipaths {
        multipath {
           wwid    14f504e46494c455273526c5666382d427931672d42633257
           alias    mpathdisk01
        }
}

#如果有两个或者多个就再加一条即可。
multipaths {
        multipath {
           wwid    14f504e46494c45525165745934692d337139312d32427555
           alias    mpathdisk02
        }
}

multipaths {
        multipath {
           wwid    14f504e46494c45526c4f646f63452d4a5577352d48665731
           alias    mpathdisk03
        }
}

3.重启服务
systemctl restart multipathd

3.状态查看

1.查看多路径
[root@ora1 ~]#  multipath -ll
[root@pg2 ~]#  multipath -ll
Aug 03 23:00:50 | /etc/multipath.conf line 33, duplicate keyword: multipaths
Aug 03 23:00:50 | /etc/multipath.conf line 40, duplicate keyword: multipaths
mpathdisk01 (14f504e46494c455273526c5666382d427931672d42633257) dm-0 OPNFILER,VIRTUAL-DISK    
size=1.9G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 3:0:0:0 sdc 8:32  active ready running
|-+- policy='service-time 0' prio=1 status=enabled
| `- 4:0:0:0 sdb 8:16  active ready running
|-+- policy='service-time 0' prio=1 status=enabled
| `- 5:0:0:0 sdg 8:96  active ready running
`-+- policy='service-time 0' prio=1 status=enabled
  `- 6:0:0:0 sdf 8:80  active ready running
mpathdisk03 (14f504e46494c45526c4f646f63452d4a5577352d48665731) dm-2 OPNFILER,VIRTUAL-DISK    
size=3.8G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 3:0:0:2 sde 8:64  active ready running
`-+- policy='service-time 0' prio=1 status=enabled
  `- 6:0:0:2 sdi 8:128 active ready running
mpathdisk02 (14f504e46494c45525165745934692d337139312d32427555) dm-1 OPNFILER,VIRTUAL-DISK    
size=2.8G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 3:0:0:1 sdd 8:48  active ready running
`-+- policy='service-time 0' prio=1 status=enabled
  `- 6:0:0:1 sdh 8:112 active ready running



2.查看存储挂载情况
[root@pg2 ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sdf             8:80   0  1.9G  0 disk  
└─mpathdisk01 252:0    0  1.9G  0 mpath 
sdd             8:48   0  2.9G  0 disk  
└─mpathdisk02 252:1    0  2.9G  0 mpath 
sdb             8:16   0  1.9G  0 disk  
└─mpathdisk01 252:0    0  1.9G  0 mpath 
sdi             8:128  0  3.8G  0 disk  
└─mpathdisk03 252:2    0  3.8G  0 mpath 
sr0            11:0    1 1024M  0 rom   
sdg             8:96   0  1.9G  0 disk  
└─mpathdisk01 252:0    0  1.9G  0 mpath 
sde             8:64   0  3.8G  0 disk  
└─mpathdisk03 252:2    0  3.8G  0 mpath 
sdc             8:32   0  1.9G  0 disk  
└─mpathdisk01 252:0    0  1.9G  0 mpath 
sda             8:0    0   40G  0 disk  
├─sda2          8:2    0    2G  0 part  [SWAP]
└─sda1          8:1    0   38G  0 part  /
sdh             8:112  0  2.9G  0 disk  
└─mpathdisk02 252:1    0  2.9G  0 mpath 


[root@pg2 ~]# ll /dev/mapper/mpathdisk0*
lrwxrwxrwx 1 root root 7 Aug  3 23:00 /dev/mapper/mpathdisk01 -> ../dm-0
lrwxrwxrwx 1 root root 7 Aug  3 23:00 /dev/mapper/mpathdisk02 -> ../dm-1
lrwxrwxrwx 1 root root 7 Aug  3 23:00 /dev/mapper/mpathdisk03 -> ../dm-2

4.查看多路径信息

[root@pg2 ~]# multipath -ll | grep mpath
mpathdisk01 (14f504e46494c455273526c5666382d427931672d42633257) dm-0 OPNFILER,VIRTUAL-DISK    
mpathdisk03 (14f504e46494c45526c4f646f63452d4a5577352d48665731) dm-2 OPNFILER,VIRTUAL-DISK    
mpathdisk02 (14f504e46494c45525165745934692d337139312d32427555) dm-1 OPNFILER,VIRTUAL-DISK

[root@pg2 ~]# multipath -ll | grep mpath | wc -l
3

5.取出wwid

[root@pg2 ~]# multipath -ll | grep dm- | awk -F "(" '{print $2}' | awk -F ")" '{print $1}' | sort
14f504e46494c45525165745934692d337139312d32427555
14f504e46494c45526c4f646f63452d4a5577352d48665731
14f504e46494c455273526c5666382d427931672d42633257

[root@pg2 ~]# cat 1.txt 
14f504e46494c45525165745934692d337139312d32427555
14f504e46494c45526c4f646f63452d4a5577352d48665731
14f504e46494c455273526c5666382d427931672d42633257
[root@pg2 ~]# cat 2.txt 
14f504e46494c45526c4f646f63452d4a5577352d48665731
14f504e46494c455273526c5666382d427931672d42633257

[root@pg2 ~]#  diff 2.txt 1.txt 
0a1
> 14f504e46494c45525165745934692d337139312d32427555
ps:diff对比出来两个文件的差异值

扫盘

1.通过powermt命令获得HBA 卡列表,并扫描列表中所有的HBA
echo "---" > /sys/class/scsi_host/host[n]/scan

2.可以使用 echo 命令来扫描每个 SCSI 主机设备,如下所示
echo "1" >> /sys/class/scsi_host/host[n]/issue_lip

[root@pg2 ~]# udevadm trigger --type=devices --action=change
[root@pg2 ~]# 

你可能感兴趣的:(linux,centos,运维)