4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ひとつのVMでGlusterfsのquotaとsnapshot機能を試してみました

Posted at

一つのVMに、GlusterFSのQuotaとSnapshot機能を試しました、その記録を残しておきたいと思っています。

実験環境:

  • Vagrant 1.8.1
  • VirtualBox 5.0.20r106931
  • GlusterFS 3.7

Vagrantfile

まずは新しいハードディスクを作っておきます:

  config.vm.provider :virtualbox do |vb|
    file_to_disk = "#{ENV["HOME"]}/glusterfs.vdi"
    unless File.exist?(file_to_disk)
      vb.customize ['createmedium', 'disk', '--filename', file_to_disk, '--format', 'VDI', '--size', 10 * 1024]
      vb.customize ['storageattach', :id,
        '--storagectl', 'IDE Controller',
        '--port', 1,
        '--device', 0,
        '--type', 'hdd',
        '--medium', file_to_disk]
    end
  end

上記の設定は環境に依存するため、自分の環境に合わせて作ってください。

詳しいのは VagrantのVMに複数のディスクを追加する方法 をご参照してください。

Install Glusterfs

ウェブ上に情報が多いですので、ここで省略。

Create LVM Volume

/dev/sdb があるのを確認:

[vagrant@g1 ~]$ ls /dev/sd
sda   sda1  sda2  sda3  sdb   

parted で新しいパティションを作ろう。感じんのは lvm on で、Snapshot 機能を使うために必須。

[vagrant@g1 ~]$ sudo parted -s -a optimal /dev/sdb mklabel msdos -- mkpart primary 1 -1 set 1 lvm on

/dev/sdb1 を確認:

[vagrant@g1 ~]$ ls /dev/sd
sda   sda1  sda2  sda3  sdb   sdb1  

物理ボリューム(pv)とボリュームグループ(vg)を作成:

[vagrant@g1 ~]$ sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

[vagrant@g1 ~]$ sudo vgcreate vg0 /dev/sdb1
  Volume group "vg0" successfully created

thinpool を作成(名前は thinp ):

[vagrant@g1 ~]$ sudo lvcreate --thin -L 1G vg0/thinp
  Logical volume "thinp" created.

thinp に基づいてボリューム data を作成して、 mkfs.xfs でファイルシステムを作ります:

[vagrant@g1 ~]$ sudo lvcreate --thin -V 1G -n data vg0/thinp
  Logical volume "data" created.


[vagrant@g1 ~]$ sudo mkfs.xfs /dev/vg0/data 
meta-data=/dev/vg0/data          isize=256    agcount=8, agsize=32752 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=262016, imaxpct=25
         =                       sunit=16     swidth=16 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=768, version=2
         =                       sectsz=512   sunit=16 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

LVM volume /dev/vg0/data をロカールにmountします:

[vagrant@g1 ~]$ sudo mkdir -p /gfs/data
[vagrant@g1 ~]$ sudo mount /dev/vg0/data /gfs/data

これで、 LVM の Thinpool Volume をロカールホストにアクセスできるようになりました。

Create Glusterfs Volume

これからGlusterfsの Volume を作成し、ロカールに mount します:

[vagrant@g1 ~]$ sudo gluster volume create vol-liubin g1:/gfs/data/vol-liubin
volume create: vol-liubin: success: please start the volume to access data
[vagrant@g1 ~]$ sudo gluster volume start vol-liubin
volume start: vol-liubin: success

[vagrant@g1 ~]$ sudo mkdir -p /gfs-client/vol-liubin
[vagrant@g1 ~]$ sudo mount -t glusterfs g1:/vol-liubin /gfs-client/vol-liubin

ロカールに mount したフォルダに、いくつのファイルを作成します。

[vagrant@g1 ~]$ sudo mkdir /gfs-client/vol-liubin/some

[vagrant@g1 ~]$ cd /gfs-client/vol-liubin/

[vagrant@g1 vol-liubin]$ sudo touch aa.txt
[vagrant@g1 vol-liubin]$ sudo touch bbb.txt
[vagrant@g1 vol-liubin]$ ls
aa.txt  bbb.txt  some

Create Snapshot and Restore Snapshot

Snapshot を作成します。no-timestamp オプションをつけないと、 Snapshot 名にタイムスタンプが自動に追加されます。

[vagrant@g1 vol-liubin]$ sudo gluster snapshot create ss-1 vol-liubin
snapshot create: success: Snap ss-1_GMT-2016.07.13-06.52.44 created successfully


[vagrant@g1 vol-liubin]$ sudo gluster snapshot list
ss-1_GMT-2016.07.13-06.52.44

[vagrant@g1 vol-liubin]$ sudo gluster snapshot create ss-2 vol-liubin no-timestamp
snapshot create: success: Snap ss-2 created successfully

Snapshot の詳細も見られます:

[vagrant@g1 vol-liubin]$ sudo gluster snapshot info ss-2
Snapshot                  : ss-2
Snap UUID                 : 2424720e-e80c-49f9-94d6-4730f1fef5a3
Created                   : 2016-07-13 06:54:23
Snap Volumes:

	Snap Volume Name          : 22b9a1f21bbb40eeabb34665f110cf98
	Origin Volume name        : vol-liubin
	Snaps taken for vol-liubin      : 2
	Snaps available for vol-liubin  : 254
	Status                    : Stopped
 

