1、给33机器添加一块硬盘。(普通的文件(file)、逻辑卷(LVM)、物理硬盘分区(partition))
[root@virt ~]# fdisk -l | grep sdb Disk /dev/sdb: 5368 MB, 5368709120 bytes
2、安装iscsi服务器端。
yum install scsi-target-utils3、编辑iscsi
<target bd.kl> backing-store /dev/sdb #后加入的硬盘 initiator-address 192.168.1.45 #指定IP initiator-address 192.168.1.35 #指定IP </target>4、检查是否加载成功
[root@virt ~]# tgt-admin --show Target 1: bd.kl 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: 192.168.1.45 192.168.1.35
这服务端就开启了~
----------
客户端:
1、扫描 iscsiadm -m discovery -t st -p 192.168.1.33
[root@ns ~ 17:29 #18]# iscsiadm -m discovery -t sendtargets \ -p 192.168.1.33 192.168.1.33:3260,1 bd.kl
2、连接 iscsiadm -m node -T bd.kl -p 192.168.1.33
[root@ns ~ 20:02 #20]# iscsiadm -m node -T bd.kl -p 192.168.1.33 -l Logging in to [iface: default, target: bd.kl, portal: 192.168.1.33,3260] (multiple) Login to [iface: default, target: bd.kl, portal: 192.168.1.33,3260] successful.
3、已经挂载上,用fdisk查看
[root@ns ~ 20:03 #21]# fdisk -l Device Boot Start End Blocks Id System /dev/sda1 * 1 2611 20970496 83 Linux Disk /dev/sdb: 5368 MB, 5368709120 bytes 166 heads, 62 sectors/track, 1018 cylinders Units = cylinders of 10292 * 512 = 5269504 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x47ef00d7 Device Boot Start End Blocks Id System
或者用驱动查看
[root@ns ~ 20:04 #22]# dmesg|tail scsi 6:0:0:0: RAID IET Controller 0001 PQ: 0 ANSI: 5 scsi 6:0:0:0: Attached scsi generic sg2 type 12 scsi 6:0:0:1: Direct-Access IET VIRTUAL-DISK 0001 PQ: 0 ANSI: 5 sd 6:0:0:1: Attached scsi generic sg3 type 0 sd 6:0:0:1: [sdb] 10485760 512-byte logical blocks: (5.36 GB/5.00 GiB) sd 6:0:0:1: [sdb] Write Protect is off sd 6:0:0:1: [sdb] Mode Sense: 49 00 00 08 sd 6:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA sdb: sd 6:0:0:1: [sdb] Attached SCSI disk
很清晰是SCSI硬盘。
4、开始挂载
fdisk分区。。。fdisk /dev/sdb -> p -> n -> -> w -> q
分完了,看一下
[root@ns ~ 20:09 #27]# fdisk /dev/sdb -l Disk /dev/sdb: 5368 MB, 5368709120 bytes 166 heads, 62 sectors/track, 1018 cylinders Units = cylinders of 10292 * 512 = 5269504 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x47ef00d7 Device Boot Start End Blocks Id System /dev/sdb1 1 1018 5238597 83 Linux
[root@ns ~ 20:11 #30]# mkdir -p /Volume/sdb
[root@ns ~ 20:12 #32]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1309649 blocks 65482 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@ns ~ 20:11 #31]# vi /etc/fstab /dev/sdb1 /Volume/sdb ext4 defaults 0 0挂载最后一步
[root@ns ~ 20:13 #33]# mount -a成功。
5、卸载SCSI硬盘,如果不卸载开机会启动不了。
[root@ns ~ 20:13 #34]# iscsiadm -m node -T bd.kl -p 192.168.1.33 --logout Logging out of session [sid: 4, target: bd.kl, portal: 192.168.1.33,3260] Logout of [sid: 4, target: bd.kl, portal: 192.168.1.33,3260] successful.如果真的没卸载重启启动不起来,那么
进入单用户模式
[root@virt ~]# chkconfig | grep iscsi iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@virt ~]# chkconfig --level 345 iscsi off [root@virt ~]# chkconfig --level 345 iscsid off然后进去了再挂载。
OVER.
客户端为WINDOWS
1、下载
在http://www.microsoft.com/en-us/download/details.aspx?id=18986下载
完成。
如果没有识别的话去设备管理删掉问好的那个SCSI。直接点卸载或删除。
----------------------
下边写一下部分注释的配置文件。
ISCSI-SERVER
/etc/tgt/targets.conf
# This is a sample config file for tgt-admin.
# The files ending with '.conf' in this directory will be included.
#
# The "#" symbol disables the processing of a line.
#只有一个逻辑单元的简单例子,默认允许所有的initiators发起访问。
# Sample target with one LUN only. Defaults to allow access for all initiators:
#<target iqn.2008-09.com.example:server.target1>
# backing-store /dev/LVM/somedevice
#</target>
与上面的相同,但是使用direct-store替代backing-srore
# Similar, but we use "direct-store" instead of "backing-store".
# "direct-store" reads drive parameters with sg_inq command and sets them to
//direct-store 读取设备sg_inq参数
# the target.
# Parameters fatched with sg_inq are:
# - Vendor identification
# - Product identification
# - Product revision level
# - Unit serial number (if present)
# We also specify "incominguser".
一个指定了incominguser的例子
#<target iqn.2008-09.com.example:server.target2>
# direct-store /dev/sdd
# incominguser someuser secretpass12
#</target>
一个含有多个逻辑单元的例子,禁止了write-cache(tgtd 默认允许write-cache),设备供应商设置为"MyVendor"
# An example with multiple LUNs, disabled write-cache (tgtd enables write-cache
# by default) and vendor identification set to "MyVendor"
#<target iqn.2008-09.com.example:server.target3>
# backing-store /dev/LVM/somedevice1 # Becomes LUN 1
# backing-store /dev/LVM/somedevice2 # Becomes LUN 2
# backing-store /dev/LVM/somedevice3 # Becomes LUN 3
# write-cache off
# vendor_id MyCompany Inc.
#</target>
与上相同,但我们从磁盘本身读取vendor_id, product_id, product_rev 和scsi_sn
# Similar to the one above, but we fetch vendor_id, product_id, product_rev and
# scsi_sn from the disks.
# Vendor identification (vendor_id) is replaced in all disks by "MyVendor"
其中vendor_id参数被设置的MyCompany Inc替代磁盘原有的参数。
#<target iqn.2008-09.com.example:server.target4>
# direct-store /dev/sdb # Becomes LUN 1
# direct-store /dev/sdc # Becomes LUN 2
# direct-store /dev/sdd # Becomes LUN 3
# write-cache off
# vendor_id MyCompany Inc.
#</target>
# Note that "first-device-first-lun numbering" will work only for simple
# scenarios above, where _only_ direct-store _or_ backing-store is used.
# If you mix backing-store and direct-store, then all backing-store entries
# are processed before direct-store-entries.
值得注意第一个LUN设备,即为LUN0,这种情况只适合以上简单的情景。即只有 direct-store,或backing-store时。
如果要向以下这种混用,backing-store参数的逻辑单元号要在direct-store前面。
#<target iqn.2008-09.com.example:server.target4>
# direct-store /dev/sdb # Becomes LUN 3
# backing-store /dev/sdc # Becomes LUN 1
# direct-store /dev/sdd # Becomes LUN 4
# backing-store /dev/sde # Becomes LUN 2
#</target>
# Even more complicated example - each device has different parameters.
甚至更复杂混乱的例子-每个设备都有不同的参数
# You can use indentation to make the config file more readable.
可以使用缩格让配置文件读起来更方便些。
# Note that LUNs will be assigned more or less randomly here (and still
# backing-store get LUNs assigned before drect-store).
注意在这里逻辑单元会被或多或少地随意地分配号码,但即便这样backing-store的逻辑单元号仍然在drect-store之前。
# You can specify multiple mode_page parameters (they are commented out
# in this example).
你可以指定复杂的mode_page参数,在例子中被注释出来。
# Note that some parameters (write-cache, scsi_sn) were specified "globally".
注意一些参数(如:write-cache,scsi_sn)具有全局参数的特性。
# "Global" parameters will be applied to all LUNs; they can be overwritten
# "locally", per LUN.
全局参数被视为适用所用的逻辑单元,他们可以被每个逻辑单元局部的配置文件所替代
# If lun is not specified, it will be allocated automatically (first available).
如果逻辑单元号码没有被指定,他将会被自动指定。
#<target iqn.2008-09.com.example:server.target5>
# <direct-store /dev/sdd>
# vendor_id VENDOR1
# removable 1
# device-type cd
# lun 1
# </direct-store>
# <direct-store /dev/sda>
# vendor_id VENDOR2
# lun 2
# </direct-store>
# <backing-store /dev/sdb1>
# vendor_id back1
# scsi_sn SERIAL
# write-cache on
# lun 3 # lun is commented out - will be allocated automatically//lun 3被注释上了,他将会被自动指定
# </backing-store>
# <backing-store /dev/sdd1>
# vendor_id back2
#mode_page 8:0:18:0x10:0:0xff....
#mode_page 8:0:18:0x10:0:0xff....
#bs-type aio
# lun 15
# </backing-store>
# Some more parameters which can be specified locally or globally:
更多的可被用于局部的和全局的参数如下:
#scsi_id ...
#scsi_sn ...
#vendor_id ...
#product_id ...
#product_rev ...
#sense_format ...
#removable ...
#online ...
#path ...
#mode_page 8:0:18:0x10:0:0xff....
#mode_page 8:0:18:0x10:0:0xff....
#device-type ...
#bs-type ... # backing store type - default rdwr, can be aio, mmap, etc...
#allow-in-use yes # if specified globally, can't be overwritten locally
# write-cache off
# scsi_sn multipath-10
# Parameters below are only global. They can't be configured per LUN.
如下的参数只能用于全局参数,而不能被用于局部
# Only allow connections from 192.168.100.1 and 192.168.200.5
只允许从192.168.100.1和192.168.200.5进行连接
# initiator-address 192.168.100.1
# initiator-address 192.168.200.5
# Tuning parameters (global, per target)
#MaxRecvDataSegmentLength 8192
#MaxXmitDataSegmentLength 8192
#HeaderDigest None
#DataDigest None
#InitialR2T Yes
#MaxOutstandingR2T 1
#ImmediateData Yes
#FirstBurstLength 65536
#MaxBurstLength 262144
#DataPDUInOrder Yes
#DataSequenceInOrder Yes
#ErrorRecoveryLevel 0
#IFMarker No
#OFMarker No
#DefaultTime2Wait 2
#DefaultTime2Retain 20
#OFMarkInt Reject
#IFMarkInt Reject
#MaxConnections 1
# Allowed incoming users
允许访问的用户
# incominguser user1 secretpass12
# incominguser user2 secretpass23
# Outgoing user
# outgoinguser userA secretpassA
#</target>
# The device will have lun 1 unless you specify something else
#<target iqn.2008-09.com.example:server.target6>
# backing-store /dev/LVM/somedevice
# lun 10
#</target>
# Devices which are in use (by system: mounted, for swap, part of RAID, or by
# userspace: dd, by tgtd for another target etc.) can't be used, unless you use
# --force flag or add 'allow-in-use yes' option
被使用中的设备(系统占用:挂载,使用中的交换分区,RAID的一部分,或用户空间:
dd, 或被其他的目标所使用)是不能被使用的,除非使用--force 或者添加allow-in-use yes参数
#<target iqn.2008-09.com.example:server.target7>
# backing-store /dev/LVM/somedevice
# allow-in-use yes
#</target>
#<target iqn.2008-09.com.example:server.target8>
# <backing-store /dev/LVM/somedevice>
# scsi_sn serial1
# </backing-store>
# <backing-store /dev/LVM/somedevice2>
# scsi_sn serial2
# </backing-store>
# allow-in-use yes
#</target>
# Not supported configurations, and therefore, commented out:
不支持的配置方式,因此被注释上了。
#<target iqn.2008-09.com.example:server.target9>
# backing-store /dev/LVM/somedevice1
# backing-store /dev/LVM/somedevice2
# lun 10
# lun 11
#</target>
#<target iqn.2008-09.com.example:server.target10>
# <direct-store /dev/sdd>
# vendor_id VENDOR1
# </direct-store>
#
# direct-store /dev/sdc
#</target>
# This one will break the parser:
这个会中断解析
#<target iqn.2008-09.com.example:server.target11>
# <direct-store /dev/sdd>
# vendor_id VENDOR1
# </direct-store>
#
# direct-store /dev/sdc
#
# <direct-store /dev/sdd>
# vendor_id VENDOR1
# </direct-store>
#</target>