Share volume between machines

共享存储卷在集群中应用广泛, 一般用作集群文件系统, 例如rhcs套件中间gfs.

但是如果不想使用集群文件系统的话, 同一时间不能同时被2台或者2台以上的系统挂载. 否则可能将文件系统破坏.

使用逻辑卷来管理是比较好的选择之一.

例如存储上划分了1个卷, 同时指派给2台主机.

在2台主机上都能看到这个存储卷.

例如 : 

A主机 :

[root@db-xxx-xxx-xxx-xxx ~]# multipath -ll
msa_60_vd01vol01 (3600c0ff000da60c23d8a375201000000) dm-3 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:4:1 sdh 8:112 [active][ready]
 \_ 1:0:4:1 sds 65:32 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:3:1 sdf 8:80  [active][ready]
 \_ 1:0:3:1 sdq 65:0  [active][ready]
msa_62_vd01vol01 (3600c0ff000da60e2f705385201000000) dm-5 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:6:1 sdk 8:160 [active][ready]
 \_ 1:0:6:1 sdv 65:80 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:5:1 sdj 8:144 [active][ready]
 \_ 1:0:5:1 sdu 65:64 [active][ready]
msa_58_vd01vol01 (3600c0ff000da61d7258a375201000000) dm-1 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:2:1 sdd 8:48  [active][ready]
 \_ 1:0:2:1 sdo 8:224 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:1:1 sdb 8:16  [active][ready]
 \_ 1:0:1:1 sdm 8:192 [active][ready]
msa_60_vd02vol01 (3600c0ff000da60ca488a375201000000) dm-4 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:3:2 sdg 8:96  [active][ready]
 \_ 1:0:3:2 sdr 65:16 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:4:2 sdi 8:128 [active][ready]
 \_ 1:0:4:2 sdt 65:48 [active][ready]
msa_58_vd02vol01 (3600c0ff000da6318358a375201000000) dm-2 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:1:2 sdc 8:32  [active][ready]
 \_ 1:0:1:2 sdn 8:208 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:2:2 sde 8:64  [active][ready]
 \_ 1:0:2:2 sdp 8:240 [active][ready]
msa_57_vd01vol01 (3600c0ff000da62c0be8d375201000000) dm-0 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:0:1 sda 8:0   [active][ready]
 \_ 1:0:0:1 sdl 8:176 [active][ready]

B主机 : 

[root@db-xxx-xxx-xxx-xxx ~]# multipath -ll
msa_60_vd01vol01 (3600c0ff000da60c23d8a375201000000) dm-3 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:4:1 sdh 8:112 [active][ready]
 \_ 1:0:4:1 sds 65:32 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:2:1 sdd 8:48  [active][ready]
 \_ 1:0:2:1 sdo 8:224 [active][ready]
msa_62_vd01vol01 (3600c0ff000da60e2f705385201000000) dm-5 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:5:1 sdj 8:144 [active][ready]
 \_ 1:0:6:1 sdv 65:80 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:6:1 sdk 8:160 [active][ready]
 \_ 1:0:5:1 sdu 65:64 [active][ready]
msa_58_vd01vol01 (3600c0ff000da61d7258a375201000000) dm-1 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:3:1 sdf 8:80  [active][ready]
 \_ 1:0:1:1 sdm 8:192 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:1:1 sdb 8:16  [active][ready]
 \_ 1:0:3:1 sdq 65:0  [active][ready]
msa_60_vd02vol01 (3600c0ff000da60ca488a375201000000) dm-4 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:2:2 sde 8:64  [active][ready]
 \_ 1:0:2:2 sdp 8:240 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:4:2 sdi 8:128 [active][ready]
 \_ 1:0:4:2 sdt 65:48 [active][ready]
msa_58_vd02vol01 (3600c0ff000da6318358a375201000000) dm-2 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:1:2 sdc 8:32  [active][ready]
 \_ 1:0:3:2 sdr 65:16 [active][ready]
