溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

cephfs中怎么實現(xiàn)Elasticsearch數(shù)據(jù)持久化

發(fā)布時間:2021-06-24 17:30:39 來源:億速云 閱讀:283 作者:Leah 欄目:云計算

cephfs中怎么實現(xiàn)Elasticsearch數(shù)據(jù)持久化,針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

一、cephfs

cephfs創(chuàng)建

  1. 在172.20.0.10上搭建了三節(jié)點ceph cluster

10.0.169.87         node1.cephfs-cluster (mons at {node1=10.0.169.87:6789/0})
10.0.149.141       node2.cephfs-cluster
10.0.235.158       node3.cephfs-cluster

  1. 每節(jié)點上掛在了一塊300G數(shù)據(jù)云盤(采用lvm創(chuàng)建分區(qū),方便以后擴容),在每個節(jié)點上將格式化后的文件系統(tǒng)掛載到/var/local/osd[123]

[root@node1 ~]# mount -l | grep cephfs
/dev/mapper/vg--for--cephfs-lvm--for--cephfs on /var/local/osd1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

[root@node2 ~]# mount -l | grep cephfs
/dev/mapper/vg--for--cephfs-lvm--for--cephfs on /var/local/osd2 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

[root@node3 ~]# mount -l | grep cephfs
/dev/mapper/vg--for--cephfs-lvm--for--cephfs on /var/local/osd3 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

  1. 后續(xù)可以參考之前給出的兩篇文章完成cephfs的創(chuàng)建,然后將cephfs掛載到本地
     [root@node1 ~]# mount -t ceph <monitor-ip>:6789:/ /opt -o name=admin,secret=<admin-key>
    其中admin-key用如下方式獲取
    [root@node1 opt]# ceph auth get client.admin

[root@node1 ~]# mount -l | grep opt
10.0.169.87:6789:/ on /opt type ceph (rw,relatime,name=admin,secret=<hidden>,acl,wsize=16777216)

  1. 然后在cephfs中創(chuàng)建出后續(xù)需要的三個目錄

[root@node1 opt]# pwd
/opt
[root@node1 opt]# ll
總用量 0
drwxr-xr-x 1 1000 root 1 8月 1 22:07 elasticsearch_node1
drwxr-xr-x 1 1000 root 1 8月 1 22:07 elasticsearch_node2
drwxr-xr-x 1 1000 root 1 8月 1 22:07 elasticsearch_node3

二、persistent storage

使用簡單,建議使用。

  1. 在elasticsearch/persistent_storage目錄下有如下文件。

drwxr-xr-x. 2 root root 30 7月 31 14:42 cephfs  (包含文件 -rw-r--r--. 1 root root 173 7月 30 15:20 ceph-secret.yaml)

-rw-r--r--. 1 root root 1115 7月 31 15:50 replicset_elasticsearch_1.yaml
-rw-r--r--. 1 root root 1115 7月 31 15:50 replicset_elasticsearch_2.yaml
-rw-r--r--. 1 root root 1115 7月 31 15:50 replicset_elasticsearch_3.yaml

  • 其中cephfs的secret文件用于在k8s中創(chuàng)建出secret資源,保存了訪問cephfs的key等信息。

  • replicaset_elasticsearch_1.yaml中需要注意以下內(nèi)容

   volumeMounts:
   -  name: cephfs
       mountPath: /usr/share/elasticsearch/data     #將cephfs中的elsticsearch_node1掛載到pod elasticsearch_node1中的/usr/share/elasticsearch/data目錄下。
volumes:
-  name: cephfs
   cephfs:
      monitors:
      -  10.0.169.87:6789                                   # cephfs的管理節(jié)點
      path: /elasticsearch_node1                       #之前創(chuàng)建的目錄
      secretRef:                                                 #引用訪問cephfs的secret
      name: ceph-secret

2.persistent storage架構(gòu)圖

  data數(shù)據(jù)會被永久保存到cephfs中,除非在elasticsearch中刪除相關(guān)index;或者將cephfs掛載到本地,然后將elasticsearch_node[123]中的內(nèi)容刪除。

  這里特別要注意的是elasticsearch_node[123]目錄的權(quán)限問題,用之前方式創(chuàng)建出來的目錄用戶為root:root,但是在elasticsearch中需要elasticsearch用戶來運行elasticsearch進程,并將數(shù)據(jù)保存在data中,在elasticsearch的docker image中,已添加更改目錄所有者操作,將elasticsearch_node[123]的所有者改為elasticsearch:root,對外映射看到的所有者為1000:root。

cephfs中怎么實現(xiàn)Elasticsearch數(shù)據(jù)持久化

3. 為什么要創(chuàng)建3個replicaset來管理3個elasticsearch pod實例,而不是在一個replicaset中將replicas設(shè)置為3 ?

在沒有添加cephfs存儲之前,采用的是使用一個replicaset來管理3個elasticsearch pod。

每個elasticsearch需要不同的空間來存儲自己的data數(shù)據(jù),不能在replicaset中設(shè)置replicas為3,這樣會導(dǎo)致每個elasticsearch的/usr/share/elasticsearch/data目錄掛載到相同cephfs目錄下。不建議在一個pod中創(chuàng)建創(chuàng)建3個container來掛載不同cephfs的目錄,這樣雖然能工作,但是這些container在同一個worker node上會導(dǎo)致該node負載過重。

三、persistent volume and persistent volume claim

pv/pvc原理同persistent storage類似,此處僅給出相關(guān)原理便于理解。

  1. pv/pvc架構(gòu)圖
    cephfs中怎么實現(xiàn)Elasticsearch數(shù)據(jù)持久化

  2. 需要以下幾點

  • persitent storage和pv/pvc一樣都是利用cephfs提供的posix接口將cephfs掛載到相應(yīng)的worker node上后再利用docker volume將該目錄掛載到container中,可在相應(yīng)worker node上利用docker inspect查看container的mount信息。

  • pv/pvc中聲明的大小可能并非cephfs中的大?。ㄍǔ2皇牵唧w能存放多少數(shù)據(jù)取決于cephfs。pv聲明的存儲大小是為了pvc選擇能夠滿足其需求的pv時使用。

  • pv是一類cluster level級別的資源,不屬于任何namespace,所以可以被任何namespace中pvc使用。

  • 以cephfs為后端存儲的pv,經(jīng)過驗證,其persistentVolumeReclaimPolicy只支持Retain,而不支持Delete和Recycle。意味著刪除pvc后,pv中的數(shù)據(jù)(其實是存儲在cephfs文件系統(tǒng)中的數(shù)據(jù))不會被刪除,但此時該pv不能再被任何pvc所使用,只能刪除該pv然后重新創(chuàng)建。因為數(shù)據(jù)存儲在cephfs文件系統(tǒng)中,所以不用擔心數(shù)據(jù)會丟失。Delete會將數(shù)據(jù)刪除,Recycle將數(shù)據(jù)刪除后重新創(chuàng)建pv以為其他pvc提供服務(wù)。

四、后期優(yōu)化

  1. cephfs讀寫性能。
    需要對cephfs的讀寫性能進行優(yōu)化,否則elasticsearch在初始化時需要較長時間。如果發(fā)現(xiàn)elasticsearch一直無法初始化完成(kubectl get pod 發(fā)現(xiàn)ready的數(shù)量為0),可能是liveness檢測的initialDelaySeconds時間過短,導(dǎo)致elasticsearch還未完成初始化就被liveness kill掉然后重啟了相關(guān)pod,可以將這個值設(shè)置得更長一些。

關(guān)于cephfs中怎么實現(xiàn)Elasticsearch數(shù)據(jù)持久化問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI