Device Mapper Multipath on CentOS 7.9
Yusuf Al Afid
5 min read
Topology
iSCSI Target Node
2 vCPU
4 GB RAM
50 GB OS Disk
100 GB Backed Disk
iSCSI Initiator
2 vCPU
4 GB RAM
50 GB OS Disk
iSCSI Target Configurations
- Setup backing storage device
# fdisk /dev/sdb
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +50G
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
- Install targetcli
yum install targetcli -y
- Create Backstore
# tergetcli
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 0]
| o- fileio ................................................................................................. [Storage Objects: 0]
| o- pscsi .................................................................................................. [Storage Objects: 0]
| o- ramdisk ................................................................................................ [Storage Objects: 0]
o- iscsi ............................................................................................................ [Targets: 0]
o- loopback ......................................................................................................... [Targets: 0]
/> cd backstores/block
/backstores/block> create dev=/dev/sdb1 name=sdb1
Created block storage object sdb1 using /dev/sdb1.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 1]
o- sdb1 ............................................................................. [/dev/sdb1 (50.0GiB) write-thru deactivated]
o- alua ....................................................................................................... [ALUA Groups: 1]
o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
- Create iscsi target
/> cd iscsi
/iscsi> create wwn=iqn.2022-01.lab.mtm:servers
Created target iqn.2022-01.lab.mtm:servers.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
- Create ACL
/iscsi> cd iqn.2022-01.lab.mtm:servers/tpg1/acls
/iscsi/iqn.20...ers/tpg1/acls> create wwn=iqn.2022-01.lab.mtm:initiator
Created Node ACL for iqn.2022-01.lab.mtm:initiator
/iscsi/iqn.20...ers/tpg1/acls> ls
o- acls .................................................................................................................. [ACLs: 1]
o- iqn.2022-01.lab.mtm:initiator ................................................................................ [Mapped LUNs: 0]
- Create LUN
/iscsi/iqn.20...ers/tpg1/acls> cd /
/> cd iscsi/iqn.2022-01.lab.mtm:servers/tpg1/luns
/iscsi/iqn.20...ers/tpg1/luns> create /backstores/block/sdb1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2022-01.lab.mtm:initiator
- Setup Firewall
# firewall-cmd --add-port=3260/tcp --permanent
# firewall-cmd --reload
Configure Initiator
- install initiator utils
yum -y install iscsi-initiator-utils
- Set initiator name
vim /etc/iscsi/initiatorname.iscsi
---
InitiatorName=iqn.2022-01.lab.mtm:initiator
---
systemctl restart iscsid
- Discover icsci
iscsiadm -m discovery -t sendtargets -p 192.168.30.34
iscsiadm -m discovery -t sendtargets -p 192.168.30.35
- Login iscsi
iscsiadm -m node -t sendtargets -p 192.168.30.34 -l
iscsiadm -m node -t sendtargets -p 192.168.30.35 -l
- List device
fdisk -l
---
[root@iscsi-initiator etc]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000ebe3c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 48.3 GB, 48314187776 bytes, 94363648 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/mapper/centos-swap: 4290 MB, 4290772992 bytes, 8380416 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: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
---
Configure Multipath
- Install device mapper multipath
yum -y install device-mapper-multipath
- Load multipath
modprobe dm_multipath
- Generate default multipath.conf
mpathconf --enable --user_friendly_names y
- enable multipathd service
systemctl enable --now multipathd
- Check multipath topology
multipath -ll
---
mpatha (360014053752d02b333c4514bfe9cb164) dm-2 LIO-ORG ,sdb1
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active
| `- 35:0:0:0 sdb 8:16 active ready running
`-+- policy='service-time 0' prio=1 status=enabled
`- 36:0:0:0 sdc 8:32 active ready running
---
- Edit multipath configuration
vim /etc/multipath.conf
---
defaults {
polling_interval 10
path_selector "round-robin 0"
path_grouping_policy multibus
uid_attribute ID_SERIAL
prio alua
path_checker readsector0
rr_min_io 100
max_fds 8192
rr_weight priorities
failback immediate
no_path_retry fail
user_friendly_names yes
find_multipaths yes
}
blacklist {
wwid 26353900f02796769
devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
devnode "^hd[a-z]"
}
multipaths {
multipath {
path_grouping_policy multibus
path_selector "round-robin 0"
failback manual
rr_weight priorities
no_path_retry 5
}
multipath {
wwid 360014053752d02b333c4514bfe9cb164 ## wwid from multipath -ll command
alias mpdata
}
}
---
- Restart multipath
systemctl restart multipath
- Verification
# multipath -ll
---
Jan 30 13:49:27 | /etc/multipath.conf line 95, duplicate keyword: blacklist
mpdata (360014053752d02b333c4514bfe9cb164) dm-2 LIO-ORG ,sdb1
size=50G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=50 status=active
|- 35:0:0:0 sdb 8:16 active ready running
`- 36:0:0:0 sdc 8:32 active ready running
---
# fdisk -l
---
Disk /dev/mapper/mpdata: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk label type: dos
Disk identifier: 0x43f9b667
---
- Test mount
# fdisk /dev/mapper/mpdata
# mkfs.ext4 /dev/mapper/mpdata1
# mkdir /iscsi-mount
# mount /dev/mapper/mpdata /iscsi-mount
# lsblk
---
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 45G 0 lvm /
└─centos-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
└─mpdata 253:2 0 50G 0 mpath
└─mpdata1 253:3 0 50G 0 part /iscsi-mount
sdc 8:32 0 50G 0 disk
└─mpdata 253:2 0 50G 0 mpath
└─mpdata1 253:3 0 50G 0 part /iscsi-mount
---
0
Subscribe to my newsletter
Read articles from Yusuf Al Afid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by