\_ round-robin 0 [prio=20][enabled]
 \_ 0:0:3:2 sdg 8:96  [active][ready]
 \_ 1:0:1:2 sdn 8:208 [active][ready]
msa_57_vd01vol01 (3600c0ff000da62c0be8d375201000000) dm-0 HP,MSA2312fc
[size=1.4T][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=100][active]
 \_ 0:0:0:1 sda 8:0   [active][ready]
 \_ 1:0:0:1 sdl 8:176 [active][ready]

在A主机上创建pv, vg, lv. 并格式文件系统.

创建完后, 在B主机上扫描 :

pvscan
vgscan
lvscan

扫描完后可以看到创建的pv, vg, lv.

此时在B主机上, lv处于未激活状态 :

[root@db-xxx-xxx-xxx-xxx ~]# lvs
  LV   VG       Attr   LSize Origin Snap%  Move Log Copy%  Convert
  lv01 vgdata01 -wi--- 8.17T
[root@db-xxx-xxx-xxx-xxx ~]# ll /dev/mapper/vgdata01-lv01
ls: /dev/mapper/vgdata01-lv01: No such file or directory

而在A主机上, lv处于激活状态 : 

[root@db-xxx-xxx-xxx-xxx ~]# lvs
  LV   VG       Attr   LSize Origin Snap%  Move Log Copy%  Convert
  lv01 vgdata01 -wi-a- 8.17T
[root@db-xxx-xxx-xxx-xxx ~]# ll /dev/mapper/vgdata01-lv01
brw-rw---- 1 root disk 253, 6 Sep 17 08:29 /dev/mapper/vgdata01-lv01

在B主机上激活逻辑卷的命令, 激活后map device 被自动创建 : 

[root@db-xxx-xxx-xxx-xxx ~]# lvchange -ay vgdata01/lv01
[root@db-xxx-xxx-xxx-xxx ~]# ll /dev/mapper/vgdata01-lv01
brw-rw---- 1 root disk 253, 6 Sep 17 08:54 /dev/mapper/vgdata01-lv01

此时可以将A主机卸载, 

[root@db-A ~]# umount /dev/mapper/vgdata01-lv01 

然后在B主机挂载该文件系统 

[root@db-B ~]# mount /dev/mapper/vgdata01-lv01 /database1

在任意主机上创建的文件, 在另一主机挂载该卷后可以正常访问. 

[root@db-B database1]# date +%F%T >>./test
[root@db-B database1]# ll
total 20
drwx------ 2 root root 16384 Sep 17 08:29 lost+found
-rw-r--r-- 1 root root    19 Sep 17 08:57 test
[root@db-B database1]# cat test
2013-09-1708:57:22

将B卸载并冻结lv后, 在A挂载.

[root@db-B ~]# umount /database1
[root@db-B ~]# lvchange -an vgdata01/lv01
[root@db-A ~]# lvchange -ay vgdata01/lv01
[root@db-A ~]# mount /dev/mapper/vgdata01-lv01 /database
[root@db-A ~]# cd /database/
[root@db-A database]# ll
total 20
drwx------ 2 root root 16384 Sep 17 08:29 lost+found
-rw-r--r-- 1 root root    19 Sep 17 08:57 test
[root@db-A database]# cat test
2013-09-1708:57:22

[注意]

1. 对于不使用集群文件系统共享卷的情况, 请务必小心, 切忌不要同时挂载该文件系统.

2. 不建议使用fstab自动挂载这类文件系统. 同时确保只有一个系统中的lv处于激活状态, 避免误挂载.

[参考]

1. man lvs

              The lv_attr bits are:

              1  Volume  type:  (m)irrored, (M)irrored without initial sync, (o)rigin, (O)rigin with merging snapshot,
                 (s)napshot, merging (S)napshot, (p)vmove, (v)irtual,  mirror  (i)mage,  mirror  (I)mage  out-of-sync,
                 under (c)onversion

              2  Permissions: (w)riteable, (r)ead-only

              3  Allocation  policy:  (c)ontiguous,  c(l)ing, (n)ormal, (a)nywhere, (i)nherited This is capitalised if
                 the volume is currently locked against allocation changes, for example during pvmove (8).

              4  fixed (m)inor

              5  State: (a)ctive, (s)uspended, (I)nvalid  snapshot,  invalid  (S)uspended  snapshot,  mapped  (d)evice
                 present without tables, mapped device present with (i)nactive table

              6  device (o)pen
