SCSI存儲詳解以及Linux下ISCSI的實現

一,概述node

SCSI最初是一種專門爲小型計算機系統設計的I/O技術,但因爲其架構和協議自身的優勢,後被普遍應用於實現DAS以及SAN的底層技術。linux


SCSI的定義:後端

SCSI: Small Computer System Interfacebash

SCSI是一種I/O技術服務器

SCSI規範了一種並行的I/O總線和相關的協議網絡

SCSI的數據傳輸是以塊的方式進行的session


SCSI的特色:架構

設備無關性app

多設備並行ide

高帶寬

低系統開銷


SCSI總線:

SCSI總線是SCSI設備之間傳輸數據的通路

SCSI總線又被稱做SCSI通道

wKioL1M6I8WzPVn6AAIpKJcesXc279.jpg



SCSI終結器:

SCSI終結器位於SCSI總線的末端,用來減少相互影響的信號,維持SCSI鏈上的電壓恆定

SCSI鏈的最後一個SCSI設備須要使用終結器

SCSI鏈上的中間設備是不須要使用終結器的


SCSI控制器:

SCSI總線經過SCSI控制器來和硬盤之類的設備進行通訊

SCSI控制器邏輯上可分爲一個任務管理單元和多個邏輯單元(LU)


SCSI ID:

一個獨立的SCSI總線按照規格不一樣能夠支持8或16個SCSI設備,設備的編號須要經過SCSI ID來進行控制,系統中每一個SCSI設備都必須有本身惟一的SCSI ID,SCSI ID實際上就是這些設備的地址,窄SCSI總線最多容許8個、寬SCSI總線最多容許16個不一樣的SCSI設備和它進行鏈接。


LUN:

LUN(Logical Unit Number,邏輯單元號)是爲了使用和描述更多設備及對象而引進的一個方法,每一個SCSI ID上最多有32個LUN,一個LUN對應一個邏輯設備。


SCSI鏈接示意圖:

wKioL1M6JXiADkIMAAERE-nIxcU549.jpg


SCSI通訊模式:

wKioL1M6JbuxuPu_AADMqk7wcEI359.jpg



二,linux下ISCSI的實現:

ISCSI 是基於TCP/IP傳輸封裝的SCSI數據包的塊級別的共享,其也爲C/S架構模型,服務器端提供客戶端所須要的存儲設備,客戶端只須要進行掛載就能夠將其看成本身主機上的存儲設備進行分區、格式話使用。

實現ISCSI須要的2個角色:

iSCSI target(server)

存儲資源所在的iSCSI服務器被稱爲「target」。iSCSI target一般是一個硬盤存儲設備。當前大部分的主流操做系統都提供了配合iSCSI target使用的客戶端軟件initiator。

iSCSI initiator(client)

initiator就是iSCSI傳輸的服務端。典型的initiator都有共同的目的,就是做爲一個SCSI總線的適配器,代替物理上的SCSI設備(相似硬盤或者磁帶)。iSCSI initiator經過IP網絡傳輸SCSI命令。


實驗環境

192.168.30.115  CentOS 6.4 x86_64   target server

192.168.30.116  CentOS 6.4 x86_64   initiator client

192.168.30.117  CentOS 6.4 x86_64   initiator client


首先在target server上安裝scsi-target-utils

[root@tgtd ~]# yum -y install scsi-target-utils
[root@tgtd ~]# cp /etc/tgt/targets.conf /etc/tgt/targets.conf.bak


編輯target配置文件,定義target

[root@tgtd ~]# vi /etc/tgt/targets.conf
# 添加以下內容
<target iqn.2014-04.com.luojianlong:target1>
        backing-store /dev/sdb
        initiator-address 192.168.30.0/24
        incominguser luojianlong mypass
</target>
[root@tgtd ~]# service  tgtd restart


backing-store:指定後端要共享的磁盤編號

initiator-address:受權客戶端訪問的網絡地址

incominguser:設置登陸用戶的帳號密碼



啓動target並查看

[root@tgtd ~]# tgtadm -L iscsi -m target -o show
Target 1: iqn.2014-04.com.luojianlong:target1
    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:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 2048 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags:
    Account information:
        luojianlong
    ACL information:
        192.168.30.0/24


看到新生成的target 1,和自動建立的LUN 1,以及建立的用戶認證信息

登陸客戶端,安裝scsi-initiator-utils

[root@localhost ~]# yum -y install iscsi-initiator-utils

修改客戶端配置文件:

[root@localhost ~]# vi /etc/iscsi/iscsid.conf
# 啓用以下幾項
node.session.auth.authmethod = CHAP
node.session.auth.username = luojianlong
node.session.auth.password = mypass
[root@localhost ~]# service  iscsid restart


在客戶端使用iscsiadm工具發現設備

[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.30.119
192.168.30.119:3260,1 iqn.2014-04.com.luojianlong:target1
[root@localhost ~]# iscsiadm -m node -T iqn.2014-04.com.luojianlong:target1 -p 192.168.30.119:3260 -l
Logging in to [iface: default, target: iqn.2014-04.com.luojianlong:target1, portal: 192.168.30.119,3260] (multiple)
Login to [iface: default, target: iqn.2014-04.com.luojianlong:target1, portal: 192.168.30.119,3260] successful.


iscsiadm的命令彙總:

發現iscsi存儲:iscsiadm -m discovery -t st -p ISCSI_IP

查看iscsi發現記錄: iscsiadm -m node

刪除iscsi發現記錄 iscsiadm -m node -o delete -T LUN_NAME -p ISCSI_IP

登陸iscsi存儲 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -l

登出iscsi存儲 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -u

刪除此前登陸生成的數據:

rm -rf /var/lib/iscsi/node/*  

rm -rf -rf /var/lib/iscsi/send_targets/*


測試設備是否可用

[root@localhost ~]# fdisk -l /dev/sd[a-z]
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b12a1
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        3917    30944256   8e  Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd498549c.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-1009, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009): +1G
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd498549c
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         506     1050931   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mke2fs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65808 inodes, 262732 blocks
13136 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7312 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376
Writing inode tables: done                     
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/sdb1 /mnt/
[root@localhost ~]# cp /etc/fstab /mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
fstab  lost+found
[root@localhost mnt]# cat fstab
#
# /etc/fstab
# Created by anaconda on Thu Jan  9 23:01:31 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=db4bad23-32a8-44a6-bdee-1585ce9e13ac /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0


注意:同一個iscsi設備分區不能同時讓不一樣客戶端同時寫入數據,不然數據文件會崩潰。

相關文章
相關標籤/搜索