読者です 読者をやめる 読者になる 読者になる

labunix's blog

labunixのラボUnix

wheezyにiscsitargetを導入する

■FreeNAS使わなくても出来たし。。。

 vmplayerにFreeNAS9.1+iSCSIサーバを導入
 http://labunix.hateblo.jp/entry/20130903/1378214837

■wheezyにiscsitargetを導入する。

$ apt-cache search iscsitarget
iscsitarget - iSCSI Enterprise Target userland tools
iscsitarget-dkms - iSCSI Enterprise Target kernel module source - dkms version

$ echo "iscsitarget iscsitarget-dkms module-assistant debhelper" | \
  sudo apt-get install -y `xargs`
...
[....] iscsitarget not enabled in "/etc/default/iscsitarget", not starting... ..[ (warning).
...

■dkmsのインストール時にkernelモジュールの設定も行われる。

$ ls /lib/modules/3.2.0-4-amd64/updates/dkms/
iscsi_trgt.ko  ndiswrapper.ko

$ lsmod | grep iscsi
iscsi_trgt             72785  4 
iscsi_tcp              17670  0 
libiscsi_tcp           17497  1 iscsi_tcp
libiscsi               35920  3 libiscsi_tcp,iscsi_tcp,ib_iser
scsi_transport_iscsi    39337  4 libiscsi,iscsi_tcp,ib_iser
scsi_mod              162269  7 libata,sd_mod,sg,scsi_transport_iscsi,libiscsi,iscsi_tcp,ib_iser


■iscsitargetが起動するよう設定変更。

$ grep -i enable /etc/default/iscsitarget 
ISCSITARGET_ENABLE=false

$ sudo sed -i s/"\(ISCSITARGET_ENABLE=\)false"/"\1true"/ /etc/default/iscsitarget 

$ grep -i enable /etc/default/iscsitarget
ISCSITARGET_ENABLE=true

■起動してみる。

$ sudo /etc/init.d/iscsitarget start
[ ok ] Starting iSCSI enterprise target service:.
. ok 

■ディスク領域(とりあえず1GB)をファイルで作成

$ sudo mkdir /var/iscsi
$ sudo dd if=/dev/zero of=/var/iscsi/disk0 bs=512k count=2048

$ ls -lh /var/iscsi/disk0
-rw-r--r-- 1 root root 1.0G  94 23:35 /var/iscsi/disk0

■コメントを参考に編集

$ sudo grep "iqn\|Lun" /etc/iet/ietd.conf
# iqn.yyyy-mm.<reversed domain name>[:identifier]
#Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
	# Lun numbers MUST start with zero (each target needs a Lun 0)
	#Lun 0 Path=/dev/sdc,Type=fileio,ScsiId=xyz,ScsiSN=xyz

$ sudo grep -v "#\|^\$" /etc/iet/ietd.conf 
Target iqn.2013-09.localdomain:debian-wheezy
	Lun 0 Path=/var/iscsi/disk0,Type=fileio

■再起動してターゲットを確認

$ sudo /etc/init.d/iscsitarget restart
[ ok ] Removing iSCSI enterprise target devices: :.
[ ok ] Stopping iSCSI enterprise target service: :.
[ ok ] Removing iSCSI enterprise target modules: :.
[ ok ] Starting iSCSI enterprise target service:.
. ok 

$ netstat -an | grep 3260
tcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN     
tcp6       0      0 :::3260                 :::*                    LISTEN     

$ sudo /etc/init.d/iscsitarget status
[ ok ] iSCSI enterprise target is running.

$ cat /proc/net/iet/session
tid:1 name:iqn.2013-09.localdomain:debian-wheezy

$ sudo ietadm --op show --tid=1 
Wthreads=8
Type=0
QueuedCommands=32
NOPInterval=0
NOPTimeout=0

$ dmesg | grep -i iscsi
[ 2089.411358] iscsi_trgt: Removing all connections, sessions and targets
[ 2090.361975] iSCSI Enterprise Target Software - version 1.4.20.3
[ 2090.362183] iscsi_trgt: Registered io type fileio
[ 2090.362191] iscsi_trgt: Registered io type blockio
[ 2090.362197] iscsi_trgt: Registered io type nullio
[ 3022.662847] scsi6 : iSCSI Initiator over TCP/IP

■クライアントチェック

$ sudo apt-get install -y open-iscsi

$ sudo iscsiadm -m discovery -t st -p 192.168.152.155:3260
192.168.152.155:3260,1 iqn.2013-09.localdomain:debian-wheezy

$ sudo iscsiadm -m node --targetname "iqn.2013-09.localdomain:debian-wheezy" --portal "192.168.152.155:3260" --login
Logging in to [iface: default, target: iqn.2013-09.localdomain:debian-wheezy, portal: 192.168.152.155,3260] (multiple)
Login to [iface: default, target: iqn.2013-09.localdomain:debian-wheezy, portal: 192.168.152.155,3260] successful.

$ sudo iscsiadm -m session
tcp: [1] 192.168.152.155:3260,1 iqn.2013-09.localdomain:debian-wheezy

■sdbとして認識されている。

$ dmesg | grep sdb
[ 3022.925526] sd 6:0:0:0: [sdb] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
[ 3022.925738] sd 6:0:0:0: [sdb] Write Protect is off
[ 3022.925750] sd 6:0:0:0: [sdb] Mode Sense: 77 00 00 08
[ 3022.926102] sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3022.929166]  sdb: unknown partition table
[ 3022.930164] sd 6:0:0:0: [sdb] Attached SCSI disk

$ sudo fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders, total 2097152 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 identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

■manualをautomaticに変更すると再起動後も自動的にiSCSIに接続する。

$ sudo grep startup /etc/iscsi/nodes/iqn.2013-09.localdomain:debian-wheezy/192.168.152.155,3260,1/default
node.startup = manual
node.conn[0].startup = manual

$ sudo grep -i manual /etc/iscsi/iscsid.conf 
# To manually startup the session set to "manual". The default is manual.
node.startup = manual

$ sudo sed -i s/"\(node.startup = \)manual"/"\1automatic"/ /etc/iscsi/iscsid.conf