[TOC]
系統:CentOS7,<code>/data</code>為非系統分區挂載目錄
docker:1.13.1
kubernetes:1.11.1
glusterfs:4.1.2
2個節點,192.168.105.97、192.168.105.98
使用yum安裝
<code>CentOS-Gluster-4.1.repo</code>
啟動及設定開機啟動
GlusterFS通過24007端口互相通信。防火牆需要開放端口。
<code>/etc/hosts</code>
在主機<code>glu1</code>上執行
檢視叢集狀态(節點間互相看到對方資訊)
GlusterFS 幾種volume模式說明:
連結中比較直覺:https://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/
預設模式,既DHT, 也叫分布卷: 将檔案已hash算法随機分布到 一台伺服器節點中存儲。
指令格式:<code>gluster volume create test-volume server1:/exp1 server2:/exp2</code>
複制模式,既AFR, 建立volume 時帶 replica x 數量: 将檔案複制到 replica x 個節點中,現在已經推薦3節點仲裁者複制模式,因為2節點可能産生腦裂。
指令格式:<code>gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2</code>
<code>gluster volume create test-volume replica 3 arbiter 1 transport tcp server1:/exp1 server2:/exp2 server3:/exp3</code>
分布式複制模式,至少4節點。
指令格式:<code>gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4</code>
分散模式,最少需要3節點
指令格式:<code>gluster volume create test-volume disperse 3 server{1..3}:/bricks/test-volume</code>
分布式分散模式,建立一個分布式分散體積,分散關鍵字和<數量>是強制性的,指定的磚塊在指令行中的數量必須是分散數的倍數
指令格式:<code>gluster volume create &lt;volname&gt; disperse 3 server1:/brick{1..6}</code>
列一些Glusterfs調優:
###3.1 實體機上使用GlusterFS的volume
以下操作在kubernetes master節點操作
<code>vim /etc/kubernetes/glusterfs/glusterfs-endpoints.json</code>
注意: 該subsets字段應填充GlusterFS叢集中節點的位址。可以在port字段中提供任何有效值(從1到65535)。
我們還需要為這些端點建立服務,以便它們能夠持久存在。我們将在沒有選擇器的情況下添加此服務,以告知Kubernetes我們想要手動添加其端點
<code>vim glusterfs-service.json</code>
建立glusterfs-pv.yaml檔案,指定storage容量和讀寫屬性
<code>vim glusterfs-pv.yaml</code>
建立<code>glusterfs-pvc.yaml</code>檔案,指定請求資源大小
<code>vim glusterfs-pvc.yaml</code>
以建立nginx,把pvc挂載到容器内的<code>/usr/share/nginx/html</code>檔案夾為例:
<code>vim glusterfs-nginx-deployment.yaml</code>
驗證結果:
至此部署完成。
此文GlusterFS是安裝在實體系統下,而非kubernetes中,所有需要手工維護,下次介紹在kubernetes中安裝使用gluster。GlusterFS的volume模式根據業務靈活應用。需要注意的是,如果使用分布卷,pod中的挂載目錄檔案可能存在卷的任一節點中,可能并非直接<code>df -h</code>看到的那個節點中。
參數資料:
[1] https://kubernetes.io/docs/concepts/storage/persistent-volumes/
[2] https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
[3] https://www.kubernetes.org.cn/4069.html
[4] https://www.gluster.org/
[5] https://blog.csdn.net/hxpjava1/article/details/79817078
[6] https://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/
[7] https://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Clients/
[8] https://github.com/kubernetes/examples/blob/master/staging/volumes/glusterfs/README.md