GlusterFS 是開源分布式文件系統,通過彈性哈希算法定位文件,無需元數據服務器,避免單點故障,適合大數據量離線應用、網絡存儲、冗余備份場景。本文記錄基於 CentOS 6.5 雙節點部署複製卷的完整過程。
| 節點 | IP | 主機名 | 存儲目錄 |
|---|---|---|---|
| g1 | 192.168.0.107 | g1 | /data |
| g2 | 192.168.0.136 | g2 | /data |
# 關閉防火牆與 SELinux
service iptables stop
chkconfig iptables off
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 設置主機名與 hosts 映射
echo "g1" > /etc/hostname
hostname g1
cat >> /etc/hosts <<'EOF'
192.168.0.107 g1
192.168.0.136 g2
EOF
g2 節點同理修改為 g2 對應信息。
yum install -y gcc gcc-c++ flex flex-devel bison bison-devel openssl openssl-devel libxml2 libxml2-devel
# FUSE 2.9.3
tar zxvf fuse-2.9.3.tar.gz
cd fuse-2.9.3
./configure && make && make install
# GlusterFS 3.6.0
tar zxvf glusterfs-3.6.0.tar.gz
cd glusterfs-3.6.0
./configure --prefix=/usr/local/glusterfs && make && make install
兩節點均需執行上述編譯安裝。
# 啟動 glusterd
service glusterd start
# 創建命令軟鏈接
ln -s /usr/local/glusterfs/sbin/gluster /usr/bin/gluster
# g1 節點將 g2 加入集群
gluster peer probe g2
# 輸出: peer probe: success
gluster peer status
# Number of Peers: 1
# Hostname: g2
# State: Peer in Cluster (Connected)
# 創建雙副本卷 (replica 2)
gluster volume create test-volume replica 2 transport tcp g1:/data g2:/data force
# 啟動卷
gluster volume start test-volume
# 查看卷信息
gluster volume info
關鍵參數:
replica 2:雙副本,數據寫入兩節點
transport tcp:TCP 傳輸協議
force:強制覆蓋非空目錄
客戶端需同樣安裝 FUSE 與 GlusterFS 客戶端。
mkdir /mnt/gfs
mount -t glusterfs g1:test-volume /mnt/gfs
df -h
輸出顯示 g1:test-volume 掛載成功,容量與單節點一致(複製卷不疊加容量)。g2 節點同理掛載 g2:test-volume 可達到同樣效果,實現客戶端就近訪問。
| 操作 | 命令 |
|---|---|
| 查看卷狀態 | gluster volume status test-volume |
| 擴容添加磚塊 | gluster volume add-brick test-volume g3:/data |
| 縮容移除磚塊 | gluster volume remove-brick test-volume g2:/data start |
| 重新平衡數據 | gluster volume rebalance test-volume start |
| 設置配額 | gluster volume quota test-volume limit-usage / 100GB |
| 開啟配額 | gluster volume quota test-volume enable |
| 查看幫助 | gluster help |
disperse (EC) 卷類型節省空間backup-volfile-servers=g2:test-volume 實現故障切換gluster volume profile 指標GlusterFS 以去中心化架構解決了傳統分布式存儲的元數據瓶頸,雙節點複製卷部署簡單,適合中小規模非核心業務存儲。生產環境建議 3 節點起步,配合仲裁機制確保數據一致性,並制定完善的災備演練預案。