简介:

      iSCSI(发音为 /aɪˈskʌzi/ "eye-scuzzy"):Inernet 小型计算机系统接口(internet small computer system interface)。iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在ip网络上运行SCSI协议,使其能够才诸如高速千兆以太网上进行路由选择。iscsi技术是一种新存储技术,改技术是将现有SCISI接口与以太网络技术结合,使服务器可与ip网络存储装置相互交换资料。
   SCSI 结构基于客户/服务器模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。此外,iSCSI提供了在IP网络封装SCSI命令,且运行在TCP上。scsi接口即为数排针脚外围为梯形的接口。
    目前的iscsi的后端存储架构一般分为三种:
    1.架构器架构。2.pc架构:由一台性能高效稳定的普通计算机,通过iscsi target软件实现iscsi功能。3.pc+toe架构

服务器端配置:
一、安装target软件
yum install scsi-target-utils -y
rpm -ql scsi-target-utils #查看所安装的文件
/etc/rc.d/init.d/tgtd #服务管理脚本
/etc/sysconfig/tgtdd #可指定服务配置文件路径
/etc/tgt/targets.conf #服务配置文件
/usr/sbin/tgt-admin #target管理员工具
/usr/sbin/tgt-setup-lun #target中管理scsi设备逻辑单元号的工具
/usr/sbin/tgtadm #target管理工具
/usr/sbin/tgtd #target服务程序
/usr/sbin/tggimg #管理target框架的镜像文件的工具
二、创建要输出的设备
可输出的设备有如下几种:
1、lvm卷设备;
2、由文件组成的块设备(经过通过挺工具处理过的);
3、单一的分区;
4、整个磁盘;
5、RAID组成的卷设备

iscsi文档_iscsi target initiat


三、修改配置文件(/etc/tgt/targets.conf)
配置文件的语法及经常会使用到的几个选项
选项                                                功能描述
<target>......</target>         iscsi目标输出,配置域的开始及结束;

iscsi Qualified Name(IQN)       输出iscsi限定名称,格式为:
                                       iqn.yyyy-mm.com.example:storage.tape1.sys1.xyz
                               
Backing-store                          后备存储,一般指非实际的物理盘,如lvm卷
                                                某个分区、文件组成的块设备;

Direct-store                              直接存储,与backing-store相对,指实际
                                                 的物理盘,如整个硬盘,系统中一般表示为
                                                 sdb、sdc等;

Initiator-address                       发起者地址,指定该资源只允许某些客户机
                                                 使用;格式可以是ip地址,也可以为
                                                 192.168.0.0/24格式来描述一个网段;

incominguser                           使用chap认证协议,由target来认证
                                                 initiator端,格式为
                                                “incominguser username userpasswd”

OutgoingUsername                使用chap认证协议,由initiator来认证
                                               target端,格为“outgoingusername   
                                               username userpassword”,较少使用;

当然也可以使用命令进行配置

tgtadm --lld iscsi --op new --mode target --tid=1 --targetname=xiyou.target1 #创建target

iscsi文档_iscsi target initiat_02

tgtadm --lld  iscsi --op new --mode=logicalunit --tid=backing-store /dev/vdb1 #创建逻辑单元

iscsi文档_iscsi target initiat_03

tgtadm  --lld iscsi --op bind --mode target --tid 1 --initiator-address 192.168.0.97 #授权97这个initiator能登录

iscsi文档_iscsi target initiat_04

四、配置&重启服务
service tgtd start
chkconfig tgtd on
netstat -antlpe | grep :3260
查看是否监听3260端口

iscsi文档_iscsi target initiat_05




客户机端配置:
一、安装iscsi发起套件(iscsi-initiator-utils)
yum install iscsi-initiator-utils
二、查看服务器设备的输出
/etc/init.d/iscsid start
iscsiadm    -m  discovery  -t  st  -p  192.168.0.52
此时若服务没启动,会自动启动该服务

iscsi文档_iscsi target initiat_06
三、链接设备
iscsiadm -m node -t  xiyou.target1 -p 192.168.0.52 -l

iscsi文档_iscsi target initiat_07
fdisk -l  查看设备,多出了一个设备

iscsi文档_iscsi target initiat_08


ls /var/lib/iscsi/nodes/
xiyou.target1 #登录后被记录到系统当中的相关文件,系统重启后会自动链接。

iscsi文档_iscsi target initiat_09


四、分区并格式化及挂载
mkfs -t ext4 /dev/
mount
echo '/dev/sd /mnt   ext4  _netdev     0  0'>>/etc/fstab
mount -a
df -H 查看那挂载情况
五、断开链接及卸载
mount  | grep sd  #查看当前的iscsi的挂载情况
unount /mnt  #卸载iscsi设备的挂在点
iscsiadm   -m  node  -S   #查看当前系统中iscsi设备的连接状态
iscsiadm -m node -T  xiyou.target1 -u #卸载该设备当前的链接
ls /dev/sd*   #此时查看系统已无此设备
ls /var/lib/iscsi/nodes/   #缓存信息还存在于系统中,瑕疵启动将会自动链接
iscsiadm -m node -T xiyou.target1 -o delete #删除改链接
ls /var/lib/iscsi/nodes/  #缓存信息已经不存在

iscsi文档_iscsi target initiat_10



tgtadm man文档
tgtadm - Linux SCSI Target Administration Utility
   --lld [driver] --op new --mode target --tid=[id] --targetname [name]
           Add a new target with [id] and [name].#创建一个target并指定id和名字;


       --lld [driver] --op delete --mode target --tid=[id]
           Delete specific target with [id]. The target must have no active I_T nexus.#删除指定的target,target必须无活跃的节点。

       --lld [driver] --op show --mode target
           Show all the targets.#查看所有的targets。

       --lld [driver] --op show --mode target --tid=[id]
           Show target parameters of a target with [id].#通过指定id的方式查看指定的target。


       --lld [driver] --op new --mode=logicalunit --tid=[id] --lun=[lun] --backing-store [path]
           Add a new logical unit with [lun] to specific target with [id]. The logical unit is offered to the initiators. [path] must be block device files (including LVM and RAID devices) or regular files. lun0 is reserved for a special device automatically created.#给指定的target添加一个逻辑单元,逻辑单元提供给驱动器,路径必须是块设备文件(包括lvm和raid设备)或者常规文件。lun0被保留作为特殊设备自动被创建。

       --lld [driver] --op delete --mode=logicalunit --tid=[id] --lun=[lun]
           Delete specific logical unit with [lun] that the target with [id] has.#删除指定的逻辑单元

 --lld [driver] --op bind --mode=target --tid=[id]   --initiator-address=[address]
           Add the address to the access lists of the target with [id].Initiators with the address can access to the target. ´ALL´ is a special address to allow all initiators to access to a target.#添加可以访问target的地址。有此地址的发起者可以连接这个target。‘ALL’是一个特定的地址,所有的发起者都可以连接这个target。

       --lld [driver] --op unbind --mode=target --tid=[id]
       --initiator-address=[address]
           Delete the address from the access lists of the target with [id].

[driver] 为iscsi

我上传了两个附件,有兴趣的可以下载仔细研究。比这篇博客详细很多!