文章目录
ceph FS 即 ceph filesystem,可以实现文件系统共享功能,客户端通过 ceph 协议挂载并使用 ceph 集群作为数据存储服务器。
Ceph FS 需要运行 Meta Data Services(MDS)服务,其守护进程为 ceph-mds,ceph-mds 进程管理与 cephFS 上存储的文件相关的元数据,并协调对 ceph 存储集群的访问。
一、部署 MDS 服务
MDS可以与mgr服务器混用,也可以自己单独一台服务器
[root@ceph-mgr1 ~]# yum install ceph-mds -y
[ceph@ceph-deploy ceph-cluster]$ mds create ceph-mgr1
二、创建 CephFS metadata 和 data 存储池
使用 CephFS 之前需要事先于集群中创建一个文件系统,并为其分别指定元数据和数据相关的存储池。
下面创建一个名为 cephfs 的文件系统用于测试,它使用 cephfs-metadata 为元数据存储池,使用 cephfs-data 为数据存储池
# 创建保存元数据的存储池
[ceph@ceph-deploy ceph-cluster]$ ceph osd pool create cephfs-metadata 32 32
# 创建保存数据的存储池
[ceph@ceph-deploy ceph-cluster]$ ceph osd pool create cephfs-data 64 64
# 当前 ceph 状态
[ceph@ceph-deploy ceph-cluster]$ ceph -s
三、创建 cephFS 并验证
# 创建CephFS文件系统
[ceph@ceph-deploy ceph-cluster]$ ceph fs new mycephfs cephfs-metadata cephfs-data
# 查看CephFS的文件系统
[ceph@ceph-deploy ceph-cluster]$ ceph fs ls
#查看指定 cephFS 状态
[ceph@ceph-deploy ceph-cluster]$ ceph fs status mycephfs
四、验证 cepfFS 服务状态
[ceph@ceph-deploy ceph-cluster]$ ceph mds stat
mycephfs-1/1/1 up {0=ceph-mgr1=up:active} #现在已经转变为活动状态
五、创建客户端普通账户
# 创建账户
[ceph@ceph-deploy ceph-cluster]$ ceph auth add client.yanyan mon 'allow r' mds 'allow rw' osd 'allow rwx pool=cephfs-data'
# 验证账户
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.yanyan
# 创建空 keyring 文件
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.yanyan -o ceph.client.yanyan.keyring
# 导入空 keyring 文件
[ceph@ceph-deploy ceph-cluster]$ ceph auth print-key client.yanyan > yanyan.key
# 验证用户的 keyring 文件
[ceph@ceph-deploy ceph-cluster]$ cat ceph.client.yanyan.keyring
六、安装 ceph 客户端
yum install epel-release -y
yum install https://mirrors.aliyun.com/ceph/rpm-mimic/el7/noarch/ceph-release-1-1.el7.noarch.rpm -y
yum install ceph-common -y
七、同步客户端认证文件
[ceph@ceph-deploy ceph-cluster]$ scp ceph.conf ceph.client.yanyan.keyring yanyan.key root@客户端IP:/etc/ceph/
八、客户端验证权限
[root@ceph-client ~]# ceph --user yanyan -s
九、客户端挂载
9.1 内核支持 ceph 模块
查看内核载 ceph.ko 模块
[root@ceph-client ~]# modinfo ceph
客户端挂载 CephFS
# 挂载方式一:客户端通过 key 文件挂载
[root@ceph-client ~]# mount -t ceph 172.31.6.104:6789,172.31.6.105:6789,172.31.6.106:6789:/ /data -o name=yanyan,secretfile=/etc/ceph/yanyan.key
[root@ceph-client ~]# df -TH
# 挂载方式二:客户端通过 key 挂载
[root@ceph-client ~]# tail /etc/ceph/yanyan.key
AQCxpdhfjQt1OxAAGe0mqTMveNu2ZMEem3tb0g==
[root@ceph-client ~]# mount -t ceph 172.31.6.104:6789,172.31.6.105:6789,172.31.6.106:6789:/ /data -o name=yanyan,secret=AQCxpdhfjQt1OxAAGe0mqTMveNu2ZMEem3tb0g==
[root@ceph-client ~]# df -TH
# 挂载方式三:开机挂载
[root@ceph-client ~]# cat /etc/fstab
172.31.6.104:6789,172.31.6.105:6789,172.31.6.106:6789:/ /data ceph defaults,name=yanyan,secretfile=/etc/ceph/yanyan.key,_netdev 0 0
[root@ceph-client ~]# mount -a
9.2 内核不支持 ceph 模块
如果内核本较低而没有 ceph 模块,那么可以安装 ceph-fuse 挂载,但是推荐使用内核模块挂载。
# 安装 ceph-fuse
[root@ceph-client ~]# yum install ceph-fuse -y
# 通过 ceph-fuse 挂载 ceph
[root@ceph-client ~]# ceph-fuse --name client.yanyan -m 172.31.6.104:6789,172.31.6.105:6789,172.31.6.106:6789 /data
# 验证挂载
[root@ceph-client ~]# df -TH
开机挂载,指定用户会自动根据用户名称加载授权文件及配置文件 ceph.conf
[root@ceph-client ~]# vim /etc/fstab
none /data fuse.ceph ceph.id=yanyan,ceph.conf=/etc/ceph/ceph.conf,_netdev,defaults 0 0
[root@ceph-client ~]# mount -a