**ISCSI存储环境的搭建**
iSCSI的工作过程:当iSCSI主机应用程序发出数据读写请求后,操作系统会生成一个相应的SCSI命令,该SCSI命令在iSCSI initiator层被封装成ISCSI消息包并通过TCP/IP传送到设备侧,设备侧的iSCSI target层会解开iSCSI消息包,得到SCSI命令的内容,然后传送给SCSI设备执行;设备执行SCSI命令后的响应,在经过设备侧iSCSI target层时被封装成ISCSI响应PDU,通过TCP/IP网络传送给主机的ISCSI initiator层,iSCSI initiator会从ISCSI响应PDU里解析出SCSI响应并传送给操作系统,操作系统再响应给应用程序。
iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
一、创建模式
选项:-C
专用选项:
-l 级别
-n 设备个数
-a {yes|no} 自动为其创建设备文件
-c 指定数据块大小(chunk)
-x 指定空闲盘(热备磁盘)个数,空闲盘(热备磁盘)能在工作盘损坏后自动顶替
注意:创建阵列时,阵列所需磁盘数为-n参数和-x参数的个数和
客户机IP192.168.10.20
服务器IP192.168.10.10
服务器配置
创建raid5
[root@localhost ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2095616K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
查看记录 UUID
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Jul 13 03:55:35 2017
Raid Level : raid5
Array Size : 4191232 (4.00 GiB 4.29 GB)
Used Dev Size : 2095616 (2046.84 MiB 2145.91 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Thu Jul 13 03:55:46 2017
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 4b2604f1:c8ffccd2:833a1fd0:ee37bc43
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde
创建RAID阵列的配置文件
[root@localhost ~]# vim /etc/mdadm.conf
DEVICE /dev/sdb /dev/sdc /dev/sdd /dev/sde
ARRAY /dev/md0 UUID=4b2604f1:c8ffccd2:833a1fd0:ee37bc43
安装ISCSI target服务
[root@localhost ~]# yum -y install targetd targetcli
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
启动targetd服务并加入开机启动项
[root@localhost ~]#
systemctl enable targetd
ln -s '/usr/lib/systemd/system/targetd.service' '/etc/systemd/system/multi-user.target.wants/targetd.service
创建存储对象
[root@localhost ~]# 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]
进入backstores/block 使用/dev/md0创建disk0
/> cd backstores/block
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
创建iscsi target目标 创建lun设备
/> cd iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1.
Created TPG 1.
/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1/
/iscsi/iqn.20....9d393e04cca1> cd tpg1/
/iscsi/iqn.20...3e04cca1/tpg1> cd luns
/iscsi/iqn.20...ca1/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
设置访问控制列表
/iscsi/iqn.20...3e04cca1/tpg1> cd acls
/iscsi/iqn.20...ca1/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1:client
Created mapped LUN 0.
/iscsi/iqn.20...ca1/tpg1/acls>
..................................path|keyword=
/iscsi/iqn.20...3e04cca1/tpg1> cd portals
添加允许监听的ip地址
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.10
Using default IP port 3260
Created network portal 192.168.10.10:3260.
创建防火墙允许规则
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
客户机
安装 iscsi-initiator-utils
[root@client ~]# yum -y install iscsi-initiator-utils
编辑的iscsi客户端名称文件
[root@client ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:248056a6629
InitiatorName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1:client
连接iscsi服务端的可用存储设备
[root@client ~]# iscsiadm -m discovery -t st -p 192.168.10.10
192.168.10.10:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1
[root@client ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1 -p 192.168.10.10 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1, portal: 192.168.10.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.9d393e04cca1, portal: 192.168.10.10,3260] successful.
#发现多了一块硬盘设备
[root@client ~]# file /dev/sdc
/dev/sdc: block special
格式化硬盘
[root@client ~]# mkfs.xfs /dev/sdc
log stripe unit (524288 bytes) is too large (maximum is 256KiB)
log stripe unit adjusted to 32KiB
meta-data=/dev/sdc isize=256 agcount=8, agsize=130944 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=1047552, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载
[root@client ~]# mount /dev/sdc /iscsi/
[root@client ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 30G 6.5G 23G 22% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 914M 80K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda5 15G 132M 15G 1% /var
/dev/sda1 297M 91M 207M 31% /boot
/dev/sdc 4.0G 33M 4.0G 1% /iscsi
添加到开机挂载项
[root@client ~]# blkid | grep /dev/sdc
/dev/sdc: UUID="195b8cf9-e8c9-4d42-93f7-a745fc0aa470" TYPE="xfs"
[root@client ~]# vim /etc/fstab
#在最后一行加入下面代码
UUID=195b8cf9-e8c9-4d42-93f7-a745fc0aa470 /iscsi xfs defualt_netdev 0 0