天天看點

SeaweedFS 高可用方案最佳實踐

作者:冰心de小屋

1. 目标

本方案主要解決單節點故障對叢集造成的影響,保證檔案的完整性、叢集功能的正确性。

2. 方案内容

SeaweedFS 高可用方案最佳實踐
  1. Master 節點至為 3 個,部署不同實體主機,啟動過程中設定參數 defaultReplication=001(相同 rack 備份 1 份資料)。
  2. Volume 檔案節點至少為 3 個,分别部署不同實體主機。
  3. Filer 管理檔案中繼資料資訊,友善檔案操作,filer 節點至少 2 個。
  4. 采用 Cassandra 分布式資料庫存儲檔案資料資訊,叢集節點數至少為 3 個。

3. 方案說明

  1. Master 節點管理資料卷和檔案 ID 的配置設定工作,為了保證可用性,通常部署 3 個,Master 節點間通過 Raft 協定選舉主 Master,非主 Master 會将請求轉發給主 Master。
  2. Volume 檔案節點至少為了 3 個平衡資料配置設定,防止單節點資料過大。
  3. Filer 至少 2 個,通常在 Filer 之前會配置 Nginx 用于統一通路和負載均衡。
  4. Filer Storage 支援 Cassandra,Cassandra 是一種非關系型分布式資料庫,可擴充至 PB 級存儲。
SeaweedFS 高可用方案最佳實踐

4.1 安裝 JDK

#!/bin/bash
HOST=$1
HOME=$2


