实验环境
操作系统:CentOS release 6.5 (Final)
iSCSI Target:10.0.0.11 (#yum install scsi-target-utils)
iSCSI Initiator 1:10.0.0.12 (#yum install iscsi-initiator-utils)
iSCSI Initiator 2::10.0.0.13 (#yum install iscsi-initiator-utils)
防火墙已关闭/iptables:Firewall is not running. (#service iptables stop or #/etc/init.d/iptables stop)
SELINUX: disabled (#setenforce 0)
验证:配置好之后三台主机之间可以相互 ping 通
存储服务器上安装配置 iSCSI target
1. 安装scsi-target-utils 软件
[root@localhost /]# yum install scsi-target-utils
2. 查看相关配置文件
# /etc/tgt/targets.conf 主配置文件,设置要共享的磁盘格式与块设备等
# /usr/sbin/tgt-admin 查询、删除target等功能的设置工具
# /usr/sbin/tgt-setup-lun 建立target以及设置共享的磁盘与可使用的客户端等的程序
# /usr/sbin/tgtadm iscsi target管理程序(可使用配置文件取代)
# /usr/sbin/tgtd 提供iSCSI target服务的主程序
# /usr/sbin/tgtimg 搭建共享镜像文件设备程序
3. 建立分区配置存储
# 首先确认下当前系统磁盘 fdisk -l
# 然后对此磁盘进行新建分区
[root@localhost /]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units tosectors (command 'u').# 在此选择DOS兼容模式查看分区大小,单位为柱面,默认或者选择 'u',则单位为扇区
Command (m for help): c
DOS Compatibility flag is not setCommand (m for help): m
Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)# 查看分区表
Command (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 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: 0x0006c4a5Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
/dev/sda2 26 1070 8388608 83 Linux
/dev/sda3 1070 1332 2097152 82 Linux swap / Solaris
/dev/sda4 1332 1959 5037056 5 Extended
/dev/sda5 1332 1593 2097152 83 Linux# 新建分区
Command (m for help): n
First cylinder (1593-1959, default 1593):
Using default value 1593
# 容量分配为1个G
Last cylinder, +cylinders or +size{K,M,G} (1593-1959, default 1959): +1G# 新建分区
Command (m for help): nFirst cylinder (1725-1959, default 1725): Using default value 1725
# 容量分配为1个G
Last cylinder, +cylinders or +size{K,M,G} (1725-1959, default 1959): +1GCommand (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes255 heads, 63 sectors/track, 1958 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0006c4a5 Device Boot Start End Blocks Id System/dev/sda1 * 1 26 204800 83 Linux/dev/sda2 26 1070 8388608 83 Linux/dev/sda3 1070 1332 2097152 82 Linux swap / Solaris/dev/sda4 1332 1959 5037056 5 Extended/dev/sda5 1332 1593 2097152 83 Linux/dev/sda6 1593 1724 1056221+ 83 Linux/dev/sda7 1725 1856 1059266 83 Linux
# 改变分区系统ID,也就是转换分区
Command (m for help): t
Partition number (1-7): 7
# 输入LVM类型编码 8e
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)Command (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 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: 0x0006c4a5Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
/dev/sda2 26 1070 8388608 83 Linux
/dev/sda3 1070 1332 2097152 82 Linux swap / Solaris
/dev/sda4 1332 1959 5037056 5 Extended
/dev/sda5 1332 1593 2097152 83 Linux
/dev/sda6 1593 1724 1056221+ 83 Linux
/dev/sda7 1725 1856 1059266 8e Linux LVMCommand (m for help): q#管理LVM分区-创建物理卷与卷组逻辑卷(删除则是按照与创建相反的顺序)
[root@localhost /]# pvcreate /dev/sda7Physical volume "/dev/sda7" successfully created
[root@localhost /]# vgcreate -s 8M VolGroup00 /dev/sda
sda sda1 sda2 sda3 sda4 sda5 sda6 sda7
[root@localhost /]# vgcreate -s 8M VolGroup00 /dev/sda7Volume group "VolGroup00" successfully created
[root@localhost /]# lvcreate -L 800M -n iscsi00 VolGroup00Logical volume "iscsi00" created
[root@localhost /]# lvscanACTIVE '/dev/VolGroup00/iscsi00' [800.00 MiB] inherit
[root@localhost /]# lvdisplay--- Logical volume ---LV Path /dev/VolGroup00/iscsi00LV Name iscsi00VG Name VolGroup00LV UUID Dzt8dM-d6zS-6ff8-aNlP-4R1Z-7KGL-n0yUQHLV Write Access read/writeLV Creation host, time localhost.iscsi, 2017-01-20 15:34:58 +0800LV Status available# open 0LV Size 800.00 MiBCurrent LE 100Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:0
4. 配置/etc/tgt/targets.conf,设置共享存储设备的路径相关属性
# 在配置文件中加入下列语句
<target iqn.2017-01.org.rambo:viscsidisk>backing-store /dev/sda6backing-store /dev/VolGroup00/iscsi00initiator-address 10.0.0.12initiator-address 10.0.0.13initiator-address 10.0.0.0/24incominguser viscsiuser viscsipasswdwrite-cache off
</target>
# 说明
# iqn = iSCSI Qualified Name
# backing-store 逻辑单元号(Logical Unit Number,LUN),这个实验中有2个LUN。
# target iSCSI target名称,规则如下:#iqn.2017-01.org.rambo:viscsidisk (格式: iqn.年份-月份.域名反写.设备识别)
# initiator-address 允许的initiator IP地址
# incominguser 配置通过用户名密码访问
5. 重启 tgtd 服务
[root@localhost tgt]# /etc/init.d/tgtd restart
停止 SCSI target daemon: [确定]
正在启动 SCSI target daemon: [确定]
6. 查看iscsi target共享存储的相关信息,使用tgt-admin --show命令
[root@localhost tgt]# tgt-admin --show
Target 1: iqn.2017-01.org.rambo:viscsidiskSystem information:Driver: iscsiState: readyI_T nexus information:LUN information:LUN: 0Type: controllerSCSI ID: IET 00010000SCSI SN: beaf10Size: 0 MB, Block size: 1Online: YesRemovable media: NoPrevent removal: NoReadonly: NoBacking store type: nullBacking store path: NoneBacking store flags: LUN: 1Type: diskSCSI ID: IET 00010001SCSI SN: beaf11Size: 839 MB, Block size: 512Online: YesRemovable media: NoPrevent removal: NoReadonly: NoBacking store type: rdwrBacking store path: /dev/VolGroup00/iscsi00Backing store flags: LUN: 2Type: diskSCSI ID: IET 00010002SCSI SN: beaf12Size: 1083 MB, Block size: 512Online: YesRemovable media: NoPrevent removal: NoReadonly: NoBacking store type: rdwrBacking store path: /dev/sda6Backing store flags: Account information:viscsiuserACL information:10.0.0.1210.0.0.1310.0.0.0/24
通过输出信息,可以看到我们之前设置的用于共享的磁盘和允许的客户端IP信息。至此,target 服务器配置就完成了。