In this exercise, you configure shared file client access with CephFS.
Outcomes
You should be able to manage CephFS and create snapshots.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start fileshare-manage
Procedure 10.2. Instructions
The serverc, serverd, and servere nodes are an operational 3-node Ceph cluster.
All three nodes operate as a MON, a MGR, and an OSD host with at least one colocated OSD.
The clienta node is set up as your admin node server and you use it to install the Metadata Server (MDS) on serverc.
The mycephfs CephFS file system is mounted on the /mnt/mycephfs folder with the key ring for the admin user.
Log in to clienta as the admin user.
[student@workstation ~]$ ssh admin@clienta
[admin@clienta ~]$Create a /mnt/mycephfs/dir1 directory.
Create an empty file /mnt/mycephfs/dir1/ddtest.
Modify the ceph.dir.layout.stripe_count layout attribute for the /mnt/mycephfs/dir1 directory.
Verify that the attribute change does not affect existing files within the directory, but that any newly created files inherit it.
The attr package is preinstalled for you.
Use the getfattr command to create and verify the layout of the /mnt/cephfs/dir1 directory.
This command should not return any layout attribute that is associated with this directory.
[admin@clienta ~]$mkdir /mnt/mycephfs/dir1[admin@clienta ~]$touch /mnt/mycephfs/dir1/ddtest[admin@clienta ~]$getfattr -n ceph.dir.layout /mnt/mycephfs/dir1/mnt/mycephfs/dir1: ceph.dir.layout: No such attribute
If a directory has no layout attributes, then it inherits the layout of its parent. You must set the layout attributes of a directory before you can view them. By default, layout attributes are set on only the top-level directory of the mounted CephFS file system (on the mount point).
Use the setfattr command to change the layout of the /mnt/mycephfs/dir1 directory.
[admin@clienta ~]$setfattr -n ceph.dir.layout.stripe_count \-v 2 /mnt/mycephfs/dir1
Verify the layout of the /mnt/mycephfs/dir1 directory again.
Layout attributes should now be available for this directory.
Settings other than the one that you specified are inherited from the closest parent directory where attributes were set.
[admin@clienta ~]$getfattr -n ceph.dir.layout /mnt/mycephfs/dir1getfattr: Removing leading '/' from absolute path names # file: mnt/mycephfs/dir1 ceph.dir.layout="stripe_unit=4194304stripe_count=2object_size=4194304 pool=mycephfs_data"
Verify the layout for the /mnt/mycephfs/dir1/ddtest file and notice that the layout does not change for this file, which existed before the layout change.
[admin@clienta ~]$getfattr -n ceph.file.layout /mnt/mycephfs/dir1/ddtestgetfattr: Removing leading '/' from absolute path names # file: mnt/mycephfs/dir1/ddtest ceph.file.layout="stripe_unit=4194304stripe_count=1object_size=4194304 pool=mycephfs_data"
Create a file called anewfile under the /mnt/cephfs/dir1/ directory.
Notice how the stripe_count for the layout of this file matches the new layout of the /mnt/cephfs/dir1/ directory.
The new file inherits the layout attributes from its parent directory at creation time.
[admin@clienta ~]$touch /mnt/mycephfs/dir1/anewfile[admin@clienta ~]$getfattr -n ceph.file.layout /mnt/mycephfs/dir1/anewfilegetfattr: Removing leading '/' from absolute path names # file: mnt/mycephfs/dir1/anewfile ceph.file.layout="stripe_unit=4194304stripe_count=2object_size=4194304 pool=mycephfs_data"
Modify the layout of the /mnt/mycephfs/dir1/anewfile file so that the stripe_count value is 3.
You can modify a specific file layout if the file is empty.
Ensure that the new value for stripe_count is correct.
[admin@clienta ~]$setfattr -n ceph.file.layout.stripe_count \-v 3 /mnt/mycephfs/dir1/anewfile[admin@clienta ~]$getfattr -n ceph.file.layout /mnt/mycephfs/dir1/anewfilegetfattr: Removing leading '/' from absolute path names # file: mnt/mycephfs/dir1/anewfile ceph.file.layout="stripe_unit=4194304stripe_count=3object_size=4194304 pool=mycephfs_data"
Ensure that the /mnt/mycephfs/dir1/anewfile file is not empty.
Verify that you cannot modify a specific file's layout attributes if the file is not empty.
[admin@clienta ~]$echo "Not empty" > /mnt/mycephfs/dir1/anewfile[admin@clienta ~]$setfattr -n ceph.file.layout.stripe_count \-v 4 /mnt/mycephfs/dir1/anewfilesetfattr: /mnt/mycephfs/dir1/anewfile: Directory not empty
Clear the configured layout attributes for the /mnt/mycephfs/dir1 directory.
Verify the new layout settings (that are inherited from the top of the CephFS file system) by creating a file called a3rdfile.
[admin@clienta ~]$setfattr -x ceph.dir.layout /mnt/mycephfs/dir1[admin@clienta ~]$touch /mnt/mycephfs/dir1/a3rdfile[admin@clienta ~]$getfattr -n ceph.file.layout /mnt/mycephfs/dir1/a3rdfilegetfattr: Removing leading '/' from absolute path names # file: mnt/mycephfs/dir1/a3rdfile ceph.file.layout="stripe_unit=4194304stripe_count=1object_size=4194304 pool=mycephfs_data"
Create a snapshot for your CephFS file system.
Mount the CephFS file system on /mnt/mycephfs as the user restricteduser.
Unmount the /mnt/mycephfs folder and mount again the CephFS file system to that folder as the user restricteduser.
[admin@clienta ~]$sudo umount /mnt/mycephfs[admin@clienta ~]$sudo mount.ceph serverc.lab.example.com:/ \ /mnt/mycephfs -o name=restricteduser
Navigate to the hidden .snap folder in /mnt/mycephfs.
[admin@clienta ~]$ cd /mnt/mycephfs/.snapCreate a mysnapshot folder, which is the snapshot name.
As the user restricteduser does not currently have snapshot permissions, you must grant snapshot permissions to this user.
After you set the permissions, you must remount the CephFS file system to use the new permissions.
[admin@clienta .snap]$mkdir mysnapshotmkdir: cannot create directory 'mysnapshot': Permission denied [admin@clienta .snap]$sudo cephadm shell[ceph: root@clienta /]#ceph auth get client.restricteduser[client.restricteduser] key = AQBc315hI7PaBRAA9/9fdmj+wjblK+izstA0aQ== caps mds = "allow r fsname=mycephfs, allow rw fsname=mycephfs path=/dir2" caps mon = "allow r fsname=mycephfs" caps osd = "allow rw tag cephfs data=mycephfs" exported keyring for client.restricteduser [ceph: root@clienta /]#ceph auth caps client.restricteduser \ mds 'allow rws fsname=mycephfs' \ mon 'allow r fsname=mycephfs' \ osd 'allow rw tag cephfs data=mycephfs'updated caps for client.restricteduser [ceph: root@clienta /]#exitexit [admin@clienta .snap]$cd[admin@clienta ~]$sudo umount /mnt/mycephfs[admin@clienta ~]$sudo mount.ceph serverc.lab.example.com:/ \ /mnt/mycephfs -o name=restricteduser[admin@clienta ~]$cd /mnt/mycephfs/.snap[admin@clienta .snap]$mkdir mysnapshot
Check that the files in the snapshot are the same as the files in the mounted CephFS file system.
[admin@clienta .snap]$tree /mnt/mycephfs/mnt/mycephfs └── dir1 ├── a3rdfile ├── anewfile └── ddtest 1 directory, 3 files [admin@clienta .snap]$tree /mnt/mycephfs/.snap/mysnapshot/mnt/mycephfs/.snap/mysnapshot └── dir1 ├── a3rdfile ├── anewfile └── ddtest 1 directory, 3 files
Schedule to create an hourly snapshot of your CephFS file system's root folder.
Use sudo to run the cephadm shell.
Enable the snapshot module.
[admin@clienta .snap]$sudo cephadm shell[ceph: root@clienta /]#ceph mgr module enable snap_schedule
Schedule to create the snapshot every hour.
[ceph: root@clienta /]# ceph fs snap-schedule add / 1h
Schedule set for path /Check that your snapshot schedule is correctly created and in an active state.
[ceph: root@clienta /]#ceph fs snap-schedule status /{"fs": "mycephfs", "subvol": null, "path": "/", "rel_path": "/","schedule": "1h", "retention": {}, "start": "2021-10-06T00:00:00", "created": "2021-10-06T08:59:16", "first": "2021-10-06T09:00:00", "last": "2021-10-06T09:00:00", "last_pruned": null, "created_count": 1, "pruned_count": 0,"active": true}
Exit from the cephadm shell.
Check that your snapshot is correctly created in your .snap folder.
[ceph: root@clienta /]#exitexit [admin@clienta .snap]$lsmysnapshotscheduled-2021-10-06-09_00_00[admin@clienta .snap]$tree. ├── mysnapshot │ └── dir1 │ ├── a3rdfile │ ├── anewfile │ └── ddtest └── scheduled-2021-10-06-09_00_00 └── dir1 ├── a3rdfile ├── anewfile └── ddtest 4 directories, 6 files
Creating the scheduled snapshot might take time. As you scheduled it every hour, it might take up to one hour to be triggered. You do not have to wait until the snapshot is created.
Return to workstation as the student user.
[admin@clienta .snap]$ exit
[student@workstation ~]$Run the lab finish script on the workstation server so that the clienta node can be safely rebooted without mount conflicts.
This concludes the guided exercise.