手動部署 Ceph Nautilus(14.2.2)

對於剛進入 Ceph 領域的讀者,部署 Ceph 可能會採用相對應的部署工具,例如:ceph-deploy。雖然它可以幫助我們快速建立 Ceph 叢集,但是對於 Ceph 整體部署流程與過程中每個 Components(如:MON, MDS)等,運作方式可能會有疑惑。

因此希望可以透過本篇文章一步一步帶領讀者安裝 Ceph 叢集,讓讀者可以理解每個步驟用途與叢集運作的流程。

環境

本篇文章利用 VirutalBox 建立一台 Ubuntu 16.04 虛擬機做 Ceph All in One,並且在實體機器規劃一個虛擬硬碟空間作為 Ceph OSD 使用。

在 VitualBox 掛載一顆虛擬硬碟後,可以透過 fdisk 指令再作進一步的 partitions。

參數 數值
Operating System Ubuntu 16.04 LTS
Host Name ceph
Private Network 172.17.1.100
Ceph Version 14.2.2

安裝

Ceph MON

更新套件集。

1
2
$ apt update
$ apt upgrade -y

增加 release.asc Key。

1
$ wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add -

增加 Ceph Repo 到 source list。

1
$ apt-add-repository 'deb https://download.ceph.com/debian-nautilus/ xenial main'

再次更新套件

1
$ apt update

安裝 Ceph 與 Ceph RADOSGW 相關套件。

1
$ apt install -y ceph radosgw radosgw-agent

確認 Ceph 版本(Version)。

1
$ ceph -v

替 Ceph 產生 UUID

1
2
$ uuidgen
cb9d566e-48e5-4810-9163-5c7784c8b3c0

目錄切換至 /etc/ceph/ 並且建立 ceph.conf 配置檔,將以下配置內容增加至 ceph.conf 配置檔內。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cd /etc/ceph/
$ vim ceph.conf

# Version 14.2.2
[global]
fsid = cb9d566e-48e5-4810-9163-5c7784c8b3c0

mon initial members = mon

mon host = 172.17.1.100

public network = 172.17.1.0/24

cluster network = 172.17.1.0/24

auth cluster required = cephx
auth service required = cephx
auth client required = cephx

mon max pg per osd = 1000
mon allow pool delete = true
osd crush update on start = false

fsid 填入前步驟所建立的 UUID

建立一把名為 ceph.mon.keyring 的 Ceph MON secret key 並且儲存於 /tmp 底下,賦予 mon 全部存取權限。

1
2
3
$ ceph-authtool --create-keyring /tmp/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'

creating /tmp/ceph.mon.keyring

–gen-key 表示系統自動產生 secret key

建立一把名為 ceph.client.admin.keyring 的 Ceph clent.admin key 並儲存於 /etc/ceph/ 底下,賦予全部(MON, OSD, MDS 與 MGR) 存取權限。

1
2
3
$ ceph-authtool --create-keyring /etc/ceph/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *'

creating /etc/ceph/ceph.client.admin.keyring

ceph.mon.keyring 內容複製至 ceph.client.admin.keyring 內。

1
2
3
$ ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.client.admin.keyring

importing contents of /etc/ceph/ceph.client.admin.keyring into /tmp/ceph.mon.keyring

替 Ceph 建立 monitor map。

1
2
3
4
5
$ monmaptool --create --add mon 172.17.1.100:6789 --fsid `ceph-conf --lookup fsid` /tmp/monmap

monmaptool: monmap file /tmp/monmap
monmaptool: set fsid to cb9d566e-48e5-4810-9163-5c7784c8b3c0
monmaptool: writing epoch 0 to /tmp/monmap (1 monitors)

修改相關檔案擁有者與群組。

1
2
3
4
$ chown -R ceph:ceph /etc/ceph
$ chown -R ceph:ceph /var/lib/ceph/mon
$ chown -R ceph:ceph /tmp/monmap
$ chown -R ceph:ceph /tmp/ceph.mon.keyring

初始化 Ceph MON。

1
$ ceph-mon --mkfs --id mon --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring

修改相關檔案擁有者與群組。

1
$ chown ceph:ceph -R /var/lib/ceph/mon

啟動 Ceph MON。

1
2
3
4
5
6
7
8
9
10
11
12
$ systemctl enable ceph-mon@mon.service
$ systemctl start ceph-mon@mon.service
$ systemctl status ceph-mon@mon.service