Snapshot ss-2 をとった後、新しいファイル ccc.txt を作成し、Volume を umount してから、停止します:

# create a new file
[vagrant@g1 vol-liubin]$ sudo touch ccc.txt

# umount

[vagrant@g1 vol-liubin]$ cd
[vagrant@g1 ~]$ sudo umount g1:/vol-liubin



# stop volume

[vagrant@g1 ~]$ sudo gluster volume stop vol-liubin
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: vol-liubin: success

ss-2 をVolume vol-liubin に Restore します:

[vagrant@g1 ~]$ sudo gluster snapshot restore ss-2
Restore operation will replace the original volume with the snapshotted volume. Do you still want to continue? (y/n) y
Snapshot restore: ss-2: Snap restored successfully

再び vol-liubin を開始しmountします:

[vagrant@g1 ~]$ sudo gluster volume start vol-liubin
volume start: vol-liubin: success

[vagrant@g1 ~]$ sudo mount -t glusterfs g1:/vol-liubin /gfs-client/vol-liubin

ss-2 は古いSnapshotのため、 ccc.txt がないことを確認できるはずです。

[vagrant@g1 ~]$ ls /gfs-client/vol-liubin/
aa.txt  bbb.txt  some

注意:Snapshot 機能を利用するには、THIN の LVM を使うのが前提です:

$ sudo gluster snapshot create ss-4 vol-3
snapshot create: failed: Snapshot is supported only for thin provisioned LV. Ensure that all bricks of vol-3 are thinly provisioned LV.
Snapshot command failed

オフィシャルのマニュアルによると:

GlusterFS volume snapshot feature is based on thinly provisioned LVM snapshot. To make use of snapshot feature GlusterFS volume should fulfill following pre-requisites:

Each brick should be on an independent thin provisioned LVM.
Brick LVM should not contain any other data other than brick.
None of the brick should be on a thick LVM.
gluster version should be 3.6 and above.

Glusterfs Volume Quota

次は Quota 機能を試します。

まずは、Volume 別に quota 機能を有効にしなければなりまぜん。

[vagrant@g1 vol-liubin]$ sudo gluster volume quota vol-liubin enable
volume quota : success

次、容量は 10MB に制限します。list コマンドはVolumeの制限リストを表示します:

[vagrant@g1 vol-liubin]$ sudo gluster volume quota vol-liubin limit-usage / 10MB
volume quota : success

[vagrant@g1 vol-liubin]$ sudo gluster volume quota vol-liubin list
                  Path                   Hard-limit  Soft-limit      Used  Available  Soft-limit exceeded? Hard-limit exceeded?
-------------------------------------------------------------------------------------------------------------------------------
/                                         10.0MB     80%(8.0MB)    1.0KB  10.0MB              No                   No

テスト用のファイル(gs.rmp、1.45MB)いくつを vol-liubin にコーピーします:


[vagrant@g1 vol-liubin]$ cd 
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/
[vagrant@g1 ~]$ sudo gluster volume quota vol-liubin list
                  Path                   Hard-limit  Soft-limit      Used  Available  Soft-limit exceeded? Hard-limit exceeded?
-------------------------------------------------------------------------------------------------------------------------------
/                                         10.0MB     80%(8.0MB)    1.4MB   8.6MB              No                   No
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/1
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/2
[vagrant@g1 ~]$ sudo gluster volume quota vol-liubin list
                  Path                   Hard-limit  Soft-limit      Used  Available  Soft-limit exceeded? Hard-limit exceeded?
-------------------------------------------------------------------------------------------------------------------------------
/                                         10.0MB     80%(8.0MB)    4.2MB   5.8MB              No                   No
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/3
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/4
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/5
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/6
[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/7
[vagrant@g1 ~]$ sudo gluster volume quota vol-liubin list
                  Path                   Hard-limit  Soft-limit      Used  Available  Soft-limit exceeded? Hard-limit exceeded?
-------------------------------------------------------------------------------------------------------------------------------
/                                         10.0MB     80%(8.0MB)   11.1MB  0Bytes             Yes                  Yes



[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/8
[vagrant@g1 ~]$ sudo gluster volume quota vol-liubin list
                  Path                   Hard-limit  Soft-limit      Used  Available  Soft-limit exceeded? Hard-limit exceeded?
-------------------------------------------------------------------------------------------------------------------------------
/                                         10.0MB     80%(8.0MB)   12.5MB  0Bytes             Yes                  Yes

7 番目のファイルをコーピーした時点ですでに容量制限を超えましたが、8 番目のファイルもコーピーし成功しました。

原因はわかりません。

続けてファイルをコーピーします。今回はエラーになりました。


[vagrant@g1 ~]$ sudo cp gs.rmp /gfs-client/vol-liubin/some/9
cp: cannot create regular file '/gfs-client/vol-liubin/some/9': Disk quota exceeded
[vagrant@g1 ~]$ 

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?