CentOS 6.5 安装部署iSCSi共享存储
一、前言
1、什么是iSCSI?
iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
iSCSI:Internet 小型计算机系统接口 (iSCSI:Internet Small Computer System Interface)。
Internet 小型计算机系统接口(iSCSI)是一种基于 TCP/IP的协议,用来建立和管理 IP 存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得 SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。
SCSI 结构基于客户/服务器模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。此外,iSCSI 提供了在 IP 网络封装 SCSI 命令,且运行在 TCP 上。
2、环境介绍:
本次部署由3台物理机实现,具体信息分别为以下:
a、iSCSI_Server:192.168.30.133
b、iSCSI_Client1:192.168.30.131
c、iSCSI_Client2:192.168.30.132
需要用到的软件为:
a、scsi-target-utils # 提供Server端服务
b、iscsi-initiator-utils #提供Client服务
二、安装部署服务端,即iSCSI_Server
1、在服务端创建可共享的磁盘或卷;这里就新添加一块新磁盘做为共享;
查看新添加的硬盘:
[root@iSCSI_Server~]#fdisk-l
Disk/dev/sda:32.2GB,32212254720bytes
64heads,32sectors/track,30720cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x000da3dc
DeviceBootStartEndBlocksIdSystem
/dev/sda1*250151200083Linux
Partition1doesnotendoncylinderboundary.
/dev/sda250230720309442568eLinuxLVM
Partition2doesnotendoncylinderboundary.
Disk/dev/sdb:21.5GB,21474836480bytes
64heads,20480cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x00000000
2、对硬盘进行分区并创建LVM卷:
[root@iSCSI_Server ~]# 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 0x47756356. 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: 21.5 GB,21474836480 bytes64 heads,128);">32 sectors/track,128);">20480 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes Disk identifier: 0x47756356 Device Boot Start End Blocks Id System Command (m for help): n #新建一个分区
Command action e extended p primary partition (1-4) e # 新建一个逻辑分区
Partition number (4): 4 # 卷标为 4
First cylinder (20480,default 1): Using default value 1Last cylinder,+cylinders or +size{K,M,G} (20480): Using 20480Command (m for help): p # 查看信息
Disk /dev/sdb: 0x47756356 Device Boot Start End Blocks Id System/dev/sdb4 1 20480 20971504 5 Extended Command (m for help): n # 新建逻辑卷
Command action l logical (5 or over) p primary partition (4) l # 选择l,逻辑卷
First cylinder (for help): p # 查看信息
Disk /dev/sdb: 0x47756356 Device Boot Start End Blocks Id System
/dev/sdb4 5 Extended
/dev/sdb5 20971488 83 Linux Command (m for help): w # 保存
The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks
[root@iSCSI_Server ~]# partprobe /dev/sdb # 使刚才的配置立即生效
[root@iSCSI_Server ~]# fdisk -l
Disk /dev/sda: 32.2 GB,32212254720 bytes
64 heads,32 sectors/track,30720 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: 0x000da3dc
Device Boot Start End Blocks Id System
/dev/sda1 * 2 501 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 502 30720 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/sdb: 21.5 GB,21474836480 bytes
64 heads,20480 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: 0x47756356
Device Boot Start End Blocks Id System
/dev/sdb4 1 20480 20971504 5 Extended
/dev/sdb5 1 20480 20971488 83 Linux
[root@iSCSI_Server ~]# cat /proc/partitions
major minor #blocks name
8 0 31457280 sda
8 1 512000 sda1
8 2 30944256 sda2
8 16 20971520 sdb
8 20 1 sdb4
8 21 20971488 sdb5
253 0 27795456 dm-0
253 1 3145728 dm-1
#注:看到以上标黄的信息证明已经创建逻辑卷成功!
接下来创建LVM卷
[root@iSCSI_Server ~]# pvcreate /dev/sdb5 # 创建PV
Physical volume "/dev/sdb5" successfully created
[root@iSCSI_Server ~]# vgcreate kvmvg /dev/sdb5 # 创建VG
Volume group "kvmvg" successfully created
[root@iSCSI_Server ~]# lvcreate -L 19G -n kvmlv kvmvg # 创建LV
Logical volume "kvmlv" created.
[root@iSCSI_Server ~]# lvs # 查看
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 26.51g
lv_swap VolGroup -wi-ao---- 3.00g
kvmlv kvmvg -wi-a----- 19.00g
[root@iSCSI_Server ~]#
#注:看到以上标黄的信息证明已经创建成功!
3、安装服务端软件:scsi-target-utils
[root@iSCSI_Server~]#yum-yinstallepel-release
[root@iSCSI_Server~]#yum-yinstallscsi-target-utils.x86_64
4、配置iSCSI服务:
[root@iSCSI_Server~]#vim/etc/tgt/targets.conf
####在40行后添加以下信息#######
<targetiqn.2017-03.com.zlyang:kvm.iscsi>
backing-store/dev/kvmvg/kvmlv
initiator-address192.168.30.0/24
</target>
注:
iqn.2017-03.com.zlyang:kvm.iscsi : 为共享名
iqn.2017-03.com.zlyang:kvm.iscsi :共享卷名及路径
initiator-address 192.168.30.0/24 :允许哪些地址访问
5、启动服务
[root@iSCSI_Server~]# service tgtd start
[root@iSCSI_Server ~]# chkconfig tgtd on
[root@iSCSI_Server~]#netstat-tnlt|grep3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
tcp 0 0 :::3260 :::* LISTEN
6、添加防火墙规则
[root@iSCSI_Server~]#iptables-IINPUT4-ptcp--dport 3260 -j ACCEPT
[root@iSCSI_Server ~]#iptables-save
[root@iSCSI_Server~]#serviceiptablessave
[root@iSCSI_Server~]#serviceiptablesrestart
三、安装Client
因为两台Client配置几乎一样,在此以Client1为例给大家演示具体部署过程
1、首先查看本地磁盘
[root@iSCSI_Client_1~]#fdisk-l
Disk/dev/sda:32.2GB,32212254720bytes64heads,30720cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x000da3dc
DeviceBootStartEndBlocksIdSystem
/dev/sda1*250151200083Linux
Partition1doesnotendoncylinderboundary.
/dev/sda250230720309442568eLinuxLVM
Partition2doesnotendoncylinderboundary.
Disk/dev/mapper/VolGroup-lv_root:28.5GB,28462546944bytes
255heads,63sectors/track,3460cylinders
Units=cylindersof16065*512=8225280bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x00000000
Disk/dev/mapper/VolGroup-lv_swap:3221MB,3221225472bytes
255heads,391cylinders
Units=cylindersof16065*512=8225280bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x00000000
# 可以看出只有一块磁盘
2、安装Client软件
[root@iSCSI_Client_1~]#yum-yinstallepel-release
[root@iSCSI_Client_1~]#yum-yinstalliscsi-initiator-utils.x86_64
3、启动服务
[root@iSCSI_Client_1~]#serviceiscsidstart
[root@iSCSI_Client_1~]#chkconfigiscsidon
4、发现下iSCSI服务端
[root@iSCSI_Client_1~]#iscsiadm-mdiscovery-tst-p192.168.30.133
192.168.30.133:3260,1iqn.2017-03.com.zlyang:kvm.iscsi
5、挂载该磁盘
a、加载磁盘
#iscsiadm-mnode-Tiqn.2017-03.com.zlyang:kvm.iscsi-p192.168.30.133-l
Logginginto[iface:default,target:iqn.2017-03.com.zlyang:kvm.iscsi,portal:192.168.30.133,3260](multiple)
Loginto[iface:default,3260]successful.
#echo"iscsiadm-mnode-Tiqn.2017-03.com.zlyang:kvm.iscsi-p192.168.30.133-l">>/etc/rc.d/rc.local"
[root@iSCSI_Client_1~]#fdisk-l
Disk /dev/sdc: 20.4 GB,20401094656 bytes
64 heads,19456 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
注:看到此信息表示已经加载成功
b、分区格式化
[root@iSCSI_Client_1~]#mkfs.ext4/dev/sdc
mke2fs1.41.12(17-May-2010)/dev/sdcisentiredevice,notjustonepartition!
Proceedanyway?(y,n)y
Filesystemlabel=OStype:Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
Stride=0blocks,Stripewidth=0blocks
1245184inodes,4980736blocks
249036blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=4294967296
152blockgroups3
2768blockspergroup,32768fragmentspergroup
8192inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912,819200,884736,1605632,2654208,
4096000Writinginodetables:done
Creatingjournal(32768blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery35mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
[root@iSCSI_Client_1~]#
c、挂载到本地
[root@iSCSI_Client_1 ~]# mount /dev/sdc /mnt
[root@iSCSI_Client_1 ~]# echo "mount /dev/sdc /mnt" >> /etc/rc.d/rc.local [root@iSCSI_Client_1 ~]# df -h Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 26G 2.6G 23G 11% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/sda1 477M 52M 400M 12% /boot
/dev/sdc 19G 44M 18G 1% /mnt
[root@iSCSI_Client_1 ~]#
Client_1的所有配置已经配置完成,Client_2配置与Client_1基本相同,只是Client_2不需要再分区格式化了,直接加载及挂载就可以!