SCSI存储详解以及Linux下ISCSI的实现

简介:

一,概述

SCSI最初是一种专门为小型计算机系统设计的I/O技术,但由于其架构和协议自身的优点,后被广泛应用于实现DAS以及SAN的底层技术。


SCSI的定义:

SCSI: Small Computer System Interface

SCSI是一种I/O技术

SCSI规范了一种并行的I/O总线和相关的协议

SCSI的数据传输是以块的方式进行的


SCSI的特点:

设备无关性

多设备并行

高带宽

低系统开销


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

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


编辑target配置文件,定义target

1
2
3
4
5
6
7
8
[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并查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[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

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

修改客户端配置文件:

1
2
3
4
5
6
[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工具发现设备

1
2
3
4
5
[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/*


测试设备是否可用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
[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设备分区不能同时让不同客户端同时写入数据,否则数据文件会崩溃。







     本文转自ljl_19880709 51CTO博客,原文链接:http://blog.51cto.com/luojianlong/1388206,如需转载请自行联系原作者





相关文章
|
4月前
|
存储 关系型数据库 MySQL
Linux C/C++ 开发(学习笔记八):Mysql数据库图片存储
Linux C/C++ 开发(学习笔记八):Mysql数据库图片存储
52 0
|
4月前
|
存储 Linux 虚拟化
Linux和开源存储
Linux和开源存储
Linux和开源存储
|
5月前
|
存储 Kubernetes Linux
解决Linux中/var/lib/docker/磁盘空间过大及k8s存储卷磁盘空间使用率过高的问题
解决Linux中/var/lib/docker/磁盘空间过大及k8s存储卷磁盘空间使用率过高的问题
152 0
|
6月前
|
存储 缓存 Linux
Linux内核文件系统:比万物之神还要强大的存储魔法!
Linux内核文件系统:比万物之神还要强大的存储魔法!
|
7月前
|
存储 缓存 Linux
百度搜索:蓝易云【如何在Linux系统服务器中测试存储/磁盘I/O性能?】
这些工具可以帮助你测试磁盘的读取和写入性能,并提供各种性能指标和统计数据。请注意,在运行这些测试时,确保没有重要的数据存储在被测试的磁盘上,并谨慎操作以避免对系统和数据造成不必要的影响。
88 0
|
5月前
|
存储 Unix Linux
Linux加强篇006-存储结构与管理硬盘
山重水复疑无路,柳暗花明又一村
216 2
Linux加强篇006-存储结构与管理硬盘
|
3月前
|
存储 缓存 关系型数据库
Mysql专栏 - Linux底层交互和Raid存储架构
Mysql专栏 - Linux底层交互和Raid存储架构
82 0
|
4月前
|
存储 Linux
百度搜索:蓝易云【Linux下ISCSI存储部署教程】
这些是在Linux下部署iSCSI存储的基本步骤。根据您的需求和具体环境,可能还需要进行其他配置和调整。请确保在进行任何与网络连接和存储操作相关的操作之前,详细了解您的网络环境和存储需求,并采取适当的安全措施。
37 1
|
5月前
|
存储 网络协议 Java
Linux本地MinIO存储服务远程调用上传文件
Linux本地MinIO存储服务远程调用上传文件
|
5月前
|
存储 Linux 网络安全
哇~真的是你呀!今天是LINUX中的ISCSI服务
iSCSI(Internet Small Computer System Interface)是一种用于将存储设备(如硬盘驱动器)通过网络连接到计算机系统的存储协议。它允许计算机通过IP网络访问远程存储设备,就像访问本地存储设备一样。
45 0