ubuntu16.04下iscsi配置、測試教程

+----------------------+          |          +----------------------+
| [   iSCSI Target   ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator  ] |
|     dlp.srv.world    +----------+----------+     www.srv.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+

Configure iSCSI Target(targetcli)

  1. Install administration tools first.
root@dlp:~# apt-get -y install targetcli 
  1. Configure iSCSI Target.
# create a directory

root@dlp:~# mkdir /var/iscsi_disks

# enter the admin console

root@dlp:~# targetcli

targetcli 3.0.pre4.1~ga55d018 (rtslib 3.0.pre4.1~g1b33ceb)
Copyright (c) 2011-2014 by Datera, Inc.
All rights reserved.

/> cd backstores/fileio
# create a disk-image with the name "disk01" on /var/iscsi_disks/disk01.img with 10G

/backstores/fileio> create disk01 /var/iscsi_disks/disk01.img 10G

Using buffered mode.
Created fileio disk01.
/backstores/fileio> cd /iscsi
# create a target

/iscsi> create iqn.2016-04.world.srv:storage.target00

Created target iqn.2016-04.world.srv:storage.target00.
Selected TPG Tag 1.
Created TPG 1.
# set portal (set IP address to listen)

/iscsi> cd iqn.2016-04.world.srv:storage.target00/tpg1/portals

/iscsi/iqn.20.../tpg1/portals> create 0.0.0.0

Using default IP port 3260
Created network portal 0.0.0.0:3260.
/iscsi/iqn.20.../tpg1/portals> cd ../luns
# set LUN

/iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01

Selected LUN 0.
Created LUN 0.
/iscsi/iqn.20...t00/tpg1/luns> cd ../acls
# set ACL (it's the IQN of an initiator you permit to connect)

/iscsi/iqn.20...t00/tpg1/acls> create iqn.2016-04.world.srv:www.srv.world

Created Node ACL for iqn.2016-04.world.srv:www.srv.world:www.srv.world
Created mapped LUN 0.
/iscsi/iqn.20...t00/tpg1/acls> cd iqn.2016-04.world.srv:www.srv.world
# set UserID for authentication

/iscsi/iqn.20....srv.world> set auth userid=username

Parameter userid is now 'username'.
/iscsi/iqn.20....srv.world> set auth password=password

Parameter password is now 'password'.
/iscsi/iqn.20....srv.world> exit

Comparing startup and running configs...
Some changes need saving.
Save configuration? [Y/n]: y

Saving new startup configuration
# after configuration above, the target enters in listening like follows

root@dlp:~# ss -napt | grep 3260

LISTEN     0      256          *:3260                     *:*

# set auto-start

root@dlp:~# /lib/systemd/systemd-sysv-install enable target 

Configure iSCSI Target(iscsitarget)

  1. Install administration tools first.
root@dlp:~# apt-get -y install iscsitarget iscsitarget-dkms 
  1. Configure iSCSI Target.
# create disk image 10G

root@dlp:~# mkdir /var/iscsi_disks

root@dlp:~# dd if=/dev/zero of=/var/iscsi_disks/disk01.img count=10000000 bs=1024

# start iscsitarget

root@dlp:~# systemctl restart iscsitarget

iSCSI Initiator (Ubuntu)

  1. Configure iSCSI Initiator.
root@www:~# apt-get -y install open-iscsi
root@www:~# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server

InitiatorName=iqn.2016-04.world.srv:www.srv.world
root@www:~# vi /etc/iscsi/iscsid.conf
# line 53: uncomment

node.session.auth.authmethod = CHAP
# line 57,58: uncomment and specify the username and password you set on the iSCSI target server

node.session.auth.username = username

node.session.auth.password = password
root@www:~# systemctl restart iscsid open-iscsi
# discover target

root@www:~# iscsiadm -m discovery -t sendtargets -p 10.0.0.30

10.0.0.30:3260,1 iqn.2016-04.world.srv:storage.target00

# confirm status after discovery

root@www:~# iscsiadm -m node -o show

# BEGIN RECORD 2.0-873
node.name = iqn.2016-04.world.srv:storage.target00
node.tpgt = 1
node.startup = manual
node.leading_login = No
...
...
...
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD

# login to the target

root@www:~# iscsiadm -m node --login

Logging in to [iface: default, target: iqn.2016-04.world.srv:storage.target00, portal: 10.0.0.30,3260] (multiple)
Login to [iface: default, target: iqn.2016-04.world.srv:storage.target00, portal: 10.0.0.30,3260] successful.

# confirm the established session

root@www:~# iscsiadm -m session -o show

tcp: [2] 10.0.0.30:3260,1 iqn.2016-04.world.srv:storage.target00 (non-flash)
# confirm the partitions

root@www:~# cat /proc/partitions

major minor  #blocks  name

   1        0      65536 ram0
   1        1      65536 ram1
   1        2      65536 ram2
.....
.....
 252        0   26759168 dm-0
 252        1    4194304 dm-1
   8        0   10485760 sdb
  1. After setting iSCSI devide, configure on Initiator to use it like follwos.
# added new device provided from the target server as "sdb"
# create label

root@www:~# parted --script /dev/sdb "mklabel msdos"

# create partiton

root@www:~# parted --script /dev/sdb "mkpart primary 0% 100%"

# format with ext4

root@www:~# mkfs.ext4 /dev/sdb1

mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 2619392 4k blocks and 655360 inodes
Filesystem UUID: a344ca52-73a7-4b47-8b2c-f7381be38b76
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

# mount

root@www:~# mount /dev/sdb1 /mnt

root@www:~# df -hT

udev                        devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs                       tmpfs     396M  5.6M  390M   2% /run
/dev/mapper/ubuntu--vg-root ext4       25G  1.4G   23G   6% /
tmpfs                       tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                       tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                   ext2      472M   55M  393M  13% /boot
tmpfs                       tmpfs     100K     0  100K   0% /run/lxcfs/controllers
tmpfs                       tmpfs     396M     0  396M   0% /run/user/0
/dev/sdb1                   ext4      9.8G   23M  9.2G   1% /mnt

# /dev/sdb1 is a remote device

fio test

root@www:~# fio -filename=/dev/sdb1 ...

logout & delete target

root@www:~# iscsiadm -m node --targetname IQN(target) --logout
root@www:~# iscsiadm -m node --op delete --targetname IQN(target)

參考資料:https://www.server-world.info/en/note?os=Ubuntu_16.04&p=iscsi&f=1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章