Создание iSCSI Target через файл

Машина с СХД

Подготовка

Создаем файл через утилиту dd

dd if=/dev/zero of=/путь_к_файлу bs=1M count=размер_файла_в_мегабайтах

Вывод получим примерно такой:

500000+0 records in
500000+0 records out
524288000000 bytes (524 GB) copied, 6269.29 s, 83.6 MB/s

Далее устанавливаем scsi

yum install scsi-target-utils

И сразу запускаем сервис

service tgtd start

Проверяем его наличие

netstat -tulpn | grep 3260

Вывод

tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      25236/tgtd
tcp        0      0 :::3260                     :::*                        LISTEN      25236/tgtd

Создание LUN-а

Создаем

tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2013-04.ru.pnv152:storage.lun0

Проверяем

tgtadm --lld iscsi --op show --mode target

Вывод такой

Target 1: iqn.2013-04.ru.pnv152:storage.lun0
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
    Account information:
    ACL information:

Теперь цепляем созданный файл

tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /путь_к_файлу

Проверяем

tgtadm --lld iscsi --op show --mode target

Вывод

Target 1: iqn.2013-04.ru.pnv152:storage.lun0
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 524288 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /путь_к_файлу
            Backing store flags:
    Account information:
    ACL information:

Разрешаем всем цеплять его

tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL

Записываем конфиг в файл

tgt-admin --dump > /etc/tgt/targets.conf

Добавляем в автозагрузку

chkconfig tgtd on

Проверка

Рестартуем сервис и проверяем, что все наши внесенные изменения сохранились

service tgtd restart
tgtadm --lld iscsi --op show --mode target

Вывод

Target 1: iqn.2013-04.ru.pnv152:storage.lun0
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 524288 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /путь_к_файлу
            Backing store flags:
    Account information:
    ACL information:
        ALL

Машина клиент

Цепляем LUN

/sbin/iscsiadm -m discovery -t st -p 192.168.0.1

Вывод

192.168.0.1:3260,1 iqn.2013-04.ru.pnv152:storage.lun0
/sbin/iscsiadm -m node -T iqn.2013-04.ru.pnv152:storage.lun0 -l

Вывод

Logging in to [iface: default, target: iqn.2013-04.ru.pnv152:storage.lun0, portal: 192.168.0.1,3260]
Login to [iface: default, target: iqn.2013-04.ru.pnv152:storage.lun0, portal: 192.168.0.1,3260] successful.

Проверяем

dmesg | tail

Вывод

sdf: Write Protect is off
sdf: Mode Sense: 49 00 00 08
SCSI device sdf: drive cache: write back
SCSI device sdf: 1024000000 512-byte hdwr sectors (524288 MB)
sdf: Write Protect is off
sdf: Mode Sense: 49 00 00 08
SCSI device sdf: drive cache: write back
 sdf: unknown partition table
sd 48:0:0:1: Attached scsi disk sdf
sd 48:0:0:1: Attached scsi generic sg9 type 0

Работа с разделом

Запускаем fdisk

/sbin/fdisk /dev/sdf

Далее выведу всю работу в этой утилите без пояснения… думаю и так понятно ;)

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 63741.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdf: 524.2 GB, 524288000000 bytes
255 heads, 63 sectors/track, 63741 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-63741, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-63741, default 63741):
Using default value 63741

Command (m for help): p

Disk /dev/sdf: 524.2 GB, 524288000000 bytes
255 heads, 63 sectors/track, 63741 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1               1       63741   511999551   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Теперь форматируем раздел

/sbin/mkfs.ext3 /dev/sdf1

Вывод

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
64012288 inodes, 127999887 blocks
6399994 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3907 block groups
32768 blocks per group, 32768 fragments per group
16384 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

Writing inode tables: 1535/3907

Смотрим UID диска

/sbin/blkid /dev/sdf1

Вывод

/dev/sdf1: UUID="230956d3-1f9e-4a47-с01a-68e194acfbc5" SEC_TYPE="ext2" TYPE="ext3"

Добавляем в /etc/fstab с целью автоматического монтирования после ребута

UUID=230956d3-1f9e-4a47-с01a-68e194acfbc5       /mnt/new_disk    ext3    _netdev 0 0

ВСЕ ГОТОВО!

С целью полной проверки

  1. Машину с СХД - в ребут
  2. Машина-клиент - в ребут
  3. На Машине с СХД
tgtadm --lld iscsi --op show --mode target

Вывод после подцепки LUN-а немного другой

Target 1: iqn.2013-04.ru.pnv152:storage.lun0
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
        I_T nexus: 1
            Initiator: iqn.1994-05.com.redhat:6af9206523ff
            Connection: 0
                IP Address: 192.168.0.2
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 524288 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /путь_к_файлу
            Backing store flags:
    Account information:
    ACL information:
        ALL
  1. На Машине-клиенте
df -h

Вывод

Filesystem            Size  Used Avail Use% Mounted on
...
/dev/sdf1             481G  340G  117G  75% /mnt/new_disk

Использованные статьи

Яндекс.Метрика