這也是因為工作需求實作後才來寫的,
首先,
為何使用glusterfs,
因為成本低,
又能有HA的機制,
但想達到較好的效果,最好用實體主機+多硬碟建置.
(當然這樣又會跟成本起相沖...不然直接用硬體的storage就好了),
glusterfs的介紹與安裝可以參考Gluster Storage System(中文)
glusterfs nodes之間的結合有幾種不同的情況.
distributed - 當成是raid 0的概念
replicated - 當成是raid 1的概念,本文實作這類型
stripe - 當成是raid 0的概念,檔案被分拆成小部分平均存到nodes
dispersed - 當成是raid 5的概念
有些情況是可以換相結合的. EX : distributed + replicated ; stripe + replicated
確保資料的高可用性,
另外file type的選擇
xfs - 大於100G
ext4 - 其他
實作環境centos 6
192.168.0.11
192.168.0.12
安裝glusterfs server 3.7
# yum install centos-release-gluster
# yum install glusterfs-server
修改設定
vi /etc/nfsmount.conf
Lock=False
chkconfig glusterd on
service glusterd start
以下設定步驟在一台執行即可,192.168.0.11
gluster peer probe 192.168.0.12
gluster volume create datavol replica 2 transport tcp 192.168.0.11:/shared 192.168.0.12:/shared
gluster volume start datavol
gluster volume set datavol auth.allow 192.168.0.* # 允許網址符合192.168.0.*的主機可以連接到,若要新增條件以逗號(,)隔開
檢查一下
gluster peer status
gluster volume info
gluster volume status
這時如果client是linux,則可以安裝glusterclient,直接掛載多台gluster server作為備援
-----------------------------------------------------------------------
補充linux glusterfs client安裝
yum install glusterfs-client -y
掛載測試
mount.glusterfs 192.168.0.11:/datavol /mnt/glusterfs
開機掛載(/etc/fstab),選另一台作備援
192.168.0.11:/datavol /mnt/glusterfs glusterfs defaults,backupvolfile-server=192.168.0.12 0 0
-----------------------------------------------------------------------
因為在Glusterfs網站上說明,client連接的方式有三種,
1. glusterfs client(最佳解,限linux)
2. NFS (linux, windows)
3. CIFS (for windows,但linux也可指定用cifs來掛載
不過除了1.之外,其他的方式都是透過特定一個node來收集讀取資料和分散寫入資料,
這種方式顯然效能不佳,且感覺不到高可用性.
所以這邊在glusterfs servers安裝ctdb(samba的light cluster) + samba(提供cifs給windows掛載),
讓ctdb提供特定IP給clientm,用來連接到gluster volume.
並且CIFS並沒有提供lock的功能,但能藉由ctdb達到這項必備的功能
因為需要設定lock資料的存放位址,
此為址最好也是在shared disk上,
這邊就把glusterfs volume拿來用,(最好能設定在另一個共享磁碟上
mount -t glusterfs 127.0.0.1:/datavol /mnt/glusters
安裝samba + ctdb
yum install ctdb samba -y #相關的相依套件會自動安裝
設定samba,設定檔/etc/samba/smb.conf
在[global]下,
clustering = yes
idmap backend = tdb2
private dir = /mnt/glusters/lock/
自定義一個[share]的分享目錄
path = /mnt/glusters/share
available = yes
valid users = gluser
read only = no
browseable = yes
public = yes
writeable = yes
新增帳號samba valid user
useradd gluser
smbpasswd -a gluser
修改/mnt/glusters/share的擁有者
chown -R gluser.gluser /mnt/glusters/share
設定ctdb,設定檔/etc/sysconfig/ctdb
CTDB_RECOVERY_LOCK=/mnt/glusters/lock/.CTDB-lockfile
CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
CTDB_MANAGES_SAMBA=yes
CTDB_NODES=/etc/ctdb/nodes
設定Cluster Nodes,/etc/ctdb/nodes
192.168.0.11
192.168.0.12
設定Cluster VIPs,/etc/ctdb/public_addresses,但因為我是安裝在aws上,很悲劇的是AWS沒辦法設定VIP,請參考CTDB and GlusterFS,也就沒有failover的能力
192.168.0.13/24 eth1
192.168.0.14/24 eth1
(這兩個IP必須是未使用的)
-----------------------------------------------------------------------
補充 : AWS ec2 利用多IP,作failover的方式
Leveraging Multiple IP Addresses for Virtual IP Address Fail-over in 6 Simple Steps
裡面是介紹在VPC內至作兩台linux的HA nodes,利用EIP來達成.
-----------------------------------------------------------------------
service smb stop
chkconfig smb off
chkconfig ctdb on
service ctdb start
(ctdb會代管samba)
ctdb檢查指令
ctdb status
ctdb ip
ctdb ping -n all
ctdb scriptstatus # 當ctdb status不是OK時,檢查用
防火牆設定 /etc/sysconfig/iptables, 設定完重啟
# CIFS
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
# glusterfs bricks
-A INPUT -m state --state NEW -m tcp -p tcp --dport 24007:24050 -j ACCEPT
# glusterfs datavol-1 : datavol-2
-A INPUT -p tcp -m tcp -m state --dport 49152:49153 --state NEW -j ACCEPT
# CTDB
-A INPUT -m state --state NEW -m tcp -p tcp --dport 4379 -j ACCEPT
順利的話,此刻ctdb就有failover的功能,(AWS沒有VIP...)
但ctdb本身並沒有作load balance,
要達到分流的功能需要設定round-robin DNS(輪替式DNS),
基本就是一個domain name對應多個IP,讓DNS幫你作分流.
Windows 2012r2 Clinet
直接輸入\\domain-name\share即可
IIS Web Site使用共享目錄的權限設定
1. IIS不能使用磁碟機代號,需用UNC的方式
2. Windows 本身需要新增一組使用者跟samba user的帳密相同,並將其加入IIS群組
3. 到IIS管理畫面,"應用程式集區"->選取該網站使用的應用程式集區 -> 進階設定 -> 修改"識別"為剛新增的帳號
參考
Explore high availability of GlusterFS through CTDB
Windows (CIFS) fileshares using GlusterFS and CTDB for Highly available data
How Do I Setup IIS to Allow it to Use Network Resources?