iscsi服务端配置
操作系统版本:
[root@ex333server ~]# lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release: 5.5
创建如下两个用来共享的逻辑卷:
[root@ex333server ~]# lvs
/dev/cdrom: open failed: No medium found
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_iscsi_244 vg_iscsi -wi-a- 4.00M
lv_iscsi_demo vg_iscsi -wi-a- 4.00M
安装软件包:
yum install scsi-target-utils
启动服务:
/etc/init.d/tgtd restart
chkconfig tgtd on
1. 通过命令配置iscsi服务端:
创建一个target:
tgtadm --lld iscsi --op new --mode target --tid=1 --targetname iqn.2012-05.com.example.ex333server:rdisks.demo
绑定共享设备到target:
tgtadm --lld iscsi --op new --mode=logicalunit --tid=1 --lun=1 --backing-store /dev/vg_iscsi/lv_iscsi_demo
设置可以访问共享的网段:
tgtadm --lld iscsi --op bind --mode=target --tid=1 --initiator-address=192.168.221.0/24
本地查看共享设备:
tgtadm --lld iscsi --op show --mode target
检查结果:
[root@ex333server init.d]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2012-05.com.example.ex333server:rdisks.demo
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
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 4 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/vg_iscsi/lv_iscsi_demo
Account information:
ACL information:
192.168.221.0/24
[root@ex333server init.d]# service tgtd restart
Stopping SCSI target daemon: Stopping target framework daemon
[ OK ]
Starting SCSI target daemon: Starting target framework daemon
[root@ex333server init.d]# tgtadm --lld iscsi --op show --mode target
[root@ex333server init.d]#
通过命令创建的iscsi共享在系统重启或服务重启后消失。
2. 通过配置文件创建iscsi共享:
vim /etc/tgt/targets.conf
<target iqn.2012-05.com.example:ex333server.demo>
backing-store /dev/vg_iscsi/lv_iscsi_demo
initiator-address 192.168.221.0/24
</target>
<target iqn.2012-05.com.example:ex333server.target244>
backing-store /dev/vg_iscsi/lv_iscsi_244
initiator-address 192.168.221.244
</target>
[root@ex333server tgt]# service tgtd restart
Stopping SCSI target daemon: Stopping target framework daemon
[ OK ]
Starting SCSI target daemon: Starting target framework daemon
[root@ex333server tgt]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2012-05.com.example:ex333server.demo
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
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 4 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/vg_iscsi/lv_iscsi_demo
Account information:
ACL information:
192.168.221.0/24
Target 2: iqn.2012-05.com.example:ex333server.target244
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00020000
SCSI SN: beaf20
Size: 0 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
LUN: 1
Type: disk
SCSI ID: IET 00020001
SCSI SN: beaf21
Size: 4 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/vg_iscsi/lv_iscsi_244
Account information:
ACL information:
192.168.221.244
[root@ex333server tgt]#
找台244的虚机当客户端测试下:
[root@localhost rules.d]# ifconfig bond0
bond0 Link encap:Ethernet HWaddr 00:0C:29:F7:5A:00
inet addr:192.168.221.244 Bcast:192.168.221.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fef7:5a00/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:11680 errors:0 dropped:0 overruns:0 frame:0
TX packets:6070 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6193467 (5.9 MiB) TX bytes:901920 (880.7 KiB)
yum install iscsi-initiator-utils.x86_64
service iscsi restart
chkconfig iscsi on
[root@localhost init.d]# iscsiadm --mode discovery --type sendtargets --portal 192.168.221.254
192.168.221.254:3260,1 iqn.2012-05.com.example:ex333server.demo
192.168.221.254:3260,1 iqn.2012-05.com.example:ex333server.target244
[root@localhost init.d]# iscsiadm --mode node --targetname iqn.2012-05.com.example:ex333server.target244 --portal 192.168.221.254:3260 --login
Logging in to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]
Login to [iface: default, target: iqn.2012-05.com.example:ex333server.target244, portal: 192.168.221.254,3260]: successful
[root@localhost init.d]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1330 10482412+ 83 Linux
/dev/sda3 1331 1591 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 4 MB, 4194304 bytes
1 heads, 8 sectors/track, 1024 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk /dev/sdb doesn't contain a valid partition table
可以看到4M的sdb已经挂载到本地了。
小贴士:
无论时iscsi客户端还是服务端,包装完后服务都没有启动,在使用前需先启动相关服务;
较长的几个命令可直接在man里找(man tgtd,man iscsiadm);
记不清包的具体名称可通过yum的搜索功能:yum search scsi。