一、給33機器添加一塊硬盤。(普通的文件(file)、邏輯卷(LVM)、物理硬盤分區(partition)) node
[root@virt ~]# fdisk -l | grep sdb Disk /dev/sdb: 5368 MB, 5368709120 bytes
二、安裝iscsi服務器端。 ios
yum install scsi-target-utils三、編輯iscsi
<target bd.kl> backing-store /dev/sdb #後加入的硬盤 initiator-address 192.168.1.45 #指定IP initiator-address 192.168.1.35 #指定IP </target>四、檢查是否加載成功
[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
這服務端就開啓了~ shell
---------- 服務器
客戶端: session
一、掃描 iscsiadm -m discovery -t st -p 192.168.1.33 app
[root@ns ~ 17:29 #18]# iscsiadm -m discovery -t sendtargets \ -p 192.168.1.33 192.168.1.33:3260,1 bd.kl
二、鏈接 iscsiadm -m node -T bd.kl -p 192.168.1.33 less
[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.
三、已經掛載上,用fdisk查看 dom
[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
或者用驅動查看 ide
[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硬盤。 fetch
四、開始掛載
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成功。
五、卸載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
一、下載
在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>