● ceph-mon@mon.service - Ceph cluster monitor daemon
Loaded: loaded (/lib/systemd/system/ceph-mon@.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-08-18 04:32:05 UTC; 33ms ago
Main PID: 21154 ((ceph-mon))
CGroup: /system.slice/system-ceph\x2dmon.slice/ceph-mon@mon.service
└─21154 (ceph-mon)

Aug 18 04:32:05 ceph systemd[1]: Started Ceph cluster monitor daemon.

Ceph MGR

建立 bootstrap keyrings。

1
$ ceph-create-keys --id mon

利用 client.admin key 建立名為 client.bootstrap-osd 的 ceph.keyring。

1
$ ceph-authtool -C ceph.keyring -n client.bootstrap-osd -a AQBp1lhdBuU7JRAAPx5h/9bsviXgNcbtGWulcA==

步驟內 AQBp1lhdBuU7JRAAPx5h/9bsviXgNcbtGWulcA== 為 client.admin key,可利用 cat ceph.client.admin.keyring 指令查詢。

將 key 增加至 auth entries 內並賦予對應存取權限。

1
$ ceph auth get-or-create mgr.mgr mon 'allow profile mgr' osd 'allow *' mds 'allow *'

mgr.mgr key 匯出並儲存於 keyring 檔案內。

1
$ ceph auth get-or-create mgr.mgr -o keyring

/var/lib/ceph/mgr/ 建立 ceph-mgr 目錄,並將 keyring 移至該目錄內。

1
2
$ mkdir -p /var/lib/ceph/mgr/ceph-mgr
$ mv keyring /var/lib/ceph/mgr/ceph-mgr

修改相關檔案擁有者與群組。

1
$ chown -R ceph:ceph /var/lib/ceph/mgr/ceph-mgr

啟動 Ceph MGR。

1
2
3
$ systemctl enable ceph-mgr@mgr.service
$ systemctl start ceph-mgr@mgr.service
$ systemctl status ceph-mgr@mgr.service

OSD

client.bootstrap-osd key 匯出並儲存於 /var/lib/ceph/bootstrap-osd/ 目錄下 ceph.keyring 檔案內。

1
$ ceph auth get client.bootstrap-osd -o /var/lib/ceph/bootstrap-osd/ceph.keyring

修改相關檔案擁有者與群組。

1
$ chown -R ceph:ceph /var/lib/ceph/bootstrap-osd

/dev/sdc1/dev/sdc4 作為 Ceph OSD。

1
2
3
4
$ ceph-volume lvm create --bluestore --data /dev/sdc1
$ ceph-volume lvm create --bluestore --data /dev/sdc2
$ ceph-volume lvm create --bluestore --data /dev/sdc3
$ ceph-volume lvm create --bluestore --data /dev/sdc4

修改相關檔案擁有者與群組。

1
2
3
4
$ chown -R ceph:ceph /var/lib/ceph/osd/ceph-0
$ chown -R ceph:ceph /var/lib/ceph/osd/ceph-1
$ chown -R ceph:ceph /var/lib/ceph/osd/ceph-2
$ chown -R ceph:ceph /var/lib/ceph/osd/ceph-3

在 Ceph CRUSH Map 中規劃 OSD01 - OSD04 host。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ ceph osd crush add-bucket OSD01 host

added bucket OSD01 type host to crush map

$ ceph osd crush add-bucket OSD02 host

added bucket OSD02 type host to crush map

$ ceph osd crush add-bucket OSD03 host

added bucket OSD03 type host to crush map

$ ceph osd crush add-bucket OSD04 host

added bucket OSD04 type host to crush map

將所有的 host(OSD01 - OSD04) 移至 default root 底下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ ceph osd crush move OSD01 root=default

moved item id -3 name 'OSD01' to location {root=default} in crush map

$ ceph osd crush move OSD02 root=default

moved item id -4 name 'OSD02' to location {root=default} in crush map

$ ceph osd crush move OSD03 root=default

moved item id -5 name 'OSD03' to location {root=default} in crush map

$ ceph osd crush move OSD04 root=default

moved item id -6 name 'OSD04' to location {root=default} in crush map

將 osd.0 - osd.4 綁定至對應的 OSD01 - OSD04 並賦予全部權重皆為 1.0。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ ceph osd crush add osd.0 1.0 root=default host=OSD01

add item id 0 name 'osd.0' weight 1 at location {host=OSD01,root=default} to crush map

$ ceph osd crush add osd.1 1.0 root=default host=OSD02

add item id 1 name 'osd.1' weight 1 at location {host=OSD02,root=default} to crush map

$ ceph osd crush add osd.2 1.0 root=default host=OSD03

add item id 2 name 'osd.2' weight 1 at location {host=OSD03,root=default} to crush map

$ ceph osd crush add osd.3 1.0 root=default host=OSD04

add item id 3 name 'osd.3' weight 1 at location {host=OSD04,root=default} to crush map

MDS

在 keyring 內增加 mds.mds key。

1
2
3
4
5
6
7
8
$ ceph-authtool --create-keyring keyring --gen-key -n mds.mds

[mds.mds]
key = AQDJ3Fhd4cISDRAAWKhKoqlGnmm39CaC5oTcWw==

$ ceph auth add mds.mds osd "allow rwx" mds "allow" mon "allow profile mds" -i keyring

added key for mds.mds

在 /var/lib/ceph/mds/ 建立 ceph-mds 目錄,並將 keyring 移至該目錄內。

1
2
$ mkdir -p /var/lib/ceph/mds/ceph-mds
$ mv keyring /var/lib/ceph/mds/ceph-mds

修改相關檔案擁有者與群組。

1
$ chown -R ceph:ceph /var/lib/ceph/mds/

啟動 Ceph MDS。

1
2
3
$ systemctl enable ceph-mds@mds.service
$ systemctl start ceph-mds@mds.service
$ systemctl status ceph-mds@mds.service

結果

利用 ceph -s 指令查詢當前 Ceph 叢集狀態。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@ceph:/etc/ceph# ceph -s
cluster:
id: cb9d566e-48e5-4810-9163-5c7784c8b3c0
health: HEALTH_OK

services:
mon: 1 daemons, quorum mon (age 30m)
mgr: mgr(active, since 18m)
osd: 4 osds: 4 up (since 12m), 4 in (since 12m)

data:
pools: 0 pools, 0 pgs
objects: 0 objects, 0 B
usage: 61 MiB used, 3.9 GiB / 4 GiB avail
pgs:

參考

評論

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×