分类: LINUX
2009-10-11 22:37:12
多路径实验
实验目标:通过iscsi建立多路径模拟环境,并检测其性能,从而理解多路径原理以及应用
实验环境:通过iscsi建立到同一个网络磁盘的两条路径,RH5.3
实验主要步骤:
l 通过YUM安装iscsi-initiator-utils 以及scsi-target-utils
l 在服务器
1. 启动tgt服务,创建iscsi目标
2. 在本地创建作为iscsi磁盘的设备(以文件的方式如/tmp/baonii.img)
3. 将本地设备(/tmp/baonii.img)与iscsi目标捆绑起来
4. 检查网络服务,虚拟两个网卡,为后面创建多路径使用
l 在客户端
1. 查询目标地址是否有iscsi设备
2. 如果发现,利用某个端口注册该设备
3. 利用另外一个目标地址查询iscsi设备
4. 利用某个端口注册该设备
5. 启动多路径服务
l 通过客户端为iscsi创建文件系统,进行数据读写,检测多路径性能
实验过程以及截图:
首先要安装iscsi的相关包iscsi-initiator-utils 以及scsi-target-utils,使用yum方式。
在本地创建repo,其中/tmp/repo下的是光盘镜像/Service拷贝过来的(原来光盘中已经包含了repodata),并且repo的信息文件如下
[root@localhost repo]# vi /etc/yum.repos.d/baonii.repo
[rhel-Server]
name=Server
baseurl=file:///tmp/repo
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
但是当我执行yum install scsi-target-utils的时候找不到对应的包,后来发现原来这个包是放在clusterStorage文件夹下,所以这里有两个解决的方法,其中一个就是在repo信息文件中添加另一个路径;还有就是在clusterStorage上一级目录中创建repo,同时需要修改repo信息文件。
下面开始安装initiator以及target包
[root@localhost repo]# yum install iscsi-initiator-utils scsi-target-utils
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
No package scsi-target-utils available.
Resolving Dependencies
--> Running transaction check
---> Package iscsi-initiator-utils.i386 0:6.2.0.868-0.18.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
iscsi-initiator-utils i386 6.2.0.868-0.18.el5 rhel-Server 566 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 566 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : iscsi-initiator-utils [1/1]
Installed: iscsi-initiator-utils.i386 0:6.2.0.868-0.18.el5
Complete!
下面在服务器,开启tgtd服务,建立iscsi磁盘
Last login: Tue Sep 15 11:14:26 2009
[root@localhost ~]# service tgtd start
Starting SCSI target daemon: [ OK ]
[root@localhost ~]# tgtadm --lld iscsi --op show --mode target
[root@localhost ~]# tgtadm --lld iscsi --op new --mode target --tid=1 --targetname hi
[root@localhost ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /tmp/baonii.img
[root@localhost ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
[root@localhost ~]# tgtadm --lld iscsi --op show --mode target
Target 1: hi
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store: No backing store
LUN: 1
Type: disk
SCSI ID: deadbeaf1:1
SCSI SN: beaf11
Size: 1075 MB
Online: Yes
Removable media: No
Backing store: /tmp/baonii.img
Account information:
ACL information:
ALL
另外由于要创建两条通路,所以还需要在服务器虚拟出两个网卡,以便客户端连接,
[root@localhost /]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:6B:59:E0
inet addr:192.168.1.77 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe6b:59e0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16571 errors:0 dropped:0 overruns:0 frame:0
TX packets:12586 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1142487 (1.0 MiB) TX bytes:1634244 (1.5 MiB)
Interrupt:193 Base address:0x2000
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:6B:59:E0
inet addr:192.168.1.88 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:193 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:247 errors:0 dropped:0 overruns:0 frame:0
TX packets:247 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:30885 (30.1 KiB) TX bytes:30885 (30.1 KiB)
对于客户器端
开启iscsi服务
[root@localhost /]# /etc/init.d/iscsid start
Turning off network shutdown. Starting iSCSI daemon:
[ OK ]
然后用服务器的两个地址在本地建立iscsi设备,实现多路径环境
[root@localhost ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.77
192.168.1.77:3260,1 hi
[root@localhost ~]# iscsiadm --mode node --targetname hi --portal 192.168.1.77:3260 --login
Logging in to [iface: default, target: hi, portal: 192.168.1.77,3260]
Login to [iface: default, target: hi, portal: 192.168.1.77,3260]: successful
[root@localhost ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.88
192.168.1.88:3260,1 hi
[root@localhost ~]# iscsiadm --mode node --targetname hi --portal 192.168.1.88:3260 --login
Logging in to [iface: default, target: hi, portal: 192.168.1.88,3260]
Login to [iface: default, target: hi, portal: 192.168.1.88,3260]: successful
启动multipath服务
[root@localhost ~]# service multipathd start
Starting multipathd daemon: [ OK ]
[root@localhost ~]# multipath -ll -v3
dm-0: blacklisted
fd0: blacklisted
hda: blacklisted
md0: blacklisted
ram0: blacklisted
ram10: blacklisted
ram11: blacklisted
ram12: blacklisted
ram13: blacklisted
ram14: blacklisted
ram15: blacklisted
ram1: blacklisted
ram2: blacklisted
ram3: blacklisted
ram4: blacklisted
ram5: blacklisted
ram6: blacklisted
ram7: blacklisted
ram8: blacklisted
ram9: blacklisted
sda: not found in pathvec
sda: mask = 0x5
sda: bus = 1
sda: dev_t = 8:0
sda: size = 312581808
sda: vendor = ATA
sda: product = Hitachi HDS72161
sda: rev = P22O
sda: h:b:t:l = 0:0:0:0
sda: path checker = readsector0 (config file default)
sda: state = 2
sdb: not found in pathvec
sdb: mask = 0x5
sdb: bus = 1
sdb: dev_t = 8:16
sdb: size = 2099200
sdb: vendor = IET
sdb: product = VIRTUAL-DISK
sdb: rev = 0001
sdb: h:b:t:l = 2:0:0:1
sdb: path checker = readsector0 (config file default)
sdb: state = 2
sdc: not found in pathvec
sdc: mask = 0x5
sdc: bus = 1
sdc: dev_t = 8:32
sdc: size = 2099200
sdc: vendor = IET
sdc: product = VIRTUAL-DISK
sdc: rev = 0001
sdc: h:b:t:l = 3:0:0:1
sdc: path checker = readsector0 (config file default)
sdc: state = 2
===== paths list =====
uuid hcil dev dev_t pri dm_st chk_st vend/prod/rev
0:0:0:0 sda 8:0 0 [undef][ready] ATA,Hitachi HDS72161
2:0:0:1 sdb 8:16 0 [undef][ready] IET,VIRTUAL-DISK
3:0:0:1 sdc 8:32 0 [undef][ready] IET,VIRTUAL-DISK
params = 0 0 2 1 round-robin 0 1 1 8:32 1000 round-robin 0 1 1 8:16 1000
status = 2 0 0 0 2 1 E 0 1 0 8:32 A 0 E 0 1 0 8:16 A 0
sdc: mask = 0x8
sdc: getprio = NULL (internal default)
sdc: prio = 1
sdb: mask = 0x8
sdb: getprio = NULL (internal default)
sdb: prio = 1
mpath1 (S_beaf11) dm-0 IET,VIRTUAL-DISK
[size=1.0G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=1][enabled]
\_ 3:0:0:1 sdc 8:32 [active][ready]
\_ round-robin 0 [prio=1][enabled]
\_ 2:0:0:1 sdb 8:16 [active][ready]
通过上面的命令可以看到多路径设备/dev/dm-0有两条通路,并且都是连通的
[root@localhost ~]# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1318 10482412+ 83 Linux
/dev/sda3 1319 1383 522112+ 82 Linux swap / Solaris
/dev/sda4 1384 19457 145179405 5 Extended
/dev/sda5 1384 1757 3004123+ 83 Linux
Disk /dev/sdb: 1074 MB, 1074790400 bytes
34 heads, 61 sectors/track, 1012 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/dm-0: 1074 MB, 1074790400 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/dm-0 doesn't contain a valid partition table
下面开始对多路径设备进行操作,首先就是建立文件系统,然后在上面进行IO操作
[root@localhost ~]# mount /dev/dm-0 /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# dd if=/dev/zero of=/mnt/baonii.img
开始检测性能:
当有两条通路的时候,进行大约1G的IO操作,速度为9.9 MB/s
\_ round-robin 0 [prio=1][enabled]
\_ 3:0:0:1 sdc 8:32 [active][ready]
\_ round-robin 0 [prio=1][active]
\_ 2:0:0:1 sdb 8:16 [active][ready]
[root@localhost /]# dd if=/dev/zero of=/mnt/baonii,img
dd: writing to `/mnt/baonii,img': No space left on device
1993969+0 records in
1993968+0 records out
1020911616 bytes (1.0 GB) copied, 102.995 seconds, 9.9 MB/s
当只有一条通路的时候,速度为9.6 MB/s
[root@localhost /]# dd if=/dev/zero of=/mnt/baonii,img
dd: writing to `/mnt/baonii,img': No space left on device
1993721+0 records in
1993720+0 records out
1020784640 bytes (1.0 GB) copied, 106.54 seconds, 9.6 MB/s
sdc: checker msg is "readsector0 checker reports path is down"
===== paths list =====
uuid hcil dev dev_t pri dm_st chk_st vend/prod/rev
0:0:0:0 sda 8:0 0 [undef][ready] ATA,Hitachi HDS72161
2:0:0:1 sdb 8:16 0 [undef][ready] IET,VIRTUAL-DISK
3:0:0:1 sdc 8:32 0 [undef][faulty] IET,VIRTUAL-DISK
params = 0 0 2 1 round-robin 0 1 1 8:32 1000 round-robin 0 1 1 8:16 1000
status = 2 0 0 0 2 1 E 0 1 0 8:32 F 1 E 0 1 0 8:16 A 1
sdc: mask = 0x8
sdb: mask = 0x8
sdb: getprio = NULL (internal default)
sdb: prio = 1
mpath1 (S_beaf11) dm-0 IET,VIRTUAL-DISK
[size=1.0G][features=0][hwhandler=0][rw]
\_ round-robin 0 [prio=0][enabled]
\_ 3:0:0:1 sdc 8:32 [failed][faulty]
\_ round-robin 0 [prio=1][enabled]
\_ 2:0:0:1 sdb 8:16 [active][ready]
从上面的数据可以看出来,有两条路径的时候比只有一条路径的IO读写速率要快,这还比较容易理解,但是为什么速度不是两倍的关系呢,这可能是因为这种多路径环境是建立的网络上的,所以网路的IO流量是一个很大的瓶颈。
实验总结:
由于这个实验首先使用secureCRT远程登陆到服务器进行操作的,并且使用的网段是10.66.这个是公司的无线网络,所以老师说这会严重影响多路径的效果,建议使用实际的物理连接。但是在使用网线进行连接的时候发现很多奇怪的问题,这里总结一下:当你的虚拟机不能和host进行连接的时候,首先要检查他们是否在同一个网段,然后,看看时候使用的桥接(他们说桥接方式就是在电脑里面虚拟出一个看起来和本地连接地位等同的网络接口,知道,这里说的是接口而不是设备VM0,这个VM0在网络连接那里是看不到的,而VM1和VM8是没有用的,另外注意在VM0桥接方式里有物理,无线以及自适应的选项,当然由于现在用的是网线,所以需要选择物理连接)。
另外,注意到在服务器供应出来的是一个文件/tmp/baonii.img,但是在客户端用iscsi去发现的时候,但是的是一个设备(分区)。所以在客户端还需要进行创建文件系统。这里又加深了我对san以及nas的理解,老师说,nas在管理storage时候,实质是通过nfs服务去访问文件的,storage就是nfs服务器的存储,而san在以前使用scsi对存储进行访问的(个人觉得这个scsi的协议应该是比较低级的,就是像本地访问一样,通常采用的介质是光线,而到了后来,发现通过使用iscsi也能达到同样的效果。所以在nas上,看到的storage是文件夹(已经建立文件系统的),而在san上看到是一个分区。