HOST_ARRAY=(${HOST//,/ })
JAVA_HOME=$HOME/jdk1.8.0_341


tar -xf jdk-8u341-linux-x64.tar.gz


echo "export JAVA_HOME=$JAVA_HOME" >> ~/.bash_profile
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bash_profile


for host in ${HOST_ARRAY[@]}
do


  scp -r jdk1.8.0_341 $host:/$HOME
  scp ~/.bash_profile $host:/$HOME


  ssh $host "source ~/.bash_profile"
done           

複制代碼

4.2 安裝 Cassandra

sh cassandra_install.sh 172.17.48.1,172.17.48.2,172.17.48.3 /home/hadoop


#!/bin/bash
HOST=$1
HOME=$2


HOST_ARRAY=(${HOST//,/ })


tar -xf apache-cassandra-3.11.14-bin.tar.gz


for host in ${HOST_ARRAY[@]}
do


cat << EoF > apache-cassandra-3.11.14/conf/cassandra.yaml
cluster_name: 'zgg'
listen_address: $host
rpc_address: $host
num_tokens: 256
seed_provider:
  - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
      - seeds: "172.17.48.3"
endpoint_snitch: GossipingPropertyFileSnitch
auto_bootstrap: false


data_file_directories:
    - ./data
commitlog_directory: ./data/commitlog
saved_caches_directory: ./data/saved_caches
EoF


scp -r apache-cassandra-3.11.14 $host:/$HOME
done           

複制代碼

SeaweedFS 高可用方案最佳實踐

4.3 在 Cassandra 中建立命名空間

CREATE KEYSPACE seaweedfs WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};
use seaweedfs;
CREATE TABLE filemeta (
    directory varchar,
    name varchar,
    meta blob,
    PRIMARY KEY (directory, name)
) WITH CLUSTERING ORDER BY (name ASC);           

複制代碼

SeaweedFS 高可用方案最佳實踐

4.4 安裝 SeaweedFS:master

cat master.sh


#!/bin/bash
HOST=$1
HOST_ARRAY=(${HOST//,/ })


for host in ${HOST_ARRAY[@]}
do


ssh -T $host <<EOF
cd /root


if [ ! -d "master" ]
then
  mkdir master
fi


nohup ./weed master -ip=$host -port=9333 -mdir=/root/master -defaultReplication=001 -peers=172.17.48.11:9333,172.17.48.12:9333,172.17.48.13:9333 > /root/master/master.log 2>&1 &
EOF
done


sh master.sh 172.17.48.11,172.17.48.12,172.17.48.13           

複制代碼

4.5 安裝 SeaweedFS:volume

cat volume.sh


#!/bin/bash
HOST=$1
HOST_ARRAY=(${HOST//,/ })


for host in ${HOST_ARRAY[@]}
do


ssh -T $host <<EOF
cd /root


if [ ! -d "volume" ]
then
  mkdir volume
fi


nohup ./weed volume -ip=$host -port=8080 -dir=/root/volume -mserver=172.17.48.11:9333,172.17.48.12:9333,172.17.48.13:9333 -dataCenter=dc1 -rack=rack1 > /root/volume/volume.log 2>&1 &
EOF


done


sh volume.sh 172.17.48.14,172.17.48.15,172.17.48.16,172.17.48.17           

複制代碼

4.6 安裝 SeaweedFS:filer

cat filer.toml


[cassandra]
enabled = true
keyspace = "seaweedfs"
hosts = [
    "172.17.48.1:9042",
    "172.17.48.2:9042",
    "172.17.48.3:9042",
]
username = ""
password = ""
superLargeDirectories = []
localDC = ""
connection_timeout_millisecond = 600


cat filer.sh


#!/bin/bash
HOST=$1
HOST_ARRAY=(${HOST//,/ })


for host in ${HOST_ARRAY[@]}
do


scp filer.toml $host:/root
ssh -T $host <<EOF
cd /root


if [ ! -d "filer" ]
then
  mkdir filer
fi


nohup ./weed filer -ip=$host -port=8888 -defaultStoreDir=/root/filer --master=172.17.48.11:9333,172.17.48.12:9333,172.17.48.13:9333 > /root/filer/filer.log 2>&1 &
EOF


done


sh filer.sh 172.17.48.18,172.17.48.19           

複制代碼

SeaweedFS 高可用方案最佳實踐
SeaweedFS 高可用方案最佳實踐

4.7 批量上傳檔案

#!/bin/bash
for i in $(seq 1 100)
do


echo $i >> $i.txt
echo `cat /proc/sys/kernel/random/uuid` >> $i.txt


done


for i in $(seq 1 100)
do


echo "uploading $i.txt"
curl -F file=@$i.txt "http://172.17.48.19:8888/ice/"
echo "uploaed $i.txt"


done           

複制代碼

SeaweedFS 高可用方案最佳實踐
SeaweedFS 高可用方案最佳實踐
SeaweedFS 高可用方案最佳實踐

5. 方案驗證

5.1 單 master 挂掉對曆史檔案讀、實時檔案寫的影響

kill 掉 Leader

SeaweedFS 高可用方案最佳實踐
SeaweedFS 高可用方案最佳實踐

可發現 Leader 重新進行了選舉

SeaweedFS 高可用方案最佳實踐

5.1.1 驗證曆史檔案的讀請求

#!/bin/bash
for i in $(seq 1 100)
do


curl  "http://172.17.48.19:8888/ice/$i.txt"


done           

複制代碼

SeaweedFS 高可用方案最佳實踐

可發現:資料均可正常通路

5.1.2 驗證明時檔案的寫請求

SeaweedFS 高可用方案最佳實踐

通過 URL 檢視:

SeaweedFS 高可用方案最佳實踐

5.2 單 volume 挂掉對曆史檔案讀、實時檔案寫的影響

SeaweedFS 高可用方案最佳實踐

kill 掉 172.17.48.14

SeaweedFS 高可用方案最佳實踐

可以看到在 volume 清單中 172.17.48.14 節點已經删除

SeaweedFS 高可用方案最佳實踐

5.2.1 驗證曆史檔案的讀請求

#!/bin/bash
for i in $(seq 1 100)
do


curl  "http://172.17.48.19:8888/ice/$i.txt"


done           

複制代碼

SeaweedFS 高可用方案最佳實踐

可發現:資料都可以通路

5.2.2 驗證明時檔案的寫請求

SeaweedFS 高可用方案最佳實踐

通過 URL 檢視:

SeaweedFS 高可用方案最佳實踐

5.3 單 filer 挂掉對曆史檔案讀、實時檔案寫的影響

Kill 掉 172.17.48.18,驗證 172.17.48.19

SeaweedFS 高可用方案最佳實踐

5.3.1 驗證曆史檔案的讀請求

#!/bin/bash
for i in $(seq 1 100)
do


curl  "http://172.17.48.19:8888/ice/$i.txt"


done           

複制代碼

SeaweedFS 高可用方案最佳實踐

172.17.48.19 可以正常對外提供讀取功能

5.3.2 驗證明時檔案的寫請求

SeaweedFS 高可用方案最佳實踐

通過 URL 檢視

SeaweedFS 高可用方案最佳實踐

5.4 單 cassandra 節點挂掉對曆史檔案讀、實時檔案寫的影響

Kill 掉 172.17.48.1

SeaweedFS 高可用方案最佳實踐

從另外一台 cassandra 節點檢視狀态,可發現 172.17.48.1 已經挂掉

SeaweedFS 高可用方案最佳實踐

5.4.1 驗證曆史檔案的讀請求

#!/bin/bash
for i in $(seq 1 100)
do


curl  "http://172.17.48.19:8888/ice/$i.txt"


done           

複制代碼

SeaweedFS 高可用方案最佳實踐

Cassandra 節點挂掉 1 個,依然可以對外提供讀取服務

5.4.2 驗證明時檔案的寫請求

SeaweedFS 高可用方案最佳實踐

6. 結論

按照本方案有如下結論:

SeaweedFS 高可用方案最佳實踐

繼續閱讀