CephFS 密钥生成与挂载

发布于 20 天前  94 次阅读


密钥生成

在 Ceph Monitor 节点上生成一个专用的 Ceph 用户,并且限制对需要挂载的目录的访问。

ceph auth get-or-create client.<username> \
  mon 'allow r' \
  mds 'allow rw path=<mount-path>' \
  osd 'allow rw pool=<cephfs-data-pool-name>' \
  -o /etc/ceph/ceph.client.<username>.keyring

完成后 Keyring 文件生成在 /etc/ceph

密钥与配置文件拷贝

/etc/ceph/ceph.conf/etc/ceph/ceph.client.<username>.keyring 复制到目标服务器 /etc/ceph/ 目录下。

若使用 LXC 容器,可以使用:

pct push <vmid> /etc/ceph/ceph.conf /etc/ceph/ceph.conf
pct push <vmid> /etc/ceph/ceph.client.<username>.keyring /etc/ceph/ceph.client.<username>.keyring

安装 Ceph-fuse

apt install ceph-fuse -y

如果是 LXC 容器,注意配置容器设置 fuse=1

挂载 CephFS

这里使用 systemd,在 /etc/systemd/system 下创建文件,内容如下:

[Unit]
Description=Mount CephFS via ceph-fuse
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/bin/ceph-fuse <mount-path> \
  --name client.<username> \
  --keyring /etc/ceph/ceph.client.<username>.keyring \
  --client-mountpoint=<mount-point> \
  --client-mount-uid=33 \
  --client-mount-gid=33
ExecStop=/bin/fusermount -u <mount-path>
Restart=on-failure
RestartSec=5
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

完成后使用 systemd 管理即可。

配额限制

若需要额外对某用户进行配额限制,此处可以基于其使用文件夹进行 quota 限制。

# 限制文件夹存储空间为 50GiB
setfattr -n ceph.quota.max_bytes -v $((50 * 1024 * 1024 * 1024)) /mnt/pve/CephFS/<target-path>
# 限制文件夹下最大文件数量为 100000
setfattr -n ceph.quota.max_files -v 100000 /mnt/pve/CephFS/<target-path>

我缓慢吐出一串啊吧啊吧并不再想说话