mysql存储数据到cephfs_采用cephfs实现Elasticsearch数据持久化
一、cephfs
參考了以下文章
在172.20.0.10上搭建了三節(jié)點(diǎn)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
每節(jié)點(diǎn)上掛在了一塊300G數(shù)據(jù)云盤(采用lvm創(chuàng)建分區(qū),方便以后擴(kuò)容),在每個(gè)節(jié)點(diǎn)上將格式化后的文件系統(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)
后續(xù)可以參考之前給出的兩篇文章完成cephfs的創(chuàng)建,然后將cephfs掛載到本地
[root@node1 ~]# mount -t ceph :6789:/ /opt -o name=admin,secret=
其中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=,acl,wsize=16777216)
然后在cephfs中創(chuàng)建出后續(xù)需要的三個(gè)目錄
[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
使用簡單,建議使用。
在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é)點(diǎn)
path: /elasticsearch_node1? ? ? ? ? ? ? ? ? ? ? ?#之前創(chuàng)建的目錄
secretRef:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#引用訪問cephfs的secret
name: ceph-secret
2.persistent storage架構(gòu)圖
data數(shù)據(jù)會(huì)被永久保存到cephfs中,除非在elasticsearch中刪除相關(guān)index;或者將cephfs掛載到本地,然后將elasticsearch_node[123]中的內(nèi)容刪除。
這里特別要注意的是elasticsearch_node[123]目錄的權(quán)限問題,用之前方式創(chuàng)建出來的目錄用戶為root:root,但是在elasticsearch中需要elasticsearch用戶來運(yùn)行elasticsearch進(jìn)程,并將數(shù)據(jù)保存在data中,在elasticsearch的docker image中,已添加更改目錄所有者操作,將elasticsearch_node[123]的所有者改為elasticsearch:root,對外映射看到的所有者為1000:root。
3.為什么要?jiǎng)?chuàng)建3個(gè)replicaset來管理3個(gè)elasticsearch pod實(shí)例,而不是在一個(gè)replicaset中將replicas設(shè)置為3 ?
在沒有添加cephfs存儲(chǔ)之前,采用的是使用一個(gè)replicaset來管理3個(gè)elasticsearch pod。
每個(gè)elasticsearch需要不同的空間來存儲(chǔ)自己的data數(shù)據(jù),不能在replicaset中設(shè)置replicas為3,這樣會(huì)導(dǎo)致每個(gè)elasticsearch的/usr/share/elasticsearch/data目錄掛載到相同cephfs目錄下。不建議在一個(gè)pod中創(chuàng)建創(chuàng)建3個(gè)container來掛載不同cephfs的目錄,這樣雖然能工作,但是這些container在同一個(gè)worker node上會(huì)導(dǎo)致該node負(fù)載過重。
三、persistent volume and persistent volume claim
pv/pvc原理同persistent storage類似,此處僅給出相關(guān)原理便于理解。
pv/pvc架構(gòu)圖
需要以下幾點(diǎn)
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中的大小(通常不是),具體能存放多少數(shù)據(jù)取決于cephfs。pv聲明的存儲(chǔ)大小是為了pvc選擇能夠滿足其需求的pv時(shí)使用。
pv是一類cluster level級(jí)別的資源,不屬于任何namespace,所以可以被任何namespace中pvc使用。
以cephfs為后端存儲(chǔ)的pv,經(jīng)過驗(yàn)證,其persistentVolumeReclaimPolicy只支持Retain,而不支持Delete和Recycle。意味著刪除pvc后,pv中的數(shù)據(jù)(其實(shí)是存儲(chǔ)在cephfs文件系統(tǒng)中的數(shù)據(jù))不會(huì)被刪除,但此時(shí)該pv不能再被任何pvc所使用,只能刪除該pv然后重新創(chuàng)建。因?yàn)閿?shù)據(jù)存儲(chǔ)在cephfs文件系統(tǒng)中,所以不用擔(dān)心數(shù)據(jù)會(huì)丟失。Delete會(huì)將數(shù)據(jù)刪除,Recycle將數(shù)據(jù)刪除后重新創(chuàng)建pv以為其他pvc提供服務(wù)。
四、后期優(yōu)化
cephfs讀寫性能。
需要對cephfs的讀寫性能進(jìn)行優(yōu)化,否則elasticsearch在初始化時(shí)需要較長時(shí)間。如果發(fā)現(xiàn)elasticsearch一直無法初始化完成(kubectl get pod 發(fā)現(xiàn)ready的數(shù)量為0),可能是liveness檢測的initialDelaySeconds時(shí)間過短,導(dǎo)致elasticsearch還未完成初始化就被liveness kill掉然后重啟了相關(guān)pod,可以將這個(gè)值設(shè)置得更長一些。
超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的mysql存储数据到cephfs_采用cephfs实现Elasticsearch数据持久化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql在linux下配置_mysql
- 下一篇: postgresql主从备份_Postg