TA的每日心情 | 怒 前天 13:01 |
---|
签到天数: 1643 天 [LV.Master]伴坛终老
|
一、简介
iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的、可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
iSCSI是一种基于TCP/IP 的协议,用来建立和管理IP存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于C/S模式,其通常应用环境是:设备互相靠近,并且这些设备由SCSI 总线连接。
iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。
完整的iSCSI系统的拓扑结构如下:
iSCSI简单来说,就是把SCSI指令通过TCP/IP协议封装起来,在以太网中传输。iSCSI 可以实现在IP网络上传递和运行SCSI协议,使其能够在诸如高速千兆以太网上进行数据存取,实现了数据的网际传递和管理。基于iSCSI建立的存储区域网(SAN)与基于光纤的FC-SAN相比,具有很好的性价比。
iSCSI属于端到端的会话层协议,它定义的是SCSI到TCP/IP的映射(如下图),即Initiator将SCSI指令和数据封装成iSCSI协议数据单元,向下提交给TCP层,最后封装成IP数据包在IP网络上传输,到达Target后通过解封装还原成SCSI指令和数据,再由存储控制器发送到指定的驱动器,从而实现SCSI命令和数据在IP网络上的透明传输。它整合了现有的存储协议SCSI和网络协议TCP/IP,实现了存储与TCP/IP网络的无缝融合。在本文中,将把发起器Initiator称为客户端,将目标器Target称为服务端以方便理解。
二、环境准备
操作系统:CentOS release 6.5
iSCSI Target:192.168.8.42 / scsi-target-utils-1.0.24-12.el6_5.i686
iSCSI Initiator:192.168.8.39 / iscsi-initiator-utils-6.2.0.873-10.el6.i686
防火墙、selinux已关闭
# service iptables status
iptables: Firewall is not running.
# getenforce
Disabled
三、安装配置iSCSI Target服务端
# yum install -y scsi-target-utils
添加一块硬盘sdb,并新建两个分区:sdb1、sdb2 模拟san存储,在initiator看来是两块硬盘
[plain] view plain copy
- # 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 0xe714b1f2.
- 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): p
-
-
- Disk /dev/sdb: 85.9 GB, 85899345920 bytes
- 255 heads, 63 sectors/track, 10443 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: 0xe714b1f2
-
-
- Device Boot Start End Blocks Id System
-
-
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First cylinder (1-10443, default 1):
- Using default value 1
- Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +20G
-
-
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 2
- First cylinder (2613-10443, default 2613):
- Using default value 2613
- Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +30G
-
-
- Command (m for help): p
-
-
- Disk /dev/sdb: 85.9 GB, 85899345920 bytes
- 255 heads, 63 sectors/track, 10443 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: 0xe714b1f2
-
-
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 2612 20980858+ 83 Linux
- /dev/sdb2 2613 6529 31463302+ 83 Linux
-
-
- Command (m for help): w
- The partition table has been altered!
-
-
- Calling ioctl() to re-read partition table.
- Syncing disks.
使配置生效
[plain] view plain copy
- # partx -a /dev/sdb
- BLKPG: Device or resource busy
- error adding partition 1
- BLKPG: Device or resource busy
- error adding partition 2
- # cat /proc/partitions
- major minor #blocks name
-
-
- 8 0 125829120 sda
- 8 1 512000 sda1
- 8 2 125316096 sda2
- 8 16 83886080 sdb
- 8 17 20980858 sdb1
- 8 18 31463302 sdb2
- 253 0 4096000 dm-0
- 253 1 20480000 dm-1
- 253 2 25600000 dm-2
- 253 3 30720000 dm-3
启动target服务,通过ss -tnl可以看到3260端口已开启
# service tgtd start
四、服务端配置管理工具tgtadm的使用
1、创建一个target id 为1 name为iqn.2016-04.com.chinasoft.san:1d
# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2016-04.com.chinasoft.san:1
2、显示所有target
# tgtadm -L iscsi -o show -m target
3、向某ID为1的设备上添加一个新的LUN,其号码为1,且此设备提供给initiator使用。/dev/sdb1是某“块设备”的路径,此块设备也可以是raid或lvm设备。lun0已经被系统预留
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/sdb1
4、定义某target的基于主机的访问控制列表,192.168.8.0/24表示允许访问此target的initiator客户端的列表:
如开放给192.168.8.0/24网络中的主机访问:
# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.8.0/24
再次向ID为1的设备上添加一个新的LUN,号码为2
# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b /dev/sdb2
# tgtadm -L iscsi -o show -m target
5、解除target的基于主机的访问控制列表权限
# tgtadm -L iscsi -o unbind -m target -t 1 -I 192.168.8.0/24
# tgtadm -L iscsi -o show -m target
6、删除target中的LUN
# tgtadm -L iscsi -o delete -m target -t 1
# tgtadm -L iscsi -o show -m target
五、客户端initiator配置iscsiadm工具的使用
安装iscsi-initiator-utils工具
[plain] view plain copy
- # yum install -y iscsi-initiator-utils
-
-
- # echo "InitiatorName=`iscsi-iname -p iqn.2016-04.com.chinasoft`" > /etc/iscsi/initiatorname.iscsi
- # echo "InitiatorAlias=initiator1" >> /etc/iscsi/initiatorname.iscsi
- # cat /etc/iscsi/initiatorname.iscsi
- InitiatorName=iqn.2016-04.com.chinasoft:59b0936b38a3
- InitiatorAlias=initiator1
[plain] view plain copy
- # service iscsi start
- # chkconfig iscsi on
- # chkconfig --list iscsi
- iscsi 0:off1:off 2:on3:on 4:on5:on 6:off
iscsiadm是个模式化的工具,其模式可通过-m或--mode选项指定,常见的模式有discovery、node、fw、session、host、iface几个,如果没有额外指定其它选项,则discovery和node会显示其相关的所有记录;session用于显示所有的活动会话和连接,fw显示所有的启动固件值,host显示所有的iSCSI主机,iface显示/var/lib/iscsi/ifaces目录中的所有ifaces设定。
[plain] view plain copy
- iscsiadm -m discovery [ -d debug_level ] [ -P printlevel ] [ -I iface -t type -p ip:port [ -l ] ]
- iscsiadm -m node [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ [ -T tar-getname -p ip:port -I iface ] [ -l | -u | -R | -s] ] [ [ -o operation ]
-
-
- -d, --debug=debug_level 显示debug信息,级别为0-8;
- -l, --login
- -t, --type=type 这里可以使用的类型为sendtargets(可简写为st)、slp、fw和 isns,此选项仅用于discovery模式,且目前仅支持st、fw和isns;其中st表示允许每个iSCSI target发送一个可用target列表给initiator;
- -p, --portal=ip[:port] 指定target服务的IP和端口;
- -m, --mode op 可用的mode有discovery, node, fw, host iface 和 session
- -T, --targetname=targetname 用于指定target的名字
- -u, --logout
- -o, --op=OPEARTION:指定针对discoverydb数据库的操作,其仅能为new、delete、update、show和nonpersistent其中之一;
- -I, --interface=[iface]:指定执行操作的iSCSI接口,这些接口定义在/var/lib/iscsi/ifaces中;
发现设备
[plain] view plain copy
- # iscsiadm -m discovery -t st -p 192.168.8.42
- Starting iscsid: [ OK ]
- 192.168.8.42:3260,1 iqn.2016-04.com.chinasoft.san:1
-
-
- # iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -l
- Logging in to [iface: default, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] (multiple)
- Login to [iface: default, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] successful.
验证能否看到服务端设备
# fdisk -l /dev/sd[a-z]
对设备sdc分区
[plain] view plain copy
- # fdisk /dev/sdc
- Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
- Building a new DOS disklabel with disk identifier 0xe3266877.
- 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): 1
- First cylinder (1-20489, default 1):
- Using default value 1
- Last cylinder, +cylinders or +size{K,M,G} (1-20489, default 20489): +3G
-
-
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 2
- First cylinder (3074-20489, default 3074):
- Using default value 3074
- Last cylinder, +cylinders or +size{K,M,G} (3074-20489, default 20489): +2G
-
-
- Command (m for help): w
- The partition table has been altered!
-
-
- Calling ioctl() to re-read partition table.
- Syncing disks.
[plain] view plain copy
- # partx -a /dev/sdc
- BLKPG: Device or resource busy
- error adding partition 1
- BLKPG: Device or resource busy
- error adding partition 2
- # cat /proc/partitions
- major minor #blocks name
-
- 8 0 125829120 sda
- 8 1 512000 sda1
- 8 2 125316096 sda2
- 8 16 83886080 sdb
- 253 0 30720000 dm-0
- 253 1 4096000 dm-1
- 253 2 25600000 dm-2
- 253 3 30720000 dm-3
- 253 4 10240000 dm-4
- 8 48 31463302 sdd
- 8 32 20980858 sdc
- 8 33 3146736 sdc1
- 8 34 2098176 sdc2
格式化
[plain] view plain copy
- # mke2fs -t ext4 /dev/sdc1
- 挂载
- # mount /dev/sdc1 /mnt
- # cd /mnt
- # ls
- lost+found
- # cp /etc/rc.d/rc.sysinit ./
- # ls
- lost+found rc.sysinit
- # vim rc.sysinit
此时通过查看服务端target的分区情况并没有发生改变
关闭iSCSI服务器端
关闭iSCSI在开机重启或重启iscsi服务时自动对target进行重新连接,就需要在该客户机彻底将该target条目信息删除:
登出target会话:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -u
Logging out of session [sid: 1, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260]
Logout of [sid: 1, target: iqn.2016-04.com.chinasoft.san:1, portal: 192.168.8.42,3260] successful.
删除target条目的记录:
# iscsiadm -m node -T iqn.2016-04.com.chinasoft.san:1 -p 192.168.8.42 -o delete
在客户端删除了之前discovery发现的可用的target条目,则重启或重启服务后将不会自动进行重连接。
# ls /var/lib/iscsi/send_targets/
192.168.8.42,3260
# ls /var/lib/iscsi/
ifaces isns nodes send_targets slp static
# rm -rf /var/lib/iscsi/*
# ls /var/lib/iscsi/
六、通过编辑文件的方式定义target服务端
# cd /etc/tgt/
[# ls
targets.conf
[root@node4 tgt]# vim targets.conf
添加定义:
<target iqn.2016-04.com.chinasoft.san:2>
backing-store /dev/sdb2
initiator-address 192.168.8.0/24
</target>
# service tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
# tgtadm -L iscsi -o show -m target
至此iscsi服务端target及客户端initiator工具常用配置已讲解完毕
|
|