共计 9429 个字符,预计需要花费 24 分钟才能阅读完成。
一、前言
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.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, 32 sectors/track, 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: 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, 32 sectors/track, 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
Command (m for help): n #新建一个分区
Command action
e extended
p primary partition (1-4)
e # 新建一个逻辑分区
Partition number (1-4): 4 # 卷标为 4
First cylinder (1-20480, default 1):
Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480):
Using default value 20480Command (m for help): p # 查看信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes64 heads, 32 sectors/track, 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
Command (m for help): n # 新建逻辑卷
Command action
l logical (5 or over)
p primary partition (1-4)
l # 选择 l, 逻辑卷
First cylinder (1-20480, default 1):
Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480):
Using default value 20480Command (m for help): p # 查看信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes64 heads, 32 sectors/track, 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
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, 32 sectors/track, 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 -y install epel-release
[root@iSCSI_Server ~]# yum -y install scsi-target-utils.x86_64
4、配置 iSCSI 服务:
[root@iSCSI_Server ~]# vim /etc/tgt/targets.conf
#### 在 40 行后添加以下信息 #######
<target iqn.2017-03.com.zlyang:kvm.iscsi>
backing-store /dev/kvmvg/kvmlv
initiator-address 192.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|grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
tcp 0 0 :::3260 :::* LISTEN
6、添加防火墙规则
[root@iSCSI_Server ~]# iptables -I INPUT 4 -p tcp –dport 3260 -j ACCEPT
[root@iSCSI_Server ~]# iptables-save
[root@iSCSI_Server ~]# service iptables save
[root@iSCSI_Server ~]# service iptables restart
三、安装 Client
因为两台 Client 配置几乎一样,在此以 Client1 为例给大家演示具体部署过程
1、首先查看本地磁盘
[root@iSCSI_Client_1 ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes64 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/mapper/VolGroup-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 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: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 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: 0x00000000
# 可以看出只有一块磁盘
2、安装 Client 软件
[root@iSCSI_Client_1 ~]# yum -y install epel-release
[root@iSCSI_Client_1 ~]# yum -y install iscsi-initiator-utils.x86_64
3、启动服务
[root@iSCSI_Client_1 ~]# service iscsid start
[root@iSCSI_Client_1 ~]# chkconfig iscsid on
4、发现下 iSCSI 服务端
[root@iSCSI_Client_1 ~]# iscsiadm -m discovery -t st -p 192.168.30.133
192.168.30.133:3260,1 iqn.2017-03.com.zlyang:kvm.iscsi
5、挂载该磁盘
a、加载磁盘
# iscsiadm -m node -T iqn.2017-03.com.zlyang:kvm.iscsi -p 192.168.30.133 -l
Logging in to [iface: default, target: iqn.2017-03.com.zlyang:kvm.iscsi, portal: 192.168.30.133,3260] (multiple)
Login to [iface: default, target: iqn.2017-03.com.zlyang:kvm.iscsi, portal: 192.168.30.133,3260] successful.
# echo “iscsiadm -m node -T iqn.2017-03.com.zlyang:kvm.iscsi -p 192.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, 32 sectors/track, 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
mke2fs 1.41.12 (17-May-2010)/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1245184 inodes, 4980736 blocks
249036 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
152 block groups3
2768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[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 不需要再分区格式化了,直接加载及挂载就可以!
好了,部署已经全部完成,如果什么问题可以回复或发邮件到:DBA_Master@163.com
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141227.htm