How to restrict Gluster mount access to Directories ?

In this article I am going to show you that how to mount the directories inside the volume on client. I am having one replicated volume with name RepVol1 and having one directory inside the volume named Dir1

Step 1 : I am setting the nfs-export-dirs option on volume to true. After enabling it you can check the same with info command.

[root@Node2 ~]# gluster vol set RepVol1 nfs.export-dirs true
volume set: success

[root@Node2 ~]# gluster vol info RepVol1

Volume Name: RepVol1
Type: Replicate
Volume ID: 213ab453-e730-4644-9aaa-147b9dba9252
Status: Started
Snap Volume: no
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: Node1:/Replicated/RepBrickNode1
Brick2: Node2:/Replicated/RepBrickNode2
Options Reconfigured:
nfs.export-dirs: true
performance.readdir-ahead: on
auto-delete: disable
snap-max-soft-limit: 90
snap-max-hard-limit: 256

Step 2 : After doing it I am trying to mount the Dir1 inside the volume RepVol1 on client side.

[root@client1 ~]# mount -t nfs Node1:/RepVol1/Dir1 /mnt
[root@client1 ~]# df -h /mnt/
Filesystem           Size  Used Avail Use% Mounted on
Node1:/RepVol1/Dir1 1014M   32M  982M   4% /mnt

If you have already mounted volume it will get disappear after mounting the directory.

Step 3 : If you going to unmount the mounted directory you can get your original volume back. Like I have got it.

[root@client1 ~]# umount /mnt

[root@client1 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   11G  1.3G  9.1G  12% /
devtmpfs               927M     0  927M   0% /dev
tmpfs                  934M     0  934M   0% /dev/shm
tmpfs                  934M  2.2M  932M   1% /run
tmpfs                  934M     0  934M   0% /sys/fs/cgroup
/dev/sda1              484M   93M  392M  20% /boot
Node1:/RepVol1        1014M   32M  982M   4% /ReplicatedVol1

Step 4 : I have created one more directory inside the Volume for the further exercise.

[root@client1 ~]# cd /ReplicatedVol1/
[root@client1 ReplicatedVol1]# mkdir Dir2
[root@client1 ReplicatedVol1]# ll
total 0
drwxr-xr-x 2 root root 24 Dec 24 14:52 Dir1
drwxr-xr-x 2 root root  6 Dec 24 15:01 Dir2

[root@client1 ReplicatedVol1]# cd Dir2/
[root@client1 Dir2]# touch newfile1

Step 5 : I am going to turn off the mount volume option off. That will help If in case you don’t want to mount the original volume only want to mount the directory inside the volume.

[root@Node2 ~]# gluster vol set RepVol1 nfs.export-volumes off
volume set: success

I have unmounted the existing mount point and then tried to mount it again, unable to do it.

[root@client1 ~]# umount /ReplicatedVol1
[root@client1 ~]# mount -t nfs Node1:/RepVol1 /ReplicatedVol1
mount.nfs: mounting Node1:/RepVol1 failed, reason given by server: No such file or directory

Still I am able to mount the directory(Dir1) inside the volume.

[root@client1 ~]# mount -t nfs Node1:/RepVol1/Dir1 /ReplicatedVol1
[root@client1 ~]# cd /ReplicatedVol1/
[root@client1 ReplicatedVol1]# ll
total 0
-rw-r–r– 1 root root 0 Dec 24 14:52 nestedfile1

Step 6 : In above you can mount the Dir2 as well which we have created in step 4. To add more twist if you want to mount the Dir1 only not the Dir2 we have the option for it as well.

[root@Node2 ~]# gluster vol set RepVol1 nfs.export-dir /Dir1
volume set: success
[root@Node2 ~]# gluster vol info RepVol1

Volume Name: RepVol1
Type: Replicate
Volume ID: 213ab453-e730-4644-9aaa-147b9dba9252
Status: Started
Snap Volume: no
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: Node1:/Replicated/RepBrickNode1
Brick2: Node2:/Replicated/RepBrickNode2
Options Reconfigured:
nfs.export-dir: /Dir1
nfs.export-volumes: off
nfs.export-dirs: true
performance.readdir-ahead: on
auto-delete: disable
snap-max-soft-limit: 90
snap-max-hard-limit: 256

Now it will allow only to mount the Dir1 present inside the volume nothing else.

Step 7 : If you want to add more directories into the list . Like I have added Dir2 along with Dir1. Now I can mount the Dir1 and Dir2 at client.

[root@Node2 ~]# gluster vol set RepVol1 nfs.export-dir /Dir2,/Dir1
volume set: success

[root@Node2 ~]# gluster vol info RepVol1

Volume Name: RepVol1
Type: Replicate
Volume ID: 213ab453-e730-4644-9aaa-147b9dba9252
Status: Started
Snap Volume: no
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: Node1:/Replicated/RepBrickNode1
Brick2: Node2:/Replicated/RepBrickNode2
Options Reconfigured:
nfs.export-dir: /Dir2,/Dir1
nfs.export-volumes: off
nfs.export-dirs: true
performance.readdir-ahead: on
auto-delete: disable
snap-max-soft-limit: 90
snap-max-hard-limit: 256

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s