==============================================
= 0. Software Envrionment =
==============================================
iSCSI Target
OS: CentOS5.6
Hostname: rhel5-1.test.org
IP: 192.168.50.201
Disk: /dev/sda 8G
/dev/sdb 1G
/dev/sdc 2G
iSCSI Initiator
OS: CentOS5.6
Hostname: rhel5-2.test.org
IP: 192.168.50.202
Disk: /dev/sda 8G
==============================================
= 1. Target settings =
==============================================
iSCSI target (server): is the storage resource located on an iSCSI server, represents nothing but hard disk storage.
======================
= A. install package =
======================
# yum install scsi-target-utils
# rpm -ql scsi-target-utils
/etc/rc.d/init.d/tgtd # init script
/etc/sysconfig/tgtd # global setting file
/etc/tgt/targets.conf # config file
/usr/sbin/tgt-admin
/usr/sbin/tgt-setup-lun
/usr/sbin/tgtadm # main command
/usr/sbin/tgtd
/usr/sbin/tgtimg
/usr/share/doc/scsi-target-utils-1.0.8/*
/usr/share/man/man8/tgt*
==================================
= B. start target service (tgtd) =
==================================
# service tgtd start
# chkconfig tgtd on
# netstat -tlunp |grep tgt
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 2123/tgtd
tcp 0 0 :::3260 :::* LISTEN 2123/tgtd
==================================
= C. Define an iscsi target name =
==================================
iqn.yyyy-mm.:identifier
e.g.
iqn.2011-05.org.test:test-storage OR
iqn.2011-05.org.test:storage.disk2.amiens.sys1.xyz
iqn: iSCSI Qualified Name
LUN: Logical Unit Number
======================
= D. target settings =
======================
D1: Hard Drive
==============
# fdisk /dev/sdb
n,p,1,,w
# fdisk -l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
# fdisk /dev/sdc
n,p,1,,w
# fdisk -l /dev/sdc
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 261 2096451 83 Linux
target支持的硬盘类型
a. 大文件,例如使用dd创建的文件,# dd if=/dev/zero of=/home/iscsi/disk1.img bs=1M count=1024
b. 单个分区,例如/dev/sdb1 # fdisk /dev/sdb
c. 裸设备,例如整块硬盘,阵列,soft RAID,LV # lvcreate -L 2G -n iscsi01
D2: Manual config
=================
tgtadm - Linux SCSI Target Administration Utility
# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2011-05.org.test:test-storage OR
# tgtadm -L iscsi -m target -o new -t 1 -T iqn.2011-05.org.test:test-storage
// Notes: Add a new target with and
--lld/-L: driver
--mode/-m: mode (target, logicalunit)
--op/-o: operation (new, delete, show, bind, unbind, update)
--tid/-t: target id, must not be 0;
--targetname/-T: target name;
Show all the targets
# tgtadm --lld iscsi --mode target --op show OR
# tgtadm -L iscsi -m target -o show
Show target parameters of a target with
# tgtadm --lld iscsi --mode target --op show --tid 1 OR
# tgtadm -L iscsi -m target -o show -t 1
# tgtadm -L iscsi -m target -o show
Target 1: iqn.2011-05.org.test:test-storage
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
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
Account information:
ACL information:
# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb1 OR
# tgtadm -L iscsi -m logicalunit -o new -t 1 -l 1 -b /dev/sdb1
# tgtadm -L iscsi -m logicalunit -o new -t 1 -l 2 -b /dev/sdc1
//Notes: Add a new logical unit with to specific target with
--lun/-l: LUN id
--backing-store/-b: block device files (including LVM and RAID devices) or regular files
# tgtadm -L iscsi -m target -o show
Target 1: iqn.2011-05.org.test:test-storage
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
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1069 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdb1
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 2147 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdc1
Backing store flags:
Account information:
ACL information:
# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.50.0/24 OR
# tgtadm -L iscsi -m target -o bind -t 1 -I 192.168.50.0/24
//Notes: Add the address to the access lists of the target with
--initiator-address/-I: single ip address/ip segment/ALL
# tgtadm -L iscsi -m target -o show
Target 1: iqn.2011-05.org.test:test-storage
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
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1069 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdb1
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 2147 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdc1
Backing store flags:
Account information:
ACL information:
192.168.50.0/24
Notes:
The above config will not be saved. It will be lost after restart of service. It's better to write them into /etc/rc.local
D3: Target Conf file
====================
# vi /etc/tgt/targets.conf
backing-store /dev/sdb1
backing-store /dev/sdc1
initiator-address 192.168.50.0/24
incominguser mrzcs test
write-cache off
Notes:
backing-store: 虚拟设备
direct-store: 实际设备 (整个磁盘)
initiator-address: 使用者地址(限制initiator的来源)
incominguser username password: 使用者帐号和密码
write-cache [off|on]: 是否使用缓存
# tgtadm -L iscsi -m target -o show
Target 1: iqn.2011-05.org.test:test-storage
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
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1069 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdb1
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 2147 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdc1
Backing store flags:
Account information:
mrzcs
ACL information:
192.168.50.0/24
==============================================
= 2. Initiator settings =
==============================================
iSCSI initiator (client): functions as an iSCSI client, sends SCSI commands over an IP network.
=========================
= A. installing package =
=========================
# yum install iscsi-initiator-utils
# rpm -ql iscsi-initiator-utils
/etc/iscsi
/etc/iscsi/iscsid.conf
/etc/rc.d/init.d/iscsid # initiator service
/etc/rc.d/init.d/iscsi # iSCSI Target login/logout
/sbin/brcm_iscsiuio
/sbin/iscsi-iname
/sbin/iscsiadm
/sbin/iscsid
/sbin/iscsistart
/usr/include/fw_context.h
/usr/include/iscsi_list.h
/usr/include/libiscsi.h
/usr/lib/libfwparam.a
/usr/lib/libiscsi.so
/usr/lib/libiscsi.so.0
/usr/lib/python2.4/site-packages/libiscsimodule.so
/usr/share/doc/iscsi-initiator-utils-6.2.0.872/*
/usr/share/man/man8/iscsi*
/var/lib/iscsi
/var/lib/iscsi/ifaces
/var/lib/iscsi/isns
/var/lib/iscsi/nodes
/var/lib/iscsi/send_targets
/var/lib/iscsi/slp
/var/lib/iscsi/static
/var/lock/iscsi
======================
= B. Configure iSCSI =
======================
# echo "InitiatorName=rhel5-2" > /etc/iscsi/initiatorname.iscsi
# vi /etc/iscsi/iscsid.conf
node.session.auth.username = mrzcs
node.session.auth.password = test
discovery.sendtargets.auth.username = mrzcs
discovery.sendtargets.auth.password = test
Notes:
node.session.*: used to set a CHAP username and password for initiator authentication by the target(s).
discovery.sendtargets.*: used to set a discovery session CHAP username and password for the initiator authentication by the target(s)
# /etc/init.d/iscsi start
iscsid (pid 1337) is running...
Setting up iSCSI targets: iscsiadm: No records found!
[ OK ]
=======================
= C. Discover targets =
=======================
iscsiadm - open-iscsi administration utility
# iscsiadm -m discovery -t sendtargets -p 192.168.50.201:3260
192.168.50.201:3260,1 iqn.2011-05.org.test:test-storage
// Notes:
-m/--mode: mode (discovery, discoverydb, node, fw, host, iface, session)
-t/--type: type (sendtargets or abbreviated as st, slp, isns or fw)
-p/--portal: ip address with port, defult port 3260
# ll -R /var/lib/iscsi/nodes/
/var/lib/iscsi/nodes/iqn.2011-05.org.test:test-storage
/var/lib/iscsi/nodes/iqn.2011-05.org.test:test-storage/192.168.50.201,3260,1
# /etc/init.d/iscsi restart
Stopping iSCSI daemon:
iscsid is stopped [ OK ]
Starting iSCSI daemon: [ OK ]
[ OK ]
Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260]
Login to [iface: default, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260] successful.
[ OK ]
# iscsiadm -m node # 显示系统所有的target信息
192.168.50.201:3260,1 iqn.2011-05.org.test:test-storage
# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1044 8281507+ 8e Linux LVM
Disk /dev/sdb: 1069 MB, 1069254144 bytes
33 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 2046 * 512 = 1047552 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 2146 MB, 2146765824 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Disk /dev/sdc doesn't contain a valid partition table
OR
# tail -f /var/log/messages
/dev/sdb and /dev/sdc are new block devices.
====================================
= D. Format and Mount iSCSI Volume =
====================================
# fdisk /dev/sdb
n,p,1,1,+100M,w
# fdisk -l /dev/sdb
Disk /dev/sdb: 1069 MB, 1069254144 bytes
33 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 2046 * 512 = 1047552 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 96 98177 83 Linux
# mkfs.ext3 /dev/sdb1
# mkdir /mnt/iscsi
# mount /dev/sdb1 /mnt/iscsi
# touch /mnt/iscsi/test
On the Target Server
# tgtadm -m target -o show
Target 1: iqn.2011-05.org.test:test-storage
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 2
Initiator: rhel5-2
Connection: 0
IP Address: 192.168.50.202
===================================================
= E. Mount iSCSI drive automatically at boot time =
===================================================
# chkconfig iscsi on
# vi /etc/fstab
/dev/sdb1 /mnt/iscsi ext3 _netdev 0 0
=============
= F. Others =
=============
不重启iscsi服务,仅登陆某个target
# iscsiadm -m node -T iqn.2011-05.org.test:test-storage --login
Logging in to [iface: default, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260]
Login to [iface: default, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260] successful.
# iscsiadm -m node
192.168.50.201:3260,1 iqn.2011-05.org.test:test-storage
# ll -R /var/lib/iscsi/nodes/
仍然存在
不重启iscsi服务,仅登出某个target
# # iscsiadm -m node -T iqn.2011-05.org.test:test-storage --logout
Logging out of session [sid: 1, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260]
Logout of [sid: 1, target: iqn.2011-05.org.test:test-storage, portal: 192.168.50.201,3260] successful.
# iscsiadm -m node
192.168.50.201:3260,1 iqn.2011-05.org.test:test-storage
# ll -R /var/lib/iscsi/nodes/
仍然存在
// Notes:
-T: targetname
-p: ip:port
--login: login to a specified record;
--logout: logout for a specified record; 但并不删除/var/lib/iscsi/nodes/内的信息
更新/刪除/新增 target 資料的方法:
# iscsiadm -m node -o [delete|new|update] -T iqn.2011-05.org.test:test-storage
// Notes:
-o delete: 刪除target连接信息 (/var/lib/iscsi/nodes/*)
-o update: 更新相关信息
-o new : 增加新的 target
e.g.
# iscsiadm -m node -o delete -T iqn.2011-05.org.test:test-storage
# iscsiadm -m node
iscsiadm: no records found!
# ll -R /var/lib/iscsi/nodes/
/var/lib/iscsi/nodes/:
total 0
# /etc/init.d/iscsi restart
Stopping iSCSI daemon:
iscsid is stopped [ OK ]
Starting iSCSI daemon: [ OK ]
[ OK ]
Setting up iSCSI targets: iscsiadm: No records found!
[ OK ]
需要重新进行discover
# iscsiadm -m discovery -t sendtargets -p 192.168.50.201:3260
reference: