Bookmark this page

Guided Exercise: Managing Shared File Storage

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.

  1. Log in to clienta as the admin user.

    [student@workstation ~]$ ssh admin@clienta
    [admin@clienta ~]$
  2. 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.

    1. 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

      Note

      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).

    2. 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
    3. 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/dir1
      getfattr: Removing leading '/' from absolute path names
      # file: mnt/mycephfs/dir1
      ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=mycephfs_data"
    4. 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/ddtest
      getfattr: Removing leading '/' from absolute path names
      # file: mnt/mycephfs/dir1/ddtest
      ceph.file.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=mycephfs_data"
    5. 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/anewfile
      getfattr: Removing leading '/' from absolute path names
      # file: mnt/mycephfs/dir1/anewfile
      ceph.file.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=mycephfs_data"
    6. 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/anewfile
      getfattr: Removing leading '/' from absolute path names
      # file: mnt/mycephfs/dir1/anewfile
      ceph.file.layout="stripe_unit=4194304 stripe_count=3 object_size=4194304 pool=mycephfs_data"
    7. 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/anewfile
      setfattr: /mnt/mycephfs/dir1/anewfile: Directory not empty
    8. 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/a3rdfile
      getfattr: Removing leading '/' from absolute path names
      # file: mnt/mycephfs/dir1/a3rdfile
      ceph.file.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=mycephfs_data"
  3. Create a snapshot for your CephFS file system. Mount the CephFS file system on /mnt/mycephfs as the user restricteduser.

    1. 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
    2. Navigate to the hidden .snap folder in /mnt/mycephfs.

      [admin@clienta ~]$ cd /mnt/mycephfs/.snap
    3. Create 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 mysnapshot
      mkdir: 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 /]# exit
      exit
      [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
    4. 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
  4. Schedule to create an hourly snapshot of your CephFS file system's root folder.

    1. 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
    2. Schedule to create the snapshot every hour.

      [ceph: root@clienta /]# ceph fs snap-schedule add / 1h
      Schedule set for path /
    3. 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}
    4. Exit from the cephadm shell. Check that your snapshot is correctly created in your .snap folder.

      [ceph: root@clienta /]# exit
      exit
      [admin@clienta .snap]$ ls
      mysnapshot  scheduled-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.

  5. Return to workstation as the student user.

    [admin@clienta .snap]$ exit
    [student@workstation ~]$

    Warning

    Run the lab finish script on the workstation server so that the clienta node can be safely rebooted without mount conflicts.

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish fileshare-manage

This concludes the guided exercise.

Revision: cl260-5.0-29d2128