操作系统: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 通
[root@localhost /]# yum install scsi-target-utils
# /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 搭建共享镜像文件设备程序
# 首先确认下当前系统磁盘 fdisk -l
# 然后对此磁盘进行新建分区
[root@localhost /]# fdisk /dev/sda
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').
# 在此选择DOS兼容模式查看分区大小,单位为柱面,默认或者选择 'u',则单位为扇区
Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
# 查看分区表
Command (m for help): p
Disk /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: 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
# 新建分区
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): p
Disk /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: 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 8e Linux LVM
Command (m for help): q
#管理LVM分区-创建物理卷与卷组逻辑卷(删除则是按照与创建相反的顺序)
[root@localhost /]# pvcreate /dev/sda7
Physical 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/sda7
Volume group "VolGroup00" successfully created
[root@localhost /]# lvcreate -L 800M -n iscsi00 VolGroup00
Logical volume "iscsi00" created
[root@localhost /]# lvscan
ACTIVE '/dev/VolGroup00/iscsi00' [800.00 MiB] inherit
[root@localhost /]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup00/iscsi00
LV Name iscsi00
VG Name VolGroup00
LV UUID Dzt8dM-d6zS-6ff8-aNlP-4R1Z-7KGL-n0yUQH
LV Write Access read/write
LV Creation host, time localhost.iscsi, 2017-01-20 15:34:58 +0800
LV Status available
# open 0
LV Size 800.00 MiB
Current LE 100
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
# 在配置文件中加入下列语句
backing-store /dev/sda6
backing-store /dev/VolGroup00/iscsi00
initiator-address 10.0.0.12
initiator-address 10.0.0.13
initiator-address 10.0.0.0/24
incominguser viscsiuser viscsipasswd
write-cache off
# 说明
# 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 配置通过用户名密码访问
[root@localhost tgt]# /etc/init.d/tgtd restart
停止 SCSI target daemon: [确定]
正在启动 SCSI target daemon: [确定]
[root@localhost tgt]# tgt-admin --show
Target 1: iqn.2017-01.org.rambo:viscsidisk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 839 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/VolGroup00/iscsi00
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 1083 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sda6
Backing store flags:
Account information:
viscsiuser
ACL information:
10.0.0.12
10.0.0.13
10.0.0.0/24
通过输出信息,可以看到我们之前设置的用于共享的磁盘和允许的客户端IP信息。至此,target 服务器配置就完成了。