阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

161次阅读
没有评论

共计 7370 个字符,预计需要花费 19 分钟才能阅读完成。

一,概述

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

SCSI 的定义:

SCSI: Small Computer System Interface

SCSI 是一种 I / O 技术

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

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

SCSI 的特点:

设备无关性

多设备并行

高带宽

低系统开销

SCSI 总线:

SCSI 总线是 SCSI 设备之间传输数据的通路

SCSI 总线又被称作 SCSI 通道

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

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 连接示意图:

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

SCSI 通信模式:

二,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 设备分区不能同时让不同客户端同时写入数据,否则数据文件会崩溃。

一,概述

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

SCSI 的定义:

SCSI: Small Computer System Interface

SCSI 是一种 I / O 技术

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

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

SCSI 的特点:

设备无关性

多设备并行

高带宽

低系统开销

SCSI 总线:

SCSI 总线是 SCSI 设备之间传输数据的通路

SCSI 总线又被称作 SCSI 通道

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

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 连接示意图:

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

SCSI 通信模式:

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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计7370字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中