linux

centos - multipath + iscsi 설정

sysman 2021. 1. 2. 14:13

 (server target)       ens37 192.168.20.1  -------   192.168.20.2 ens37        (client initiator)

server1                                                                                       server2

                          ens38 192.168.30.1  -------   192.168.30.2 ens38

 

 

server1 target

[root@server1 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0  100G  0 disk

├─sda1   8:1    0    2G  0 part /boot

├─sda2   8:2    0   50G  0 part /var

├─sda3   8:3    0    5G  0 part /home

├─sda4   8:4    0    1K  0 part

├─sda5   8:5    0    4G  0 part [SWAP]

└─sda6   8:6    0   39G  0 part /

sdb      8:16   0    2G  0 disk

sdc      8:32   0    2G  0 disk

sr0     11:0    1 1024M  0 rom

 

[root@server1 ~]# fdisk /dev/sdb

[root@server1 ~]# fdisk /dev/sdc

 

 

[root@server1 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0  100G  0 disk

├─sda1   8:1    0    2G  0 part /boot

├─sda2   8:2    0   50G  0 part /var

├─sda3   8:3    0    5G  0 part /home

├─sda4   8:4    0    1K  0 part

├─sda5   8:5    0    4G  0 part [SWAP]

└─sda6   8:6    0   39G  0 part /

sdb      8:16   0    2G  0 disk

└─sdb1   8:17   0    2G  0 part

sdc      8:32   0    2G  0 disk

└─sdc1   8:33   0    2G  0 part

sr0     11:0    1 1024M  0 rom

 

[root@server1 ~]# dnf -y install lvm2 targetcli

 

[root@server1 ~]# pvcreate /dev/sd[cd]1

  Physical volume "/dev/sdc1" successfully created.

[root@server1 ~]# vgcreate vg1 /dev/sd[bc]1

  Physical volume "/dev/sdb1" successfully created.

  Volume group "vg1" successfully created

[root@server1 ~]# lvcreate -l 100%FREE vg1 -n lv_iscsi

  Logical volume "lv_iscsi" created.

[root@server1 ~]# lvscan

  ACTIVE            '/dev/vg1/lv_iscsi' [3.99 GiB] inherit

 

 

[root@server1 ~]# targetcli

Warning: Could not load preferences file /root/.targetcli/prefs.bin.

targetcli shell version 2.1.53

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

 

/> ls

/> cd /backstores/block

/backstores/block> create block1 /dev/vg1/lv_iscsi

Created block storage object block1 using /dev/vg1/lv_iscsi.

/backstores/block> cd ..

/backstores> cd ..

/> cd iscsi

/iscsi> create iqn.2020-12.com.example.server1:disk1

/iscsi> cd iqn.2020-12.com.example.server1:disk1/tpg1/acls

/iscsi/iqn.20...sk1/tpg1/acls> create iqn.2020-12.com.example.server2:server2

/iscsi/iqn.20...sk1/tpg1/acls> cd ..

/iscsi/iqn.20...r1:disk1/tpg1> cd luns

/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/block1

/> cd /iscsi/iqn.2020-12.com.example.server1:disk1/tpg1/portals/

/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260

/iscsi/iqn.20.../tpg1/portals> create 192.168.20.1 3260

/iscsi/iqn.20.../tpg1/portals> create 192.168.30.1 3260

/iscsi/iqn.20.../tpg1/portals> ls

o- portals ........................................................ [Portals: 2]

  o- 192.168.20.1:3260 .................................................... [OK]

  o- 192.168.30.1:3260 .................................................... [OK]

/iscsi/iqn.20.../tpg1/portals> exit

Global pref auto_save_on_exit=true

Configuration saved to /etc/target/saveconfig.json

[root@server1 ~]#

[root@server1 ~]# targetcli ls

o- / ..................................................................... [...]

  o- backstores .......................................................... [...]

  | o- block .............................................. [Storage Objects: 1]

  | | o- block1 .............. [/dev/vg1/lv_iscsi (4.0GiB) write-thru activated]

  | |   o- alua ............................................... [ALUA Groups: 1]

  | |     o- default_tg_pt_gp ................... [ALUA state: Active/optimized]

  | o- fileio ............................................. [Storage Objects: 0]

  | o- pscsi .............................................. [Storage Objects: 0]

  | o- ramdisk ............................................ [Storage Objects: 0]

  o- iscsi ........................................................ [Targets: 1]

  | o- iqn.2020-12.com.example.server1:disk1 ......................... [TPGs: 1]

  |   o- tpg1 ........................................... [no-gen-acls, no-auth]

  |     o- acls ...................................................... [ACLs: 1]

  |     | o- iqn.2020-12.com.example.server2:server2 .......... [Mapped LUNs: 1]

  |     |   o- mapped_lun0 ............................ [lun0 block/block1 (rw)]

  |     o- luns ...................................................... [LUNs: 1]

  |     | o- lun0 ........ [block/block1 (/dev/vg1/lv_iscsi) (default_tg_pt_gp)]

  |     o- portals ................................................ [Portals: 2]

  |       o- 192.168.20.1:3260 ............................................ [OK]

  |       o- 192.168.30.1:3260 ............................................ [OK]

  o- loopback ..................................................... [Targets: 0]

 

[root@server1 ~]# firewall-cmd --permanent --add-port=3260/tcp

[root@server1 ~]# firewall-cmd --reload

 

 

 

< test >

[root@server1 ~]# ifdown ens37

[root@server1 ~]# ifup ens37

[root@server1 ~]# ifdown ens38

[root@server1 ~]# ifup ens38

 

 

 

#############################################################################

#############################################################################

 

server2 initiator

[root@server2 ~]# dnf -y install iscsi-initiator-utils *multipath*

 

[root@server2 ~]# vi /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2020-12.com.example.server2:server2

[root@server2 ~]# systemctl restart iscsid

[root@server2 ~]# systemctl status iscsid

 

[root@server2 ~]# systemctl enable iscsid

[root@server2 ~]# systemctl enable multipathd

 

[root@server2 ~]# cp /usr/share/doc/device-mapper-multipath/multipath.conf /etc/

[root@server2 ~]# systemctl start multipathd

[root@server2 ~]# systemctl status multipathd

multipathd.service - Device-Mapper Multipath Device Controller

   Loaded: loaded (/usr/lib/systemd/system/multipathd.service; enabled; vendor >

   Active: active (running) since Fri 2021-01-01 23:09:48 EST; 7s ago

  Process: 4327 ExecStartPre=/sbin/multipath -A (code=exited, status=0/SUCCESS)

  Process: 4319 ExecStartPre=/sbin/modprobe -a scsi_dh_alua scsi_dh_emc scsi_dh>

 Main PID: 4329 (multipathd)

   Status: "up"

    Tasks: 7

   Memory: 12.7M

   CGroup: /system.slice/multipathd.service

           └─4329 /sbin/multipathd -d -s

 

Jan 01 23:09:47 server2.example.com systemd[1]: Starting Device-Mapper Multipat>

Jan 01 23:09:47 server2.example.com multipathd[4329]: --------start up--------

Jan 01 23:09:47 server2.example.com multipathd[4329]: read /etc/multipath.conf

Jan 01 23:09:47 server2.example.com multipathd[4329]: path checkers start up

Jan 01 23:09:48 server2.example.com multipathd[4329]: sda: failed to get udev u>

Jan 01 23:09:48 server2.example.com multipathd[4329]: sda: failed to get unknow>

Jan 01 23:09:48 server2.example.com systemd[1]: Started Device-Mapper Multipath>

 

 

[root@server2 ~]# multipath -ll    //멀티패스 구성이 없어 아무것도 안나옴

 

[root@server2 ~]# iscsiadm -m discovery -t st -p 192.168.20.1

192.168.20.1:3260,1 iqn.2020-12.com.example.server1:disk1

192.168.30.1:3260,1 iqn.2020-12.com.example.server1:disk1

 

[root@server2 ~]# iscsiadm -m node -T iqn.2020-12.com.example.server1:disk1 -p 192.168.20.1:3260 -l

Logging in to [iface: default, target: iqn.2020-12.com.example.server1:disk1, portal: 192.168.20.1,3260]

Login to [iface: default, target: iqn.2020-12.com.example.server1:disk1, portal: 192.168.20.1,3260] successful.

[root@server2 ~]# iscsiadm -m node -T iqn.2020-12.com.example.server1:disk1 -p 192.168.30.1:3260 -l

Logging in to [iface: default, target: iqn.2020-12.com.example.server1:disk1, portal: 192.168.30.1,3260]

Login to [iface: default, target: iqn.2020-12.com.example.server1:disk1, portal: 192.168.30.1,3260] successful.

 

[root@server2 ~]# multipath -ll

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=active

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=50 status=enabled

  `- 4:0:0:0 sdc 8:32 active ready running

[root@server2 ~]# multipath -l

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=0 status=active

| `- 3:0:0:0 sdb 8:16 active undef running

`-+- policy='service-time 0' prio=0 status=enabled

  `- 4:0:0:0 sdc 8:32 active undef running

[root@server2 ~]# cat /etc/multipath/bindings

# Multipath bindings, Version : 1.0

# NOTE: this file is automatically maintained by the multipath program.

# You should not need to edit this file in normal circumstances.

#

# Format:

# alias wwid

#

mpatha 36001405c0f1a523f8474196a94c2cf2f

[root@server2 ~]# cat /etc/multipath/wwids

# Multipath wwids, Version : 1.0

# NOTE: This file is automatically maintained by multipath and multipathd.

# You should not need to edit this file in normal circumstances.

#

# Valid WWIDs:

/36001405c0f1a523f8474196a94c2cf2f/

 

[root@server2 ~]# lsblk

NAME     MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT

sda        8:0    0  100G  0 disk

├─sda1     8:1    0    2G  0 part  /boot

├─sda2     8:2    0   50G  0 part  /var

├─sda3     8:3    0    5G  0 part  /home

├─sda4     8:4    0    1K  0 part

├─sda5     8:5    0    4G  0 part  [SWAP]

└─sda6     8:6    0   39G  0 part  /

sdb        8:16   0    4G  0 disk

└─mpatha 253:0    0    4G  0 mpath

sdc        8:32   0    4G  0 disk

└─mpatha 253:0    0    4G  0 mpath

sr0       11:0    1 1024M  0 rom

[root@server2 ~]# ls -Rl /var/lib/iscsi/nodes/

/var/lib/iscsi/nodes/:

total 0

drw-------. 4 root root 60 Jan  1 23:12 iqn.2020-12.com.example.server1:disk1

 

'/var/lib/iscsi/nodes/iqn.2020-12.com.example.server1:disk1':

total 0

drw-------. 2 root root 21 Jan  1 23:12 192.168.20.1,3260,1

drw-------. 2 root root 21 Jan  1 23:12 192.168.30.1,3260,1

 

'/var/lib/iscsi/nodes/iqn.2020-12.com.example.server1:disk1/192.168.20.1,3260,1':

total 4

-rw-------. 1 root root 2154 Jan  1 23:12 default

 

'/var/lib/iscsi/nodes/iqn.2020-12.com.example.server1:disk1/192.168.30.1,3260,1':

total 4

-rw-------. 1 root root 2154 Jan  1 23:12 default

[root@server2 ~]#

[root@server2 ~]#

 

[root@server2 /]# iscsiadm -m iface -P 1

Iface: default

        Target: iqn.2020-12.com.example.server1:disk1

                Portal: 192.168.20.1:3260,1

                Portal: 192.168.30.1:3260,1

Iface: iser

[root@server2 /]# fdisk -l

 

Disk /dev/mapper/mpatha: 4 GiB, 4286578688 bytes, 8372224 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 4194304 bytes

 

[root@server2 /]# fdisk /dev/mapper/mpatha

 

Welcome to fdisk (util-linux 2.32.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table.

Created a new DOS disklabel with disk identifier 0xecc29086.

 

Command (m for help): p

Disk /dev/mapper/mpatha: 4 GiB, 4286578688 bytes, 8372224 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 4194304 bytes

Disklabel type: dos

Disk identifier: 0xecc29086

 

Command (m for help): n

Partition type

   p   primary (0 primary, 0 extended, 4 free)

   e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1):

First sector (8192-8372223, default 8192):

Last sector, +sectors or +size{K,M,G,T,P} (8192-8372223, default 8372223):

 

Created a new partition 1 of type 'Linux' and of size 4 GiB.

 

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

 

Command (m for help): p

Disk /dev/mapper/mpatha: 4 GiB, 4286578688 bytes, 8372224 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 4194304 bytes

Disklabel type: dos

Disk identifier: 0xecc29086

 

Device                   Boot Start     End Sectors Size Id Type

/dev/mapper/mpatha-part1       8192 8372223 8364032   4G 8e Linux LVM

 

Command (m for help): w

The partition table has been altered.

Failed to add partition 1 to system: Invalid argument

 

The kernel still uses the old partitions. The new table will be used at the next reboot.

Syncing disks.

 

 

[root@server2 /]# mkdir mpatha

 

[root@server2 /]# mkfs.ext4 /dev/mapper/mpatha1

mke2fs 1.45.6 (20-Mar-2020)

Creating filesystem with 1045504 4k blocks and 261632 inodes

Filesystem UUID: 9b7a0514-ce55-4f4f-9c7a-cbf35faf231a

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736

 

Allocating group tables: done

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

 

[root@server2 /]# mount /dev/mapper/mpatha1 /mpatha/

[root@server2 /]# df -Th

Filesystem          Type      Size  Used Avail Use% Mounted on

devtmpfs            devtmpfs  957M     0  957M   0% /dev

tmpfs               tmpfs     975M     0  975M   0% /dev/shm

tmpfs               tmpfs     975M  8.8M  966M   1% /run

tmpfs               tmpfs     975M     0  975M   0% /sys/fs/cgroup

/dev/sda6           xfs        39G  1.7G   38G   5% /

/dev/sda2           xfs        50G  591M   50G   2% /var

/dev/sda3           xfs       5.0G   69M  5.0G   2% /home

/dev/sda1           xfs       2.0G  176M  1.9G   9% /boot

tmpfs               tmpfs     195M     0  195M   0% /run/user/0

/dev/mapper/mpatha1 ext4      3.9G   16M  3.7G   1% /mpatha

[root@server2 /]# multipath -ll

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=active

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=50 status=enabled

  `- 4:0:0:0 sdc 8:32 active ready running

 

[root@server2 /]# multipath -ll

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=active

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=50 status=enabled

  `- 4:0:0:0 sdc 8:32 active ready running

 

 

 

< test >

[root@server2 /]# cd /mpatha/

[root@server2 mpatha]# echo 1111 >> file1

[root@server2 mpatha]# echo 1111 >> file2

[root@server2 mpatha]# ls

file1  file2  lost+found

[root@server2 mpatha]# ls -l

total 24

-rw-r--r--. 1 root root     5 Jan  1 23:26 file1

-rw-r--r--. 1 root root     5 Jan  1 23:26 file2

drwx------. 2 root root 16384 Jan  1 23:25 lost+found

 

[root@server2 mpatha]# ping 192.168.20.1

PING 192.168.20.1 (192.168.20.1) 56(84) bytes of data.

^C

--- 192.168.20.1 ping statistics ---

2 packets transmitted, 0 received, 100% packet loss, time 38ms

 

 

[root@server2 mpatha]# ping 192.168.20.1

PING 192.168.20.1 (192.168.20.1) 56(84) bytes of data.

^C

--- 192.168.20.1 ping statistics ---

2 packets transmitted, 0 received, 100% packet loss, time 43ms

 

[root@server2 mpatha]# ping 192.168.30.1

PING 192.168.30.1 (192.168.30.1) 56(84) bytes of data.

64 bytes from 192.168.30.1: icmp_seq=1 ttl=64 time=0.506 ms

^C

--- 192.168.30.1 ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 0.506/0.506/0.506/0.000 ms

 

[root@server2 mpatha]# multipath -ll //ens37 포트 다운

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=0 status=enabled

| `- 3:0:0:0 sdb 8:16 failed faulty running

`-+- policy='service-time 0' prio=50 status=active

  `- 4:0:0:0 sdc 8:32 active ready running

[root@server2 mpatha]# multipath -ll  //ens38 포트 업

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=enabled

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=50 status=active

  `- 4:0:0:0 sdc 8:32 active ready running

 

[root@server2 mpatha]#

[root@server2 mpatha]# ls

file1  file2  lost+found

[root@server2 mpatha]# multipath -ll  

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=enabled

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=0 status=active

  `- 4:0:0:0 sdc 8:32 failed faulty running

 

 

[root@server2 mpatha]# echo 111 >> file3

[root@server2 mpatha]#

[root@server2 mpatha]# ls

file1  file2  file3  lost+found

[root@server2 mpatha]# multipath -ll     //ens38 포트 다운

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw  

|-+- policy='service-time 0' prio=50 status=active

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=0 status=enabled

  `- 4:0:0:0 sdc 8:32 failed faulty running

[root@server2 mpatha]#

[root@server2 mpatha]#

[root@server2 mpatha]#

[root@server2 mpatha]# multipath -ll    //ens38 포트 업

mpatha (36001405c0f1a523f8474196a94c2cf2f) dm-0 LIO-ORG,block1

size=4.0G features='0' hwhandler='1 alua' wp=rw

|-+- policy='service-time 0' prio=50 status=active

| `- 3:0:0:0 sdb 8:16 active ready running

`-+- policy='service-time 0' prio=50 status=enabled

  `- 4:0:0:0 sdc 8:32 active ready running

[root@server2 mpatha]#

'linux' 카테고리의 다른 글

centos 8 - pacemaker  (0) 2021.01.03
centos - keepalived (링크 이중화 vrrp)  (0) 2021.01.03
centos - vlan 설정  (0) 2020.12.31
centos teaming 티밍 - activebackup  (0) 2020.12.31
centos - 초기세팅  (0) 2020.12.30