Лаба ISCSI

How can we help?

Навигация

Схема:

на R1:

[root@localhost ~]# hostnamectl set-hostname target
[root@localhost ~]# bash
[root@target ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
DEVICE=enp0s8
IPADDR=10.0.12.1
PREFIX=24
ONBOOT=yes
[root@target ~]# systemctl restart network
[root@target ~]# ip a
...
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:9b:36:c9 brd ff:ff:ff:ff:ff:ff
    inet 10.0.12.1/24 brd 10.0.12.255 scope global noprefixroute enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::e4af:f22a:6c21:ffc5/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
...
[root@target ~]# yum install targetcli -y
....
[root@target ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@target ~]# systemctl start target
[root@target ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
   Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
   Active: active (exited) since Пн 2022-06-27 20:05:42 MSK; 12s ago
  Process: 20770 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
 Main PID: 20770 (code=exited, status=0/SUCCESS)

июн 27 20:05:42 target systemd[1]: Starting Restore LIO kernel target configuration...
июн 27 20:05:42 target target[20770]: No saved config file at /etc/target/saveconfig.json, ok, exiting
июн 27 20:05:42 target systemd[1]: Started Restore LIO kernel target configuration.

[root@target ~]# yum info target
Загружены модули: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.corbina.net
 * extras: mirror.yandex.ru
 * updates: mirror.yandex.ru
Ошибка: Совпадений среди пакетов не найдено
[root@target ~]# yum info targetcli
Загружены модули: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.corbina.net
 * extras: mirror.yandex.ru
 * updates: mirror.yandex.ru
Установленные пакеты
Название: targetcli
Архитектура: noarch
Версия: 2.1.53
Выпуск: 1.el7_9
Объем: 254 k
Источник: installed
Из источника: updates
Аннотация: An administration shell for storage targets
Ссылка: https://github.com/open-iscsi/targetcli-fb
Лицензия: ASL 2.0
Описание: An administration shell for configuring iSCSI, FCoE, and other
        : SCSI targets, using the TCM/LIO kernel target subsystem. FCoE
        : users will also need to install and use fcoe-utils.

[root@target ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   10G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0    9G  0 part
  ├─centos-root 253:0    0    8G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
sdb               8:16   0  100M  0 disk
sr0              11:0    1 1024M  0 rom

[root@target ~]# 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'.

/>      # двойной tab показывает доступные команды
*              /              backstores/    iscsi/         loopback/      bookmarks      cd
clearconfig    exit           get            help           ls             pwd            refr
restoreconfig  saveconfig     sessions       set            status         version

/> /backstores> block/ create name=TEST-DISK-100M dev=/dev/sdb
Created block storage object TEST-DISK-100M using /dev/sdb.

/backstores> ls
o- backstores ......................................................................................... [...]
  o- block ............................................................................. [Storage Objects: 1]
  | o- TEST-DISK-100M .......................................... [/dev/sdb (100.0MiB) write-thru deactivated]
  |   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]

/backstores> cd ..
/> iscsi/
/iscsi> create wwn=iqn.2022-06.ru.wifikzn
Created target iqn.2022-06.ru.wifikzn.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

/iscsi> cd ..
/> ls
o- / .................................................................................................. [...]
  o- backstores ....................................................................................... [...]
  | o- block ........................................................................... [Storage Objects: 1]
  | | o- TEST-DISK-100M ........................................ [/dev/sdb (100.0MiB) write-thru deactivated]
  | |   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.2022-06.ru.wifikzn ..................................................................... [TPGs: 1]
  |   o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  |     o- acls ................................................................................... [ACLs: 0]
  |     o- luns ................................................................................... [LUNs: 0]
  |     o- portals ............................................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 .............................................................................. [OK]
  o- loopback .................................................................................. [Targets: 0]

/> iscsi/iqn.2022-06.ru.wifikzn/tpg1/luns
@last      bookmarks  cd         create     delete     exit       get        help       ls
pwd        refresh    set        status

/> iscsi/iqn.2022-06.ru.wifikzn/tpg1/luns create /backstores/block/TEST-DISK-100M
Created LUN 0.
 
/> iscsi/iqn.2022-06.ru.wifikzn/tpg1/acls create wwn=iqn.1994-05.com.redhat:b97aa511f960
Created Node ACL for iqn.1994-05.com.redhat:b97aa511f960
Created mapped LUN 0.
 
/> cd ..
/> ls
o- / .................................................................................................. [...]
  o- backstores ....................................................................................... [...]
  | o- block ........................................................................... [Storage Objects: 1]
  | | o- TEST-DISK-100M .......................................... [/dev/sdb (100.0MiB) 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.2022-06.ru.wifikzn ..................................................................... [TPGs: 1]
  |   o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  |     o- acls ................................................................................... [ACLs: 1]
  |     | o- iqn.1994-05.com.redhat:b97aa511f960 ........................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ................................................. [lun0 block/TEST-DISK-100M (rw)]
  |     o- luns ................................................................................... [LUNs: 1]
  |     | o- lun0 ...................................... [block/TEST-DISK-100M (/dev/sdb) (default_tg_pt_gp)]
  |     o- portals ............................................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 .............................................................................. [OK]
  o- loopback .................................................................................. [Targets: 0]

/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json

[root@target ~]# ss -lntpu
Netid State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port
... 
tcp   LISTEN     0      256                      *:3260                                 *:*
...

[root@target ~]# yum install tcpdump -y

[root@target ~]# tcpdump -nni enp0s8
...
21:44:50.571382 IP 10.0.12.2.33158 > 10.0.12.1.3260: Flags [S], seq 2709168090, win 29200, options [mss 1460,sackOK,TS val 25580525 ecr 0,nop,wscale 7], length 0
21:44:50.571445 IP 10.0.12.1 > 10.0.12.2: ICMP host 10.0.12.1 unreachable - admin prohibited, length 68
...

[root@target ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Пн 2022-06-27 19:04:21 MSK; 2h 41min ago
     Docs: man:firewalld(1)
 Main PID: 683 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─683 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

июн 27 19:04:21 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
июн 27 19:04:21 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
июн 27 19:04:21 localhost.localdomain firewalld[683]: WARNING: AllowZoneDrifting is enabled. This is...ow.
Hint: Some lines were ellipsized, use -l to show in full.

[root@target ~]# tcpdump -nni enp0s8
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
21:55:43.626409 ARP, Request who-has 10.0.12.1 tell 10.0.12.2, length 46
21:55:43.626439 ARP, Reply 10.0.12.1 is-at 08:00:27:9b:36:c9, length 28
21:55:43.626700 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [S], seq 4280087857, win 29200, options [mss 1460,sackOK,TS val 26233575 ecr 0,nop,wscale 7], length 0
21:55:43.626732 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [S.], seq 725768401, ack 4280087858, win 28960, options [mss 1460,sackOK,TS val 9986579 ecr 26233575,nop,wscale 7], length 0
21:55:43.627021 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [.], ack 1, win 229, options [nop,nop,TS val 26233581 ecr 9986579], length 0
21:55:43.627125 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [P.], seq 1:49, ack 1, win 229, options [nop,nop,TS val 26233581 ecr 9986579], length 48
21:55:43.627130 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [.], ack 49, win 227, options [nop,nop,TS val 9986580 ecr 26233581], length 0
21:55:43.627138 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [P.], seq 49:297, ack 1, win 229, options [nop,nop,TS val 26233581 ecr 9986579], length 248
21:55:43.627141 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [.], ack 297, win 235, options [nop,nop,TS val 9986580 ecr 26233581], length 0
21:55:43.628532 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [P.], seq 1:249, ack 297, win 235, options [nop,nop,TS val 9986581 ecr 26233581], length 248
21:55:43.628644 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [.], ack 249, win 237, options [nop,nop,TS val 26233583 ecr 9986581], length 0
21:55:43.628754 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [P.], seq 297:345, ack 249, win 237, options [nop,nop,TS val 26233583 ecr 9986581], length 48
21:55:43.628796 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [P.], seq 345:361, ack 249, win 237, options [nop,nop,TS val 26233583 ecr 9986581], length 16
21:55:43.628889 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [.], ack 361, win 235, options [nop,nop,TS val 9986581 ecr 26233583], length 0
21:55:43.628907 IP 10.0.12.1.3260 > 10.0.12.2.33168: Flags [P.], seq 249:365, ack 361, win 235, options [nop,nop,TS val 9986581 ecr 26233583], length 116
21:55:43.629623 IP 10.0.12.2.33168 > 10.0.12.1.3260: Flags [R.], seq 361, ack 365, win 237, options [nop,nop,TS val 26233583 ecr 9986581], length 0
21:55:48.631243 ARP, Request who-has 10.0.12.2 tell 10.0.12.1, length 28
21:55:48.631519 ARP, Reply 10.0.12.2 is-at 08:00:27:21:20:c7, length 46
^C
18 packets captured
18 packets received by filter
0 packets dropped by kernel







На R2:

[root@localhost ~]# hostnamectl set-hostname initiator
[root@localhost ~]# bash
[root@initiator ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
DEVICE=enp0s8
IPADDR=10.0.12.2
PREFIX=24
ONBOOT=yes
[root@initiator ~]# ifdown enp0s8
[root@initiator ~]# ifup enp0s8
[root@initiator ~]# ip a
...
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:21:20:c7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.12.2/24 brd 10.0.12.255 scope global noprefixroute enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::6004:14f:fe6e:b10a/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
...

[root@initiator ~]# yum install iscsi-initiator-utils
...
Установлено:
  iscsi-initiator-utils.x86_64 0:6.2.0.874-22.el7_9

Установлены зависимости:
  iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-22.el7_9

Выполнено!

[root@initiator ~]# ls /etc/is
iscsi/     issue      issue.net
[root@initiator ~]# cd /etc/iscsi/
[root@initiator iscsi]# ll
итого 20
-rw-r--r--. 1 root root    50 июн 27 20:29 initiatorname.iscsi
-rw-------. 1 root root 12602 ноя 24  2021 iscsid.conf
[root@initiator iscsi]# cat initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:b97aa511f960 # это имя добавляем в acls target

[root@initiator iscsi]# man iscsiadm  # копируем из радела examples
[root@initiator iscsi]# iscsiadm --mode discoverydb --type sendtargets --portal 10.0.12.1 --discover
iscsiadm: cannot make connection to 10.0.12.1: No route to host
iscsiadm: cannot make connection to 10.0.12.1: No route to host
^Ciscsiadm: caught SIGINT, exiting...

[root@initiator iscsi]# yum install tcpdump
...
Установлено:
  tcpdump.x86_64 14:4.9.2-4.el7_7.1

Установлены зависимости:
  libpcap.x86_64 14:1.5.3-13.el7_9

Выполнено!

# после отключения файрвола соединение устанавливается
 
[root@initiator iscsi]# iscsiadm --mode discoverydb --type sendtargets --portal 10.0.12.1 --discover
10.0.12.1:3260,1 iqn.2022-06.ru.wifikzn

[root@initiator iscsi]# man iscsiadm  # копируем из радела examples
[root@initiator iscsi]# iscsiadm --mode node --targetname iqn.2022-06.ru.wifikzn --portal 10.0.12.1:3260 --login
Logging in to [iface: default, target: iqn.2022-06.ru.wifikzn, portal: 10.0.12.1,3260] (multiple)
Login to [iface: default, target: iqn.2022-06.ru.wifikzn, portal: 10.0.12.1,3260] successful.

[root@initiator iscsi]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   10G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0    9G  0 part
  ├─centos-root 253:0    0    8G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
sdb               8:16   0  100M  0 disk
sr0              11:0    1 1024M  0 rom

[root@initiator iscsi]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb               isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@initiator iscsi]# mkdir /test && mount /dev/sdb /test

[root@initiator iscsi]# cd  /test
[root@initiator test]# touch lkscs ljksndlwkn lkndlkwnd
[root@initiator test]# ll
итого 0
-rw-r--r--. 1 root root 0 июн 27 22:07 ljksndlwkn
-rw-r--r--. 1 root root 0 июн 27 22:07 lkndlkwnd
-rw-r--r--. 1 root root 0 июн 27 22:07 lkscs

[root@initiator test]# df -h
Файловая система        Размер Использовано  Дост Использовано% Cмонтировано в
devtmpfs                  484M            0  484M            0% /dev
tmpfs                     496M            0  496M            0% /dev/shm
tmpfs                     496M          13M  483M            3% /run
tmpfs                     496M            0  496M            0% /sys/fs/cgroup
/dev/mapper/centos-root   8,0G         1,4G  6,7G           18% /
/dev/sda1                1014M         138M  877M           14% /boot
tmpfs                     100M            0  100M            0% /run/user/0
/dev/sdb                   97M         5,3M   92M            6% /test