前文我們使用ceph-deploy工具簡單拉起了ceph底層存盤集群RADOS,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/16724473.html;今天我們來聊一聊ceph集群訪問介面相關話題;
我們知道RADOS集群是ceph底層存盤集群,部署好RADOS集群以后,默認只有RBD(Rados Block Device)介面;但是該介面并不能使用;這是因為在使用rados存盤集群存取物件資料時,都是通過存盤池找到對應pg,然后pg找到對應的osd,由osd通過librados api介面將資料存盤到對應的osd所對應的磁盤設備上;
啟用Ceph塊設備介面(RBD)
對于RBD介面來說,客戶端基于librbd即可將RADOS存盤集群用作塊設備,不過,用于rbd的存盤池需要事先啟用rbd功能并進行初始化;
1、創建RBD存盤池
[root@ceph-admin ~]# ceph osd pool create rbdpool 64 64 pool 'rbdpool' created [root@ceph-admin ~]# ceph osd pool ls testpool rbdpool [root@ceph-admin ~]#
2、啟用RBD存盤池RBD功能
查看ceph osd pool 幫助
Monitor commands:
=================
osd pool application disable <poolname> <app> {--yes- disables use of an application <app> on pool
i-really-mean-it} <poolname>
osd pool application enable <poolname> <app> {--yes-i- enable use of an application <app> [cephfs,rbd,rgw]
really-mean-it} on pool <poolname>
提示:ceph osd pool application disable 表示禁用對應存盤池上的對應介面功能,enbale 表示啟用對應功能;后面的APP值只接受cephfs、rbd和rgw;
[root@ceph-admin ~]# ceph osd pool application enable rbdpool rbd enabled application 'rbd' on pool 'rbdpool' [root@ceph-admin ~]#
3、初始化RBD存盤池
[root@ceph-admin ~]# rbd pool init -p rbdpool [root@ceph-admin ~]#
驗證rbdpool是否成功初始化,對應rbd應用是否啟用?

