目录node
1、ISCSI简介
SCSI 即小型计算机系统接口(Small Computer System Interface;简写:SCSI),一种用于计算机和外部设备之间(硬盘、光驱、软驱、打印机等)系统级接口的独立处理器标准。SCSI是一种智能的通用接口标准,它是各类计算机和外部设备之间的接口标准。shell
iSCSI是由Cisco和IBM发起的,它将SCSI命令封装在TCP/IP包里,并使用一个iSCSI帧头。它基于IP协议栈,假设以不可靠的网络为基础,依靠TCP恢复丢失的数据包。数据库
背景:
相比直连存储,网络存储解决方案可以更加有效地共享,整合和管理资源。从服务器为中心的存储转向网络存储,一直依赖于数据传输技术的发展,速度要求与直连存储至关,甚至更高,同事须要克服并行SCSI固有的局限性。vim
全部数据在没有文件系统格式化的状况下,都以块的形式存储于磁盘上。并行SCSI将数据以块的形式传送至存储,可是,对于网络它的用处至关有限,由于线缆不能超过25m,并且最多链接16个设备;后端
光纤通道(FC,Fiber Channel,跑FC协议)是目前SAN的主导架构,它在专门的高速网络上分离存储资源。光纤通道协议与互联技术起源于知足高性能传送块数据的需求,同时克服直连存储的链接和距离限制。一般光纤通道设备链接距离可达到10000米,甚至数十万米,而且对于链接在SAN之上的设备没有数量要求。服务器
与SAN不一样,NAS将数据以文件的形式传输而且能够直接链接至IP网络。部署NAS设备传送数据库块数据,使用基于SCSI的光纤通道协议,比Server Message Block(SMB)协议更加高效。网络
iSCSI是一种使用TCP/IP协议,在现有IP网络上传输SCSI块命令的工业标准,它是一种在现有的IP网络上无需安装单独的光纤网络便可同时传输消息和块数据的突破性技术。iSCSI基于应用很是普遍的TCP/IP协议,将SCSI命令/数据块封装为iSCSI包,再封装至TCP 报文,而后封装到IP 报文中。iSCSI经过TCP面向链接的协议来保护数据块的可靠交付。因为iSCSI基于IP协议栈,所以能够在标准以太网设备上经过路由或交换机来传输。架构
准备两台Linux服务器app
IP 安装的软件
172.25.0.10 iscsi target端:targetcli
172.25.0.11 iscsi客户端:iscsi-inittcp
要求:
配置 server 提供一个 iSCSI 共享服务;磁盘名为 iqn.2014-09.com.example:server,服务端口为 3260,使用 iscsi_store 做为其后端卷其大小为 3G,此服务只能被 desktop.example.com 访问
配置 desktop 使其能链接在 server 上提供的 iscsi;iSCSI 设备在系统启动的期间自动加载块设备 iSCSI 上包含一个大小 1500MiB 的分区,并格式化为 ext4,此分区挂载在/mnt/netdev 上同时在系统启动的期间自动加载
//安装服务端主程序 yum -y install targetcli* lsblk //分出3G的分区用于共享 fdisk /dev/vdb +3G partprobe /dev/vdb //交互式配置 [root@server0 ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb34 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> ls o- / ................................................................................................. [...] o- backstores ...................................................................................... [...] | o- block .......................................................................... [Storage Objects: 0] | o- fileio ......................................................................... [Storage Objects: 0] | o- pscsi .......................................................................... [Storage Objects: 0] | o- ramdisk ........................................................................ [Storage Objects: 0] o- iscsi .................................................................................... [Targets: 0] o- loopback ................................................................................. [Targets: 0] /> cd backstores/block /backstores/block> create iscsi_store /dev/vdb1 Created block storage object iscsi_store using /dev/vdb1. /backstores/block> cd /iscsi /iscsi> create iqn.2014-09.com.example:server Created target iqn.2014-09.com.example:server. Created TPG 1. /iscsi> ls o- iscsi ...................................................................................... [Targets: 1] o- iqn.2014-09.com.example:server .............................................................. [TPGs: 1] o- tpg1 ......................................................................... [no-gen-acls, no-auth] o- acls .................................................................................... [ACLs: 0] o- luns .................................................................................... [LUNs: 0] o- portals .............................................................................. [Portals: 0] /iscsi> cd iqn.2014-09.com.example:server/tpg1/acls /iscsi/iqn.20...ver/tpg1/acls> create iqn.2014-09.com.example:desktop Created Node ACL for iqn.2014-09.com.example:desktop /iscsi/iqn.20...ver/tpg1/acls> cd ../luns /iscsi/iqn.20...ver/tpg1/luns> create /backstores/block/iscsi_store Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2014-09.com.example:desktop /iscsi/iqn.20...ver/tpg1/luns> cd ../portals /iscsi/iqn.20.../tpg1/portals> create 172.25.0.11 3260 Using default IP port 3260 Created network portal 172.25.0.11:3260. /iscsi/iqn.20.../tpg1/portals> cd / /> ls o- / ................................................................................................. [...] o- backstores ...................................................................................... [...] | o- block .......................................................................... [Storage Objects: 1] | | o- iscsi_store ............................................. [/dev/vdb1 (3.0GiB) write-thru activated] | o- fileio ......................................................................... [Storage Objects: 0] | o- pscsi .......................................................................... [Storage Objects: 0] | o- ramdisk ........................................................................ [Storage Objects: 0] o- iscsi .................................................................................... [Targets: 1] | o- iqn.2014-09.com.example:server ............................................................ [TPGs: 1] | o- tpg1 ....................................................................... [no-gen-acls, no-auth] | o- acls .................................................................................. [ACLs: 1] | | o- iqn.2014-09.com.example:desktop .............................................. [Mapped LUNs: 1] | | o- mapped_lun0 ................................................... [lun0 block/iscsi_store (rw)] | o- luns .................................................................................. [LUNs: 1] | | o- lun0 .......................................................... [block/iscsi_store (/dev/vdb1)] | o- portals ............................................................................ [Portals: 1] | o- 172.25.0.11:3260 ......................................................................... [OK] o- loopback ................................................................................. [Targets: 0] /> exit //启动target服务并加入自启动 systemctl enable target.service systemctl restart target.service //加入防火墙 firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.25.0.0/24 port port=3260 protocol=tcp accept' --permanent firewall-cmd --reload firewall-cmd --list-all
//安装客户端iscsi程序 yum -y install iscsi-init* man iscsiadm //修改iscsi配置文件,并链接上主服务器 iscsiadm --mode discoverydb --type sendtargets --portal 172.25.0.11 –discover vim /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2014-09.com.example:desktop systemctl restart iscsid.service systemctl enable iscsid.service iscsiadm --mode node --targetname iqn.2014-09.com.example:server --portal 172.25.0.11:3260 –login //链接成功后查看磁盘会发现多个新磁盘,而后根据使用需求挂载并使用 lsblk fdisk /dev/sda +1500M partprobe /dev/sda mkfs.ext4 /dev/sda1 mkdir /mnt/netdev blkid vim /etc/fstab UUID /mnt/netdev ext4 defaults,_netdev 0 0 mount -a //挂载上就能够正常使用了 df -Th