CentOS 6.6 安装 iSCSI
一,ISCSI简介
iSCSI,即internet SCSI,又称为IP-SAN,是IETF制订的一项标准,用于将SCSI数据块映射成以太网数据包。iSCSI是一种基于TCP/IP 的协议,用来建立和管理IP存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于C/S模式,其通常应用环境是:设备互相靠近,并且这些设备由SCSI 总线连接。
iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。
从根本上说,iSCSI协议是一种跨过IP网络来传输潜伏时间短的SCSI数据块的方法。
完整的iSCSI系统的拓扑结构如下:
与传统的SCSI技术比较起来,iSCSI技术有以下三个革命性的变化:
- 把原来只用于本机的SCSI协同透过TCP/IP网络传送,使连接距离可作无限的地域延伸;
- 连接的服务器数量无限(原来的SCSI-3的上限是15);
- 由于是服务器架构,因此也可以实现在线扩容以至动态部署。
ISCSI的协议结构:
--------------------------------------分割线--------------------------------------
--------------------------------------分割线--------------------------------------
二,搭建基于 IP SAN 的 ISCSI 存储系统
- 规划:
- 环境: CentOS 6.6 32位
- 服务器端 IP: 192.168.1.43
- 客户端 IP : 192.168.1.111
- 共享磁盘: /dev/sdb
1,配置服务器端
- [root@localhost ~]# yum -y install scsi-target-utils #安装服务器端软件
- [root@node1 iscsi]# rpm -ql scsi-target-utils
- /etc/rc.d/init.d/tgtd
- /etc/sysconfig/tgtd
- /etc/tgt/targets.conf #配置文件
- /usr/sbin/tgt-admin
- /usr/sbin/tgt-setup-lun
- /usr/sbin/tgtadm
- /usr/sbin/tgtd
- /usr/sbin/tgtimg
- /usr/share/doc/scsi-target-utils-1.0.24
- /usr/share/doc/scsi-target-utils-1.0.24/README
- /usr/share/doc/scsi-target-utils-1.0.24/README.iscsi
- /usr/share/doc/scsi-target-utils-1.0.24/README.iser
- /usr/share/doc/scsi-target-utils-1.0.24/README.lu_configuration
- /usr/share/doc/scsi-target-utils-1.0.24/README.mmc
- /usr/share/man/man5/targets.conf.5.gz
- /usr/share/man/man8/tgt-admin.8.gz
- /usr/share/man/man8/tgt-setup-lun.8.gz
- /usr/share/man/man8/tgtadm.8.gz
- [root@localhost ~]# lsmod |grep scsi
- mptscsih 31330 1 mptspi
- mptbase 86744 2 mptspi,mptscsih
- scsi_transport_spi 19726 1 mptspi #高级驱动程序
iscsi可以使用命令或配置文件进行配置,我们首先使用命令行来进行配置:
- [root@node1 iscsi]# service tgtd start
- Starting SCSI target daemon: [ OK ]
- [root@node1 iscsi]# ss -tlnp |grep 3260 #其监听在3260端口
- LISTEN 0 128 :::3260 :::* users:(("tgtd",11882,5),("tgtd",11885,5))
- LISTEN 0 128 *:3260 *:* users:(("tgtd",11882,4),("tgtd",11885,4))
- [root@localhost ~]# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2015-08.com.feiyu.testsan:1 #创建一个target,-t指定TID,-T指定名称
iqn表示“ISCSI Qualified Name”,简称iqn。
- [root@localhost ~]# tgtadm -L iscsi -o show -m target
- Target 1: iqn.2015-08.com.feiyu.testsan:1
- 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:
- Account information:
- ACL information:
然后设定LUN(Logical Unit Number,逻辑单元号),服务器端只需要创建好分区,不需要格式化:
- [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/sdb5 #创建一个LUN,-m表示模式,-l :LUN ,-b: 设备
- [root@localhost ~]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16
- [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
- Target 1: iqn.2015-08.com.feiyu.testsan:1
- 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: 2107 MB, Block size: 512
- Online: Yes
- Removable media: No
- Prevent removal: No
- Readonly: No
- Backing store type: rdwr
- Backing store path: /dev/sdb5
- Backing store flags:
- Account information:
- ACL information:
- [root@node1 iscsi]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.0.0/16 #设定共享区
- [root@node1 iscsi]# tgtadm -L iscsi -o show -m target
- Target 1: iqn.2015-08.com.feiyu.testsan:1
- 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: 2107 MB, Block size: 512
- Online: Yes
- Removable media: No
- Prevent removal: No
- Readonly: No
- Backing store type: rdwr
- Backing store path: /dev/sda5
- Backing store flags:
- Account information:
- ACL information:
- 192.168.0.0/16
- [root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 2 -b /dev/sdb6 #绑定第二个LUN
2,配置客户端
- [root@node1 ~]# yum install -y iscsi-initiator-utils #安装客户端
- [root@node1 iscsi]# echo "InitiatorName=`iscsi-iname -p iqn.2013-05.com.feiyu`" > /etc/iscsi/initiatorname.iscsi #生成iqn
- [root@node1 iscsi]# echo "InitiatorAlias=initiator1" >> /etc/iscsi/initiatorname.iscsi #定义别名
- [root@node1 iscsi]# ls
- initiatorname.iscsi iscsid.conf
- [root@node1 iscsi]# cat initiatorname.iscsi #查看所定义的数据
- InitiatorName=iqn.2015-08.com.feiyu:10834bd52221
- InitiatorAlias=initiator1
- [root@node1 ~]# service iscsi start #启动服务,需要启动两个服务
- [root@node1 ~]# service iscsid start
- [root@node1 ~]# chkconfig iscsi on
- [root@node1 ~]# chkconfig iscsid on
若出现以下错误,可能由于服务器端的防火墙没有关!
- [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43
- Starting iscsid: [ OK ]
- iscsiadm: cannot make connection to 192.168.1.43: No route to host
- [root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.43 #进行探测
- 192.168.1.43:3260,1 iqn.2015-08.com.feiyu.testsan:1
- [root@node1 ~]# iscsiadm -m node -T iqn.2015-08.com.feiyu.testsan:1 -p 192.168.1.43 -l #登录节点
- Logging in to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] (multiple)
- Login to [iface: default, target: iqn.2015-08.com.feiyu.testsan:1, portal: 192.168.1.43,3260] successful.
- [root@node1 ~]# fdisk -l #登录成功可以看到多了一块硬盘,
- Disk /dev/sda: 21.5 GB, 21474836480 bytes
- 255 heads, 63 sectors/track, 2610 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: 0x0006d052
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 39 307200 83 Linux
- Partition 1 does not end on cylinder boundary.
- /dev/sda2 39 2354 18598912 83 Linux
- /dev/sda3 2354 2610 2057689 5 Extended
- /dev/sda5 2354 2610 2057657+ 83 Linux
- Disk /dev/sdc: 10.7 GB, 10742183424 bytes -------> iscsi设备
- 64 heads, 32 sectors/track, 10244 cylinders
- Units = cylinders of 2048 * 512 = 1048576 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk identifier: 0x00000000
为磁盘创建分区并格式化。
- [root@node1 ~]# mke2fs -t ext4 /dev/sdc1