提示:使用ceph osd pool ls detail命令就能查看存盤池詳細資訊;到此rbd存盤池就初始化完成;但是,rbd存盤池不能直接用于塊設備,而是需要事先在其中按需創建映像(image),并把映像檔案作為塊設備使用;
4、在rbd存盤池里創建image
[root@ceph-admin ~]# rbd create --size 5G rbdpool/rbd-img01 [root@ceph-admin ~]# rbd ls rbdpool rbd-img01 [root@ceph-admin ~]#
查看創建image的資訊
[root@ceph-admin ~]# rbd info rbdpool/rbd-img01
rbd image 'rbd-img01':
size 5 GiB in 1280 objects
order 22 (4 MiB objects)
id: d4466b8b4567
block_name_prefix: rbd_data.d4466b8b4567
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Sun Sep 25 11:25:01 2022
[root@ceph-admin ~]#
提示:可以看到對應image支持分層克隆,排他鎖,物件映射等等特性;到此一個5G大小的磁盤image就創建好了;客戶端可以基于內核發現機制將對應image識別成一塊磁盤設備進行使用;
啟用radosgw介面
RGW并非必須的介面,僅在需要用到與S3和Swift兼容的RESTful介面時才需要部署RGW實體;radosgw介面依賴ceph-rgw行程對外提供服務;所以我們要啟用radosgw介面,就需要在rados集群上運行ceph-rgw行程;
1、部署ceph-radosgw
[root@ceph-admin ~]# ceph-deploy rgw --help
usage: ceph-deploy rgw [-h] {create} ...
Ceph RGW daemon management
positional arguments:
{create}
create Create an RGW instance
optional arguments:
-h, --help show this help message and exit
[root@ceph-admin ~]#
提示:ceph-deploy rgw命令就只有一個create子命令用于創建RGW實體;
[root@ceph-admin ~]# su - cephadm
Last login: Sat Sep 24 23:16:00 CST 2022 on pts/0
[cephadm@ceph-admin ~]$ cd ceph-cluster/
[cephadm@ceph-admin ceph-cluster]$ ceph-deploy rgw create ceph-mon01
[ceph_deploy.conf][DEBUG ] found configuration file at: /home/cephadm/.cephdeploy.conf
[ceph_deploy.cli][INFO ] Invoked (2.0.1): /bin/ceph-deploy rgw create ceph-mon01
[ceph_deploy.cli][INFO ] ceph-deploy options:
[ceph_deploy.cli][INFO ] username : None
[ceph_deploy.cli][INFO ] verbose : False
[ceph_deploy.cli][INFO ] rgw : [('ceph-mon01', 'rgw.ceph-mon01')]
[ceph_deploy.cli][INFO ] overwrite_conf : False
[ceph_deploy.cli][INFO ] subcommand : create
[ceph_deploy.cli][INFO ] quiet : False
[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7fa658caff80>
[ceph_deploy.cli][INFO ] cluster : ceph
[ceph_deploy.cli][INFO ] func : <function rgw at 0x7fa6592f5140>
[ceph_deploy.cli][INFO ] ceph_conf : None
[ceph_deploy.cli][INFO ] default_release : False
[ceph_deploy.rgw][DEBUG ] Deploying rgw, cluster ceph hosts ceph-mon01:rgw.ceph-mon01
[ceph-mon01][DEBUG ] connection detected need for sudo
[ceph-mon01][DEBUG ] connected to host: ceph-mon01
[ceph-mon01][DEBUG ] detect platform information from remote host
[ceph-mon01][DEBUG ] detect machine type
[ceph_deploy.rgw][INFO ] Distro info: CentOS Linux 7.9.2009 Core
[ceph_deploy.rgw][DEBUG ] remote host will use systemd
[ceph_deploy.rgw][DEBUG ] deploying rgw bootstrap to ceph-mon01
[ceph-mon01][DEBUG ] write cluster configuration to /etc/ceph/{cluster}.conf
[ceph-mon01][WARNIN] rgw keyring does not exist yet, creating one
[ceph-mon01][DEBUG ] create a keyring file
[ceph-mon01][DEBUG ] create path recursively if it doesn't exist
[ceph-mon01][INFO ] Running command: sudo ceph --cluster ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/ceph.keyring auth get-or-create client.rgw.ceph-mon01 osd allow rwx mon allow rw -o /var/lib/ceph/radosgw/ceph-rgw.ceph-mon01/keyring
[ceph-mon01][INFO ] Running command: sudo systemctl enable [email protected]
[ceph-mon01][WARNIN] Created symlink from /etc/systemd/system/ceph-radosgw.target.wants/[email protected] to /usr/lib/systemd/system/[email protected].
[ceph-mon01][INFO ] Running command: sudo systemctl start [email protected]
[ceph-mon01][INFO ] Running command: sudo systemctl enable ceph.target
[ceph_deploy.rgw][INFO ] The Ceph Object Gateway (RGW) is now running on host ceph-mon01 and default port 7480
[cephadm@ceph-admin ceph-cluster]$
查看集群狀態

提示:可以看到現在集群有一個rgw行程處于活躍狀態;這里需要說明一點,radosgw部署好以后,對應它會自動創建自己所需要的存盤池,如下所示;

提示:默認情況下,它會創建以上4個存盤池;這里說一下默認情況下radosgw會監聽tcp協議的7480埠,以web服務形式提供服務;如果我們需要更改對應監聽埠,可以在組態檔/etc/ceph/ceph.conf中配置
[client] rgw_frontends = "civetweb port=8080"
提示:該配置操作需要在對應運行rgw的主機上修改配置,然后重啟對應行程即可;
重啟行程

提示:可以看到現在mon01上沒有監聽7480的埠,而是8080的埠;
用瀏覽器訪問8080埠

提示:訪問對應主機的8080埠這里給我們回傳一個xml的檔案的界面;RGW提供的是RESTful介面,客戶端通過http與其進行互動,完成資料的增刪改查等管理操作,有上述界面說明我們rgw服務部署并運行成功;到此radosgw介面就啟用Ok了;
啟用檔案系統介面(cephfs)
在說檔案系統時,我們首先會想到元資料和資料的存放問題;CephFS和rgw一樣它也需要依賴一個行程,cephfs依賴mds行程來幫助它來維護檔案的元資料資訊;MDS是MetaData Server的縮寫,主要作用就是處理元資料資訊;它和別的元資料服務器不一樣,MDS只負責路由元資料資訊,它自己并不存盤元資料資訊;檔案的元資料資訊是存放在RADOS集群之上;所以我們要使用cephfs需要創建兩個存盤池,一個用于存放cephfs的元資料一個用于存放檔案的資料;那么對于mds來說,它為了能夠讓用戶讀取資料更快更高效,通常它會把一些熱區資料快取在自己本地,以便更快的告訴客戶端,對應資料存放問位置;由于MDS將元資料資訊存放在rados集群之上,使得MDS就變成了無狀態,無狀態意味著高可用是以冗余的方式;至于怎么高可用,后續要再聊;
1、部署ceph-mds
[cephadm@ceph-admin ceph-cluster]$ ceph-deploy mds create ceph-mon02
[ceph_deploy.conf][DEBUG ] found configuration file at: /home/cephadm/.cephdeploy.conf
[ceph_deploy.cli][INFO ] Invoked (2.0.1): /bin/ceph-deploy mds create ceph-mon02
[ceph_deploy.cli][INFO ] ceph-deploy options:
[ceph_deploy.cli][INFO ] username : None
[ceph_deploy.cli][INFO ] verbose : False
[ceph_deploy.cli][INFO ] overwrite_conf : False
[ceph_deploy.cli][INFO ] subcommand : create
[ceph_deploy.cli][INFO ] quiet : False
[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7ff12df9e758>
[ceph_deploy.cli][INFO ] cluster : ceph
[ceph_deploy.cli][INFO ] func : <function mds at 0x7ff12e1f7050>
[ceph_deploy.cli][INFO ] ceph_conf : None
[ceph_deploy.cli][INFO ] mds : [('ceph-mon02', 'ceph-mon02')]
[ceph_deploy.cli][INFO ] default_release : False
[ceph_deploy.mds][DEBUG ] Deploying mds, cluster ceph hosts ceph-mon02:ceph-mon02
[ceph-mon02][DEBUG ] connection detected need for sudo
[ceph-mon02][DEBUG ] connected to host: ceph-mon02
[ceph-mon02][DEBUG ] detect platform information from remote host
[ceph-mon02][DEBUG ] detect machine type
[ceph_deploy.mds][INFO ] Distro info: CentOS Linux 7.9.2009 Core
[ceph_deploy.mds][DEBUG ] remote host will use systemd
[ceph_deploy.mds][DEBUG ] deploying mds bootstrap to ceph-mon02
[ceph-mon02][DEBUG ] write cluster configuration to /etc/ceph/{cluster}.conf
[ceph-mon02][WARNIN] mds keyring does not exist yet, creating one
[ceph-mon02][DEBUG ] create a keyring file
[ceph-mon02][DEBUG ] create path if it doesn't exist
[ceph-mon02][INFO ] Running command: sudo ceph --cluster ceph --name client.bootstrap-mds --keyring /var/lib/ceph/bootstrap-mds/ceph.keyring auth get-or-create mds.ceph-mon02 osd allow rwx mds allow mon allow profile mds -o /var/lib/ceph/mds/ceph-ceph-mon02/keyring
[ceph-mon02][INFO ] Running command: sudo systemctl enable ceph-mds@ceph-mon02
[ceph-mon02][WARNIN] Created symlink from /etc/systemd/system/ceph-mds.target.wants/[email protected] to /usr/lib/systemd/system/[email protected].
[ceph-mon02][INFO ] Running command: sudo systemctl start ceph-mds@ceph-mon02
[ceph-mon02][INFO ] Running command: sudo systemctl enable ceph.target
[cephadm@ceph-admin ceph-cluster]$
查看mds狀態
[cephadm@ceph-admin ceph-cluster]$ ceph mds stat , 1 up:standby [cephadm@ceph-admin ceph-cluster]$
提示:可以看到現在集群有一個mds啟動著,并以standby的方式運行;這是因為我們只是部署了ceph-mds行程,對應在rados集群上并沒有系結存盤池;所以現在mds還不能正常提供服務;
2、創建存盤池
[cephadm@ceph-admin ceph-cluster]$ ceph osd pool create cephfs-metadatpool 64 64 pool 'cephfs-metadatpool' created [cephadm@ceph-admin ceph-cluster]$ceph osd pool create cephfs-datapool 128 128 pool 'cephfs-datapool' created [cephadm@ceph-admin ceph-cluster]$ ceph osd pool ls testpool rbdpool .rgw.root default.rgw.control default.rgw.meta default.rgw.log cephfs-metadatpool cephfs-datapool [cephadm@ceph-admin ceph-cluster]$
3、初始化存盤池
查看ceph fs幫助

提示:我們可以使用ceph fs new命令來指定cephfs的元資料池和資料池;
[cephadm@ceph-admin ceph-cluster]$ ceph fs new cephfs cephfs-metadatpool cephfs-datapool new fs with metadata pool 7 and data pool 8 [cephadm@ceph-admin ceph-cluster]$
再次查看mds狀態
[cephadm@ceph-admin ceph-cluster]$ ceph mds stat
cephfs-1/1/1 up {0=ceph-mon02=up:active}
[cephadm@ceph-admin ceph-cluster]$
查看集群狀態

提示:可以看到現在mds已經運行起來,并處于active狀態;
查看ceph 檔案系統狀態

提示:可以看到對應檔案系統是活躍狀態;隨后,客戶端通過內核中的cephfs檔案系統介面即可掛載使用cephfs檔案系統,或者通過FUSE介面與檔案系統進行互動使用;
作者:Linux-1874 出處:https://www.cnblogs.com/qiuhom-1874/ 本文著作權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利.轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/510906.html
標籤:其他
上一篇:網路層:資料平面
下一篇:列印陣列的全部排列
