Ceph文件存儲(chǔ)部署與使用
1.安裝client操作系統(tǒng)
(1)虛擬機(jī)基礎(chǔ)設(shè)置
在VMware中創(chuàng)建一臺(tái)虛擬機(jī),操作系統(tǒng)為CentOS-7-x86_64-DVD-1908,硬盤大小為20G,并將虛擬機(jī)的名字設(shè)為client,如圖7-10所示。

????????????????? 圖7-10 虛擬機(jī)配置
(2)虛擬機(jī)網(wǎng)絡(luò)設(shè)置
為虛擬機(jī)配置主機(jī)名:client。設(shè)置網(wǎng)絡(luò)為NAT模式,配置IP地址:192.168.100.100,子網(wǎng)掩碼為255.255.255.0,默認(rèn)網(wǎng)關(guān)為192.168.100.2,DNS服務(wù)器為192.168.100.2,使虛擬機(jī)可以訪問Internet。
2.配置Ceph文件系統(tǒng)
(1)部署MDS
在ceph-1節(jié)點(diǎn)中,將MDS部署到ceph-1節(jié)點(diǎn)
[root@ceph-1 ~]# cd /opt/osd
[root@ceph-1 osd]# ceph-deploy mdscreate ceph-1
(2)創(chuàng)建數(shù)據(jù)和存儲(chǔ)池
在ceph-1節(jié)點(diǎn)為Ceph文件系統(tǒng)創(chuàng)建數(shù)據(jù)和元數(shù)據(jù)存儲(chǔ)池。
[root@ceph-1 osd]# ceph osd poolcreate cephfs_data 64
pool 'cephfs_data' created
[root@ceph-1 osd]# ceph osd poolcreate cephfs_metadata 64
pool 'cephfs_metadata' created
(3)創(chuàng)建Ceph文件系統(tǒng)
在ceph-1節(jié)點(diǎn)創(chuàng)建ceph的文件系統(tǒng)cephfs。
[root@ceph-1 osd]# ceph fs newcephfs cephfs_metadata cephfs_data
new fs with metadata pool 2 anddata pool 1
(4)驗(yàn)證MDS和CephFS的狀態(tài)
[root@ceph-1 osd]# ceph mds stat
cephfs:1 {0=ceph-1=up:active}
[root@ceph-1 osd]# ceph osd pool ls
rbd
.rgw.root
default.rgw.control
default.rgw.meta
default.rgw.log
.rgw
.rgw.control
.rgw.gc
.rgw.buckets
.rgw.buckets.index
.rgw.buckets.extra
.log
.intent-log
.usage
.users
.users.email
.users.swift
.users.uid
default.rgw.buckets.index
default.rgw.buckets.data
cephfs_data
cephfs_metadata
[root@ceph-1 osd]# ceph fs ls
name: cephfs, metadata pool:cephfs_metadata, data pools: [cephfs_data ]
(5)創(chuàng)建用戶
在Ceph集群中創(chuàng)建用戶client.cephfs,允許這個(gè)用戶可以訪問CephFS池。
[root@ceph-1 osd]# ceph authget-or-create client.cephfs mon 'allow r' mds 'allow r,allow rw path=/' osd'allow rw pool=cephfs_data' -o /etc/ceph/client.cephfs.keyring
[root@ceph-1 osd]# ceph-authtool -p-n client.cephfs /etc/ceph/client.cephfs.keyring > /etc/ceph/client.cephfs
[root@ceph-1 osd]# cat/etc/ceph/client.cephfs
AQA18Nldot+5DBAAQc4R6zbX+V6jBRINE4lJRA==
3、訪問CephFS
(1)創(chuàng)建掛載點(diǎn)
[root@client ~]# mkdir/media/cephfs
(2)文件系統(tǒng)掛載
使用mount命令掛載CephFS文件系統(tǒng)
[root@client ~]# mount -t ceph192.168.100.101:6789:/ /media/cephfs -o name=cephfs,secret=AQA18Nldot+5DBAAQc4R6zbX+V6jBRINE4lJRA==
(3)查看掛載并解除掛載
[root@client ~]# mount | grep/media/cephfs
192.168.100.101:6789:/ on/media/cephfs type ceph(rw,relatime,name=cephfs,secret=,acl,wsize=16777216)
[root@client ~]# umount/media/cephfs
(4)通過文件掛載
為了更安全的掛載CephFS,防止在命令行歷史中泄露密碼,應(yīng)該把密碼存儲(chǔ)在一個(gè)單獨(dú)的文本文件中,然后把這個(gè)文件作為掛載命令的參數(shù)值。為了實(shí)現(xiàn)這個(gè)功能,需要在client節(jié)點(diǎn)安裝ceph。
首先編輯ceph-1節(jié)點(diǎn)的hosts。
[root@ceph-1 osd]# vi /etc/hosts
192.168.100.100 client
192.168.100.101 ceph-1
192.168.100.102 ceph-2
192.168.100.103 ceph-3
(5)復(fù)制公鑰
在ceph-1節(jié)點(diǎn),將公鑰復(fù)制到client節(jié)點(diǎn)。
[root@ceph-1 osd]# ssh-copy-idroot@client
/usr/bin/ssh-copy-id: INFO: Sourceof key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'client(192.168.100.100)' can't be established.
ECDSA key fingerprint isSHA256:XpUmb4kHGXWKkaTj44vITJDwBBApSk6Yo8ZunIEW010.
ECDSA key fingerprint isMD5:85:d3:f8:41:59:c4:a4:b4:c3:e9:71:2c:3b:45:0b:29.
Are you sure you want to continueconnecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO:attempting to log in with the new key(s), to filter out any that are alreadyinstalled
/usr/bin/ssh-copy-id: INFO: 1key(s) remain to be installed -- if you are prompted now it is to install thenew keys
root@client's password:
Number of key(s) added: 1
Now try logging into the machine,with:?? "ssh 'root@client'"
and check to make sure that onlythe key(s) you wanted were added.
(6)編輯yum文件
在client節(jié)點(diǎn)編輯YUM軟件源配置文件
[root@client ~]# mkdir /opt/bak
[root@client ~]# cd/etc/yum.repos.d
[root@client yum.repos.d]# mv */opt/bak
將CentOS7-Base-163.repo通過SFTP復(fù)制到client節(jié)點(diǎn)的/etc/yum.repos.d目錄。
[root@client yum.repos.d]# ls
CentOS7-Base-163.repo
[root@client yum.repos.d]# viceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=http://mirrors.163.com/ceph/rpm-nautilus/el7/$basearch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
priority=1
[Ceph-noarch]
name=Ceph noarch packages
baseurl=http://mirrors.163.com/ceph/rpm-nautilus/el7/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
priority=1
[ceph-source]
name=Ceph source packages
baseurl=http://mirrors.163.com/ceph/rpm-nautilus/el7/SRPMS
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
priority=1
[root@client yum.repos.d]# yumclean all
[root@client yum.repos.d]# yummakecache
(7)安裝ceph
在ceph-1節(jié)點(diǎn),通過ceph-deploy將ceph安裝到client節(jié)點(diǎn)。
[root@ceph-1 osd]# ceph-deployinstall --release=nautilus client
(8)生成密鑰
在client節(jié)點(diǎn)生成密鑰文件
[root@client ~]# echo AQA18Nldot+5DBAAQc4R6zbX+V6jBRINE4lJRA==> /etc/ceph/cephfskey
(9)使用secretfile參數(shù)掛載
[root@client ~]# mount -t ceph 192.168.100.101:6789://media/cephfs -o name=cephfs,secretfile=/etc/ceph/cephfskey
[root@client ~]# mount | grep/media/cephfs
192.168.100.101:6789:/ on/media/cephfs type ceph (rw,relatime,name=cephfs,secret=,acl,wsize=16777216)
[root@client ~]# umount/media/cephfs
(10)開機(jī)自動(dòng)掛載
將參數(shù)按要求寫入系統(tǒng)文件實(shí)現(xiàn)開機(jī)時(shí)自動(dòng)掛載CephFS文件系統(tǒng)
[root@client ~]# vi /etc/fstab
192.168.100.101:6789://media/cephfs ceph name=cephfs,secretfile=/etc/ceph/cephfskey,_netdev,noatime 02
[root@client ~]# mount -a
[root@client ~]# mount | grep /media/cephfs
192.168.100.101:6789:/ on/media/cephfs type ceph(rw,noatime,name=cephfs,secret=,acl,wsize=16777216)