iSCSI服务配置全指南(含服务器与客户端)
iSCSI服务配置全指南(含服务器与客户端)

一、iSCSI简介
1. 概念
互联网小型计算机系统接口(Internet Small Computer System Interface,简称iSCSI)是一种基于TCP/IP的协议,其核心功能是通过IP网络仿真SCSI高性能本地存储总线,实现远程块存储设备的数据传输与管理。iSCSI采用客户端/服务器(C/S)架构,其中提供存储资源的一方称为“iSCSI目标(Target)”,访问存储的一方称为“iSCSI启动器(Initiator)”。
二、iSCSI存储服务器配置(提供iSCSI目标)
1. 准备存储分区
首先为iSCSI服务创建专用存储分区(以/dev/sda5为例,大小5G):
partprobe /dev/sda # 刷新分区表,使系统识别新分区
[root@zhangyiwei ~]# fdisk /dev/sda # 进入分区工具,新建分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):p
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009fd54
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 115345407 52428800 83 Linux
命令(输入 m 获取帮助):n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
已选择分区 4
起始 扇区 (115345408-209715199,默认为 115345408):
将使用默认值 115345408
Last 扇区, +扇区 or +size{
K,M,G} (115345408-209715199,默认为 209715199):
将使用默认值 209715199
分区 4 已设置为 Extended 类型,大小设为 45 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009fd54
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 115345407 52428800 83 Linux
/dev/sda4 115345408 209715199 47184896 5 Extended
命令(输入 m 获取帮助):n
All primary partitions are in use
添加逻辑分区 5
起始 扇区 (115347456-209715199,默认为 115347456):
将使用默认值 115347456
Last 扇区, +扇区 or +size{
K,M,G} (115347456-209715199,默认为 209715199):+10G
分区 5 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):P
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009fd54
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 115345407 52428800 83 Linux
/dev/sda4 115345408 209715199 47184896 5 Extended
/dev/sda5 115347456 136318975 10485760 83 Linux
命令(输入 m 获取帮助):W
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
[root@zhangyiwei ~]# partprobe /dev/sda# 刷新分区表,使系统识别新分区
[root@zhangyiwei ~]# parted /dev/sda #查看分区情况
GNU Parted 3.1
使用 /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit
Unit? [compact]? Mib
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 102400MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1.00MiB 1025MiB 1024MiB primary xfs 启动
2 1025MiB 5121MiB 4096MiB primary linux-swap(v1)
3 5121MiB 56321MiB 51200MiB primary xfs
4 56321MiB 102400MiB 46079MiB extended
5 56322MiB 66562MiB 10240MiB logical
(parted) quit
2. 安装配置工具
RHEL7中使用targetcli工具配置iSCSI目标,安装命令:
[root@zhangyiwei ~]# yum -y install targetcli
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 targetcli.noarch.0.2.1.fb46-7.el7 将被 安装
--> 正在处理依赖关系 python-rtslib >= 2.1.fb41,它被软件包 targetcli-2.1.fb46-7.el7.noarch 需要
--> 正在处理依赖关系 python-configshell,它被软件包 targetcli-2.1.fb46-7.el7.noarch 需要
--> 正在检查事务
---> 软件包 python-configshell.noarch.1.1.1.fb23-5.el7 将被 安装
--> 正在处理依赖关系 python-urwid,它被软件包 1:python-configshell-1.1.fb23-5.el7.noarch 需要
--> 正在处理依赖关系 pyparsing,它被软件包 1:python-configshell-1.1.fb23-5.el7.noarch 需要
---> 软件包 python-rtslib.noarch.0.2.1.fb63-13.el7 将被 安装
--> 正在处理依赖关系 python-kmod,它被软件包 python-rtslib-2.1.fb63-13.el7.noarch 需要
--> 正在检查事务
---> 软件包 pyparsing.noarch.0.1.5.6-9.el7 将被 安装
---> 软件包 python-kmod.x86_64.0.0.9-4.el7 将被 安装
---> 软件包 python-urwid.x86_64.0.1.1.1-3.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================
Package 架构 版本 源 大小
=====================================================================================================
正在安装:
targetcli noarch 2.1.fb46-7.el7 aa 67 k
为依赖而安装:
pyparsing noarch 1.5.6-9.el7 aa 94 k
python-configshell noarch 1:1.1.fb23-5.el7 aa 68 k
python-kmod x86_64 0.9-4.el7 aa 57 k
python-rtslib noarch 2.1.fb63-13.el7 aa 100 k
python-urwid x86_64 1.1.1-3.el7 aa 654 k
事务概要
=====================================================================================================
安装 1 软件包 (+5 依赖软件包)
总下载量:1.0 M
安装大小:4.6 M
Downloading packages:
-----------------------------------------------------------------------------------------------------
总计 24 MB/s | 1.0 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : python-kmod-0.9-4.el7.x86_64 1/6
正在安装 : python-rtslib-2.1.fb63-13.el7.noarch 2/6
正在安装 : pyparsing-1.5.6-9.el7.noarch 3/6
正在安装 : python-urwid-1.1.1-3.el7.x86_64 4/6
正在安装 : 1:python-configshell-1.1.fb23-5.el7.noarch 5/6
正在安装 : targetcli-2.1.fb46-7.el7.noarch 6/6
验证中 : 1:python-configshell-1.1.fb23-5.el7.noarch 1/6
验证中 : python-urwid-1.1.1-3.el7.x86_64 2/6
验证中 : targetcli-2.1.fb46-7.el7.noarch 3/6
验证中 : python-rtslib-2.1.fb63-13.el7.noarch 4/6
验证中 : pyparsing-1.5.6-9.el7.noarch 5/6
验证中 : python-kmod-0.9-4.el7.x86_64 6/6
已安装:
targetcli.noarch 0:2.1.fb46-7.el7
作为依赖被安装:
pyparsing.noarch 0:1.5.6-9.el7 python-configshell.noarch 1:1.1.fb23-5.el7
python-kmod.x86_64 0:0.9-4.el7 python-rtslib.noarch 0:2.1.fb63-13.el7
python-urwid.x86_64 0:1.1.1-3.el7
完毕!
3. 创建后备存储(Backstores)
后备存储是iSCSI目标提供的实际存储资源,支持block(块设备)、fileio(文件)、pscsi(物理SCSI)、ramdisk(内存盘)等类型,此处以块设备为例:
# 进入targetcli交互模式
[root@zhangyiwei named]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> ls
o- / .......................................................................................... [...]
o- backstores ........