时间: 2024-09-20 09:06:12

Share volume between machines的相关文章

bigtable: A Distributed Storage System for Structured Data

bigtable: A Distributed Storage System for Structured Data http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en//archive/bigtable-osdi06.pdf http://www.dbthink.com/?p=493, 中文翻译   总结 A Bigtable is a sparse, distri

谈谈 Docker Volume 之权限管理(一)

Volume数据卷是Docker的一个重要概念.数据卷是可供一个或多个容器使用的特殊目录,可以为容器应用存储提供有价值的特性: 持久化数据与容器的生命周期解耦:在容器删除之后数据卷中的内容可以保持.Docker 1.9之后引进的named volume(命名文件卷)可以更加方便地管理数据卷的生命周期:数据卷可以被独立地创建和删除. 数据卷可以用于实现容器之间的数据共享 可以支持不同类型的数据存储实现 Docker缺省提供了对宿主机本地文件卷的支持,可以将宿主机的目录挂载到容器之中.由于没有容器分

Windows 8 Store Apps学习(39) 契约: Share Contract

介绍 重新想象 Windows 8 Store Apps 之 契约 Share Contract - 右侧边栏称之为 Charm,其 中的"共享"称之为 Share Contract 示例 1.演示如何开发共享源 Contracts/ShareContract/ShareSource.xaml <Page x:Class="XamlDemo.Contracts.ShareContract.ShareSource" xmlns="http://sche

Get Volume Serial Number in C#

Recently somebody asked how to get the Hard Drive serial number in VB.NET. The easy answer of course is to use VBScript with the WMI classes. Actually, this gets the "Volume" serial number, not the hard-coded manufacturer's hard drive serial num

How to Share Session State Between Classic ASP and ASP.NET(2)

asp.net|session ASP ImplementationThe native ASP session can only store session data in memory. In order to store the session data to SQL Server, a custom Microsoft Visual Basic 6.0 COM object is written to manage the session state instead of using t

How to Share Session State Between Classic ASP and ASP.NET(1)

asp.net|session Applies to:   Microsoft ASP.NET Summary: Discusses how to share session state between classic ASP and Microsoft ASP.NET using Microsoft .NET Framework classes and the serialization feature of the .NET Framework. Sharing session state

DOS的Setver、Share、Subst命令使用说明

setver:设置版本 [适用场合] 当希望使用其它版本的dos命令时可以用它来欺骗电脑.在高版本dos中,某些旧版本程序需要dos3.3时,可用setver来设置 [用法] 使用时一般在config.sys中加入 device=setver.exe setver 显示文件的版本 setver [文件名] n.nn 设置指定文件的版本号 [例子] C:\dos>setver KERNEL.EXE 5.00 dosOAD.SYS 5.00 EDLIN.EXE 5.00 BACKUP.EXE 5.0

取得Disk Volume Information

Private Declare Function GetVolumeInformation Lib "kernel32" _ Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, _ ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _ lpVolumeSerialNumber As Long, lpMaximu

Mixer Volume Ctrler V1.0

Dos 下的声卡音量控制程序,以内存驻留键盘激活的方式控制CD-Audio,MIDI,Voice以及Master的音量(未作键盘的解封锁处理,有兴趣可加上) CTRL-F1 -- TURN MASTER VOL UP CTRL-F2 -- TURN MASTER VOL DOWN CTRL-F3 -- TURN CD VOL UP CTRL-F4 -- TURN CD VOL DOWN CTRL-F5 -- TURN FM VOL UP CTRL-F6 -- TURN FM VOL DOWN C