============================================================
虚拟机环境下共享磁盘的实现方法 之 Startwind(一)
-by 王磊/菜小小~@2012/4/22 23:56
============================================================
很多采用虚拟机进行Oracle RAC试验的童鞋,在搭建共享存储这块主要有以下几种方式:
1、使用Vmware 虚拟机或者 VirtualBox 虚拟机自带功能实现;
2、使用Openfiler或者FreeNAS这样的免费开源系统搭建网络存储服务器;
3、使用StarWind 等软件基于Windows的software iscsi模拟软件;
本文主要描述Red Hat Enterprise Linux 6环境 iscsi设备的配置过程,关于StarWind 软件的安装及配置请参考以下文章
Startwind的安装与配置参看:http://plaway.blog.51cto.com/872211/234873
安装iscsi的rpm包-在RAC两节点运行
[22:18:45root@rhel6_1 ~]>rpm -qa |grep iscsi
[22:19:06root@rhel6_1 ~]>yum search iscsi
Loaded plugins: product-id, subscription-manager
Updating Red Hat repositories.
Server | 4.0 kB 00:00 ...
dvd | 4.0 kB 00:00 ...
============================= N/S Matched: iscsi ==============================
iscsi-initiator-utils.x86_64 : iSCSI daemon and utility programs
Name and summary matches only, use "search all" for everything.
[22:19:20root@rhel6_1 ~]>yum install iscsi-initiator-utils
Loaded plugins: product-id, subscription-manager
Updating Red Hat repositories.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
iscsi-initiator-utils x86_64 6.2.0.872-21.el6 Server 579 k
Transaction Summary
===============================================================================
Install 1 Package(s)
Total download size: 579 k
Installed size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : iscsi-initiator-utils-6.2.0.872-21.el6.x86_64 1/1
duration: 711(ms)
Installed products updated.
Installed:
iscsi-initiator-utils.x86_64 0:6.2.0.872-21.el6
Complete!
/etc/iscsi/initiatorname.iscsi配置文件描述了该节点在iscsi服务端表现出来的名字
[22:49:31root@rhel6_1 iscsi]>cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:27c25c5214bb
为便于识别,我将其做了修改
[23:17:32root@rhel6_1 ~]>cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:rhel6_1-RAC11gR2-node1
发现设备并挂载设备-在RAC两节点运行
探测主机server运行的共享存储标识target
[22:49:32root@rhel6_1 iscsi]>iscsiadm -m discovery -t sendtargets -p 192.168.100.7:3260
192.168.100.7:3260,-1 rac11gr2-a-1g
192.168.100.7:3260,-1 rac11gr2-b-2g
192.168.100.7:3260,-1 rac11gr2-c-2g
这里发现了我们事先创建好的存储,下面我们使用iscsi挂载磁盘。
通过iscsi挂载磁盘-在RAC两节点运行
[22:52:22root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-a-1g -p 192.168.100.7:3260 -l
Logging in to [iface: default, target: rac11gr2-a-1g, portal: 192.168.100.7,3260]
Login to [iface: default, target: rac11gr2-a-1g, portal: 192.168.100.7,3260] successful.
[22:53:04root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-b-2g -p 192.168.100.7:3260 -l
Logging in to [iface: default, target: rac11gr2-b-2g, portal: 192.168.100.7,3260]
Login to [iface: default, target: rac11gr2-b-2g, portal: 192.168.100.7,3260] successful.
[22:53:09root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-c-2g -p 192.168.100.7:3260 -l
Logging in to [iface: default, target: rac11gr2-c-2g, portal: 192.168.100.7,3260]
Login to [iface: default, target: rac11gr2-c-2g, portal: 192.168.100.7,3260] successful.
查看挂载状态
[22:53:14root@rhel6_1 iscsi]>service iscsi status
Target: rac11gr2-a-1g
Current Portal: 192.168.100.7:3260,1
Persistent Portal: 192.168.100.7:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:27c25c5214bb
Iface IPaddress: 192.168.100.21
Iface HWaddress:
Iface Netdev:
SID: 2
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 262144
FirstBurstLength: 262144
MaxBurstLength: 262144
ImmediateData: Yes
InitialR2T: No
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 5 State: running
scsi5 Channel 00 Id 0 Lun: 0
Attached scsi disk sdj State: running
Target: rac11gr2-b-2g
Current Portal: 192.168.100.7:3260,1
Persistent Portal: 192.168.100.7:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:27c25c5214bb
Iface IPaddress: 192.168.100.21
Iface HWaddress:
Iface Netdev:
SID: 3
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 262144
FirstBurstLength: 262144
MaxBurstLength: 262144
ImmediateData: Yes
InitialR2T: No
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 6 State: running
scsi6 Channel 00 Id 0 Lun: 0
Attached scsi disk sdk State: running
Target: rac11gr2-c-2g
Current Portal: 192.168.100.7:3260,1
Persistent Portal: 192.168.100.7:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:27c25c5214bb
Iface IPaddress: 192.168.100.21
Iface HWaddress:
Iface Netdev:
SID: 4
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 262144
FirstBurstLength: 262144
MaxBurstLength: 262144
ImmediateData: Yes
InitialR2T: No
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 7 State: running
scsi7 Channel 00 Id 0 Lun: 0
Attached scsi disk sdl State: running
同时,通过StartWind console也能看到当前连接情况
连接前:
卸载设备
[23:06:27root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-a-1g -p 192.168.100.7:3260 --logout
Logging out of session [sid: 2, target: rac11gr2-a-1g, portal: 192.168.100.7,3260]
Logout of [sid: 2, target: rac11gr2-a-1g, portal: 192.168.100.7,3260] successful.
[23:06:41root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-b-2g -p 192.168.100.7:3260 --logout
Logging out of session [sid: 3, target: rac11gr2-b-2g, portal: 192.168.100.7,3260]
Logout of [sid: 3, target: rac11gr2-b-2g, portal: 192.168.100.7,3260] successful.
[23:06:49root@rhel6_1 iscsi]>iscsiadm -m node -T rac11gr2-c-2g -p 192.168.100.7:3260 --logout
Logging out of session [sid: 4, target: rac11gr2-c-2g, portal: 192.168.100.7,3260]
Logout of [sid: 4, target: rac11gr2-c-2g, portal: 192.168.100.7,3260] successful.
[23:06:53root@rhel6_1 iscsi]>service iscsi status
No active sessions
分区--在RAC其中一个节点运行即可
[23:32:18root@rhel6_1 ~]>fdisk /dev/sde
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').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1011, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011):
Using default value 1011
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[23:32:28root@rhel6_1 ~]>fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x426e7c8b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1009, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009):
Using default value 1009
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[23:32:52root@rhel6_1 ~]>fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4a5e0611.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1009, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009):
Using default value 1009
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
配置raw-在RAC两节点运行
[23:34:22root@rhel6_1 ~]>cat /etc/udev/rules.d/60-raw.rules
# This file and interface are deprecated.
# Applications needing raw device access should open regular
# block devices with O_DIRECT.
#
# Enter raw device bindings here.
#
# An example would be:
# ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"
# to bind /dev/raw/raw1 to /dev/sda, or
# ACTION=="add", ENV{MAJOR}=="8", ENV{MINOR}=="1", RUN+="/bin/raw /dev/raw/raw2 %M %m"
# to bind /dev/raw/raw2 to the device with major 8, minor 1.
ACTION=="add",KERNEL=="sde1",RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add",KERNEL=="sdf1",RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add",KERNEL=="sdg1",RUN+="/bin/raw /dev/raw/raw3 %N"
KERNEL=="raw[1-3]", OWNER="ora11", GROUP="oinstall", MODE="660"
[23:34:27root@rhel6_1 ~]>start_udev
Starting udev: [ OK ]
[23:34:56root@rhel6_1 ~]>ls -l /dev/raw
total 0
crw-rw---- 1 ora11 oinstall 162, 1 Apr 22 23:34 raw1
crw-rw---- 1 ora11 oinstall 162, 2 Apr 22 23:34 raw2
crw-rw---- 1 ora11 oinstall 162, 3 Apr 22 23:34 raw3
crw-rw---- 1 root disk 162, 0 Apr 22 23:34 rawctl
[23:35:00root@rhel6_1 ~]>raw -qa
/dev/raw/raw1: bound to major 8, minor 65
/dev/raw/raw2: bound to major 8, minor 81
/dev/raw/raw3: bound to major 8, minor 97
至此,搭建rac环境所需的raw存储设备已配置完毕。
常用命令
发现target,以下命令将返回target名称
iscsiadm -m discovery -t sendtargets -p target IP地址:端口号
得到了target名称后,使用下面命令建立连接
iscsiadm -m node -T target名称 -p targetIP地址:端口号 --login
这时应该看到映射到的逻辑磁盘名号,使用fdisk -l 可以看到有关逻辑磁盘的详细内容,可以象使用本地硬盘一样对其进行分区、创建文件系统、挂载、卸载等操作。
使用下面命令断开连接,注意:如果逻辑磁盘已经挂载,断开连接前应先卸载
iscsiadm -m node -T target名称 -p targetIP地址:端口号 --logout
关机之前应该正确的卸载和断开逻辑磁盘,否则会在target服务器上留下僵死的进程,造成服务器资源的浪费。
参考:http://www.qidunet.com/index.php/archives/300
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21162451/viewspace-721993/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21162451/viewspace-721993/