eph是一個統一的分布式存儲系統,提供較好的性能、可靠性和可擴展性。Ceph的主要目標是設計成基于POSIX的沒有單點故障的分布式文件系統,使數據能容錯和無縫的復制。
一、準備服務器
1、SSH免密碼登錄
[root@ceph-1 ~]# ssh-keygen
[root@ceph-1 ~]# ssh-copy-id root@ceph-2
[root@ceph-1 ~]# ssh-copy-id root@ceph-3
2、時間同步
[root@ceph-1 ~]# vim /etc/chrony.conf
添加:
server 20.0.0.202 iburst
[root@ceph-1 ~]# scp /etc/chrony.conf root@ceph-2:/etc/
[root@ceph-1 ~]# scp /etc/chrony.conf root@ceph-3:/etc/
注意:ceph-1、ceph-2和ceph-3都要重啟chronyd服務。
[root@ceph-1 ~]# systemctl restart chronyd
[root@ceph-1 ~]# chronyc sources -v
3、添加硬盤
(1)ceph-1、ceph-2和ceph-3服務器中各添加一塊硬盤。
[root@ceph-1 ~]# lsblk
[root@ceph-2 ~]# lsblk
[root@ceph-3 ~]# lsblk
(2)格式硬盤
[root@ceph-1 ~]# mkfs.xfs /dev/sdb
[root@ceph-2 ~]# mkfs.xfs /dev/sdb
[root@ceph-3 ~]# mkfs.xfs /dev/sdb
二、部署ceph
目前Ceph官方提供三種部署Ceph集群的方法,分別是ceph-deploy,cephadm和手動安裝:
1、在所有節點ceph-1安裝工具
(1)準備yum源
[root@ceph-1 ~]# vim /etc/yum.repos.d/ceph.repo
添加:
[Ceph]
name=Ceph packages for $basearch
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el8/x86_64/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[Ceph-noarch]
name=Ceph noarch packages
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el8/noarch/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[ceph-source]
name=Ceph source packages
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el8/SRPMS/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[root@ceph-1 ~]# scp /etc/yum.repos.d/ceph.repo root@ceph-2:/etc/yum.repos.d/
[root@ceph-1 ~]# scp /etc/yum.repos.d/ceph.repo root@ceph-3:/etc/yum.repos.d/
[root@ceph-1 ~]# yum install epel-release -y
[root@ceph-1 ~]# yum clean all && yum makecache
(2)在所有節點上部署ceph軟件
[root@ceph-1 ~]# yum -y install ceph
[root@ceph-1 ~]# yum install -y ceph-common
[root@ceph-1 ~]# ceph --version
2、創建管理節點
(2)在ceph-1創建管理節點
[root@ceph-1 ~]# yum install -y cephadm
[root@ceph-1 ~]# cd /etc/ceph/
[root@ceph-1 ceph]# cephadm bootstrap --mon-ip 192.168.1.201
(3)訪問ceph UI界面。注意:首次登陸要修改密碼,進行驗證。
[root@ceph-1 ~]# podman images
[root@ceph-1 ~]# podman ps -a
cephadm shell命令在安裝了所有Ceph包的容器中啟動一個bash shell
[root@ceph-1 ~]# cephadm shell
[root@ceph-1 ~]# cephadm install ceph-common
或者
[root@ceph-1 ~]# yum install -y ceph-common
[root@ceph-1 ~]# ceph -v
[root@ceph-1 ~]# ceph status
[root@ceph-1 ~]# ceph health
3、創建ceph群集
[root@ceph-1 ~]# ssh-copy-id -f -i /etc/ceph/ceph.pub root@ceph-2
[root@ceph-1 ~]# ssh-copy-id -f -i /etc/ceph/ceph.pub root@ceph-3
[root@ceph-1 ~]# ceph orch host add ceph-2
[root@ceph-1 ~]# ceph orch host add ceph-3
[root@ceph-1 ~]# ceph status
4、部署添加monitor
(1)設置公共網段,以便client訪問
[root@ceph-1 ~]# ceph config set mon public_network 192.168.1.0/24
(2)設置monitor節點
[root@ceph-1 ~]# ceph orch host label add ceph-1 mon
[root@ceph-1 ~]# ceph orch host label add ceph-2 mon
[root@ceph-1 ~]# ceph orch host label add ceph-3 mon
[root@ceph-1 ~]# ceph orch host ls
(3)各節點拉取images并啟動容器
[root@ceph-1 ~]# ceph orch apply mon label:mon
查看ceph-2的鏡像和容器運行情況
查看ceph-3的鏡像和容器運行情況
(4)查看ceph群集健康狀態
[root@ceph-1 ~]# ceph -s
5、部署OSD
(1)查看查看硬盤
[root@ceph-1 ~]# ceph orch device ls
(2)添加硬盤
[root@ceph-1 ceph]# ceph orch daemon add osd ceph-1:/dev/sdb
[root@ceph-1 ceph]# ceph orch daemon add osd ceph-2:/dev/sdb
[root@ceph-1 ceph]# ceph orch daemon add osd ceph-3:/dev/sdb
(3)查看添加硬盤情況
[root@ceph-1 ceph]# ceph osd df
(4)查看群集健康
[root@ceph-1 ceph]# ceph -s
6、部署MDS
[root@ceph-1 ceph]# ceph orch apply mds ceph-cluster --placement=3
[root@ceph-1 ceph]# ceph -s
7、部署RGW
(1)創建一個領域
[root@ceph-1 ceph]# radosgw-admin realm create --rgw-realm=my-rgw --default
(2)創建一個zonegroup
[root@ceph-1 ~]# radosgw-admin zonegroup create --rgw-zonegroup=my-rgwgroup --master --default
(3)創建一個區域
[root@ceph-1 ceph]# radosgw-admin zone create --rgw-zonegroup=my-rgwgroup --rgw-zone=my-zone-1 --master --default
(4)部署一組radosgw守護進程
[root@ceph-1 ceph]# ceph orch apply rgw my-rgw my-zone-1 --placement="2 ceph-2 ceph-3"
(5)查看RGW部署情況
[root@ceph-1 ceph]# ceph -s
(6)為RGW開啟dashborad創建管理用戶
[root@ceph-1 ceph]# radosgw-admin user create --uid=admin --display-name=admin --system
(7)設置dashboard憑證
注意:使用rgw的管理用戶的Key。
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-access-key VKIC8KNA7Q75P1PT8JVA
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-secret-key EEqJMI7zEgK1MPSWSAM4vZJRbLkmaQZs8czJez9B
設置
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-ssl-verify False
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-scheme http
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-host 192.168.1.0/24
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-port 80
[root@ceph-1 ceph]# ceph dashboard set-rgw-api-user-id admin
(8)重啟RGW
[root@ceph-1 ceph]# ceph orch restart rgw
(4)修改ceph配置文件
[root@ceph-1 ~]# vim /etc/ceph/ceph.conf
添加:
public network=192.168.1.0/24
cluster network=192.168.1.0/24
osd_pool_default_size=2
mon_clock_drift_allowed=2 ##增大mon之間時差
[mon]
mon allow pool delete=true ##允許刪除pool
掛載使用
[root@ceph-1 ~]# rados df
[root@ceph-1 ~]# ceph osd lspools
三、創建ceph文件系統
1、創建存儲池
[root@ceph-1 ceph]# ceph fs ls
一個 Ceph 文件系統需要至少兩個 RADOS 存儲池,一個用于數據、一個用于元數據。配置這些存儲池時需考慮:
為元數據存儲池設置較高的副本水平,因為此存儲池丟失任何數據都會導致整個文件系統失效。
為元數據存儲池分配低延時存儲器(像 SSD ),因為它會直接影響到客戶端的操作延時。
[root@ceph-1 ceph]# ceph osd pool create cephfs_data 128
[root@ceph-1 ceph]# ceph osd pool create cephfs_metadata 128
注:關于創建存儲池
確定 pg_num 取值是強制性的,因為不能自動計算。下面是幾個常用的值:
*少于 5 個 OSD 時可把 pg_num 設置為 128
*OSD 數量在 5 到 10 個時,可把 pg_num 設置為 512
*OSD 數量在 10 到 50 個時,可把 pg_num 設置為 4096
*OSD 數量大于 50 時,你得理解權衡方法、以及如何自己計算 pg_num 取值
刪除存儲池pool
2、創建文件系統
[root@ceph-1 ceph]# ceph fs new cephfs_dodo cephfs_metadata cephfs_data
查看創建后的cephfs
[root@ceph-1 ceph]# ceph fs ls
查看mds節點狀態
查看存儲池pool
[root@ceph-1 ceph]# rados lspools
或者
[root@ceph-1 ceph]# ceph osd lspools
[root@ceph-1 ceph]# rados df
3、掛載Ceph文件系統
(1)創建掛載點
[root@client ~]# mkdir /dodo
(2)內核驅動掛載Ceph文件系統
準備秘鑰
[root@ceph-1 ceph]# cat /etc/ceph/ceph.client.admin.keyring
將ceph服務器的秘鑰復制到Client中。
[root@client ~]# mkdir /etc/ceph/
[root@client ~]# vim /etc/ceph/admin.secret
添加:
AQAc879eIBHNIhAAhmLPJSe758tL9lyqNL5aZw==掛載
[root@client ~]# mount -t ceph 192.168.1.201:6789:/ /dodo/ -o name=admin,secret=AQAc879eIBHNIhAAhmLPJSe758tL9lyqNL5aZw==或者
[root@client ~]# mount -t ceph 192.168.1.201:6789:/ /dodo -o name=admin,secretfile=/etc/ceph/admin.secret
[root@client ~]# mount | grep ceph
[root@client ~]# df -h
取消掛載
[root@client ~]# umount /dodo
(3)用戶控件掛載Ceph文件系統
安裝ceph-fuse
[root@client ~]# yum install epel-release -y
[root@client ~]# yum install -y ceph-fuse
拷貝ceph配置和秘鑰文件
[root@ceph-1 ~]# scp /etc/ceph/ceph.* client:/etc/ceph/
注意:將ceph配置和秘鑰文件權限設置為644
[root@client ~]# chmod 644 /etc/ceph/*
掛載
[root@client ~]# ceph-fuse -m 192.168.1.201:6789 /dodo
[root@client ~]# df -h
取消掛載
[root@client ~]# fusermount -u /dodo
四、kubernetes應用ceph
(一)準備ceph存儲
1、創建存儲池pool
[root@ceph-1 ceph]# ceph osd pool create dodo-cephfs 64
2、Ceph上準備K8S客戶端賬號
[root@ceph-1 ceph]# ceph auth get-or-create client.dodo mon 'allow r' osd 'allow rwx pool=dodo-cephfs' -o dodo-cephfs.k8s.keyring
3、獲取賬號的密鑰
[root@ceph-1 ceph]# ceph auth get-key client.admin | base64
秘鑰為:QVFBYzg3OWVJQkhOSWhBQWhtTFBKU2U3NTh0TDlseXFOTDVhWnc9PQ==
(二)在客戶端(k8s-node-1、k8s-node-2和k8s-master)上安裝ceph
注意:客戶端版本與ceph集群的版本保持一致。
1、安裝ceph
[root@k8s-master ~]# vim /etc/yum.repos.d/ceph.repo
添加:
[Ceph]
name=Ceph packages for $basearch
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el7/x86_64/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[Ceph-noarch]
name=Ceph noarch packages
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el7/noarch/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[ceph-source]
name=Ceph source packages
baseurl=https://mirrors.aliyun.com/ceph/rpm-octopus/el7/SRPMS/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
[root@k8s-master ~]# scp /etc/yum.repos.d/ceph.repo 192.168.1.1:/etc/yum.repos.d/
[root@k8s-master ~]# scp /etc/yum.repos.d/ceph.repo 192.168.1.2:/etc/yum.repos.d/
[root@k8s-master ~]# yum install epel-release -y
[root@k8s-master ~]# yum -y install ceph-common
[root@k8s-master ~]# ceph --version
2、將ceph群集中的配置文件ceph.conf拷貝到所有節點的/etc/ceph目錄下
[root@ceph-1 ~]# scp /etc/ceph/ceph.conf 192.168.1.1:/etc/ceph/
[root@ceph-1 ~]# scp /etc/ceph/ceph.conf 192.168.1.2:/etc/ceph/
[root@ceph-1 ~]# scp /etc/ceph/ceph.conf 192.168.1.3:/etc/ceph/
3、將caph集群的ceph.client.admin.keyring文件放在k8s控制節點的/etc/ceph目錄
[root@ceph-1 ~]# scp /etc/ceph/dodo-cephfs.k8s.keyring 192.168.1.1:/etc/ceph/
[root@ceph-1 ~]# scp /etc/ceph/dodo-cephfs.k8s.keyring 192.168.1.2:/etc/ceph/
[root@ceph-1 ~]# scp /etc/ceph/dodo-cephfs.k8s.keyring 192.168.1.3:/etc/ceph/
4、生成加密key
[root@ceph-1 ~]# grep key /etc/ceph/ceph.client.admin.keyring |awk '{printf "%s", $NF}'|base64
QVFBYzg3OWVJQkhOSWhBQWhtTFBKU2U3NTh0TDlseXFOTDVhWnc9PQ==
5、創建ceph的secret
[root@k8s-master ~]# vim ceph-secret.yaml
添加:
apiVersion: v1
kind: Secret
metadata:
name: ceph-secret
type: "kubernetes.io/rbd"
data:
key: QVFBYzg3OWVJQkhOSWhBQWhtTFBKU2U3NTh0TDlseXFOTDVhWnc9PQ==
[root@k8s-master ~]# kubectl apply -f ceph-secret.yaml
[root@k8s-master ~]# kubectl get secrets ceph-secret
6、創建存儲類
[root@k8s-master ~]# vim ceph-class.yaml
添加:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: test-ceph
provisioner: kubernetes.io/rbd
parameters:
monitors: 192.168.1.201:6789
adminId: admin
adminSecretName: ceph-secret
adminSecretNamespace: default
pool: dodo-cephfs
userId: admin
userSecretName: ceph-secret
7、應用ceph
[root@k8s-master ~]# vim ceph-web.yaml
添加:
apiVersion: v1
kind: Service
metadata:
name: ceph-web
labels:
app: ceph-web
spec:
type: NodePort
selector:
app: ceph-web
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: ceph-web
spec:
serviceName: "ceph-web"
replicas: 2
selector:
matchLabels:
app: ceph-web
template:
metadata:
labels:
app: ceph-web
spec:
containers:
- name: nginx
image: nginx:1.17
ports:
- name: http
containerPort: 80
volumeMounts:
- name: test-storage
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: test-storage
spec:
storageClassName: test-ceph
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 3Gi
[root@k8s-master ~]# kubectl apply -f ceph-web.yaml
[root@k8s-master ~]# kubectl get pod -o wide
[root@k8s-master ~]# kubectl get pv
[root@k8s-master ~]# kubectl get pvc
連接容器查看掛載情況
添加測試文件
[root@k8s-master ~]# kubectl exec -it ceph-web-0 -- /bin/bash
root@ceph-web-0:/# echo "welcome to POD:ceph-web-0!!!" > /usr/share/nginx/html/index.html
[root@k8s-master ~]# kubectl exec -it ceph-web-1 -- /bin/bash
root@ceph-web-1:/# df -hT
[root@k8s-master ~]# kubectl exec -it ceph-web-1 -- /bin/bash
root@ceph-web-1:/# echo "welcome to POD:ceph-web-1!!!" > /usr/share/nginx/html/index.html
訪問:
注:以輪訓的方式顯示。
上次找了一臺物理服務器直接安裝了一個proxmox VE 環境(VE是虛擬化環境的意思),后續又看了官方的admin文檔,對整個系統架構有了一定的了解,接下來,準備好好研究一下具體能夠落在生產環境上的系統設計。官方文檔可以在官網下載,也可以在安裝pve之后在web界面上直接查看或者下載,如下圖:
設計思路:
基本想法是,3個以上物理節點的集群環境,組成HA,具體設想如下: