- 軟件版本: seaweedfs-1.33
- 壓縮包包名:linux_amd64.tar.gz
- 想了解更多請查看官方文檔wiki
相關概念:
定義名稱 | 說明 |
---|---|
master | 提供volume=>location 位置映射服務和文件id的序列號 |
Node | 系統抽象的節點,抽象爲DataCenter、Rack |
DataCenter | 數據中心,對應現實中的不同機架 |
Rack | 機架,對應現實中的機櫃,一個機架屬於特定的數據中心,一個數據中心可以包含多個機架。 |
Volume | 邏輯卷,存儲的邏輯結構,邏輯卷下存儲Needle,A VolumeServer contains one Store |
Needle | 邏輯卷中的Object,對應存儲的文件, Needle file size is limited to 4GB for now. |
Filer | 文件管理器,Filer將數據上傳到Weed Volume Servers,並將大文件分成塊,將元數據和塊信息寫入Filer存儲區 |
Collection | 文件集,可以分佈在多個邏輯捲上,如果在存儲文件的時候沒有指定collection,那麼使用默認的"" |
Mount | 用戶空間,當filer與mount一起使用時,filer僅提供文件元數據檢索,實際文件內容直接在mount和volume服務器之間讀寫,所以不需要多個filer |
部署規劃:
節點 | master | volume | filer |
---|---|---|---|
192.168.88.129 | √ | √ | √ |
192.168.88.130 | √ | √ | √ |
192.168.88.131 | √ | √ | √ |
解壓:
- tar -zxvf ./linux_amd64.tar.gz -C /opt/module
- 得到/opt/module目錄下weed文件
啓動前準備:
- 創建master文件夾和volume文件夾
mkdir -p ./seaweedfs/data ./seaweedfs/volume
配置運行master
- 具體參數請參考./weed master -h
- 分別在三臺機器上執行以下命令
nohup ./weed master -ip=192.168.88.129 -port=9333 -mdir=./seaweedfs/data -peers=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 > ./seaweedfs/data/master.log &
nohup ./weed master -ip=192.168.88.130 -port=9333 -mdir=./seaweedfs/data -peers=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 > ./seaweedfs/data/master.log &
nohup ./weed master -ip=192.168.88.131 -port=9333 -mdir=./seaweedfs/data -peers=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 > ./seaweedfs/data/master.log &
配置運行volume
- 具體參數請參考./weed volume -h
- 配置volume邏輯卷時, 可以指定數據中心datacenter以及機架rack, 複製模式和數據中心和機架有關, 具體見文檔https://github.com/chrislusf/seaweedfs/wiki/Replication
- 分別在三臺機器上執行以下命令
nohup ./weed volume -dataCenter dc1 -rack rack1 -dir ./seaweedfs/volume -ip 192.168.88.129 -port 9222 -ip.bind 192.168.88.129 -max 20 -mserver 192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -publicUrl 192.168.88.129:9222 > ./seaweedfs/volume/volume.log &
nohup ./weed volume -dataCenter dc1 -rack rack1 -dir ./seaweedfs/volume -ip 192.168.88.130 -port 9222 -ip.bind 192.168.88.130 -max 20 -mserver 192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -publicUrl 192.168.88.130:9222 > ./seaweedfs/volume/volume.log &
nohup ./weed volume -dataCenter dc1 -rack rack1 -dir ./seaweedfs/volume -ip 192.168.88.131 -port 9222 -ip.bind 192.168.88.131 -max 20 -mserver 192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -publicUrl 192.168.88.130:9222 > ./seaweedfs/volume/volume.log &
- 配置完成後訪問http://192.168.88.129:9333/
測試上傳下載
- 文件上傳首先需要請求master, 去分配一個邏輯卷和fid
- 返回結果
{"fid":"14,0c3657515f","url":"192.168.88.129:9222","publicUrl":"192.168.88.129:9222","count":1}
- 使用返回的url和fid上傳文件
curl -F file=@./seaweedfs/volume/volume.log 192.168.88.129:9222/14,0c3657515f
- 可以這麼理解, 上傳文件, 首先請求master分配volume和fid, 然後將文件上傳到某個卷下
- wget 192.168.88.129:9222/14,0c3657515f 可以將該文件下載下來,也可通過瀏覽器直接訪問該地址下載圖片
配置運行Filer並掛載到本地目錄
Filer允許以另一種方式上傳文件
- 安裝啓動
mkdir -p /etc/seaweedfs
cd /etc/seaweedfs
touch filer.toml
mkdir -p /opt/module/filer_path/level
將 /opt/module/weed scaffold filer -output=""
打印出的內容寫入到 filer.toml中, 並且修改其中的配置
dir = "/opt/module/filer_path/level"
可以使用文件, MySQL, redis等保存 filer的元數據信息, 只需要啓用或者停用對應的配置,具體請參考https://github.com/chrislusf/seaweedfs/wiki/Filer-Server-API
- 啓動
./weed filer -master=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -ip=192.168.88.129 -port=8888&
./weed filer -master=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -ip=192.168.88.130 -port=8888&
./weed filer -master=192.168.88.129:9333,192.168.88.130:9333,192.168.88.131:9333 -ip=192.168.88.131 -port=8888&
- 上傳文件
curl -F "filename=@./abc.log" "http://192.168.88.129:8888/path/to/sources/"
- 返回結果
{"name":"volume.log","size":1656,"fid":"13,0da7c2b7ff","url":"http://192.168.88.130:9222/13,0da7c2b7ff"}
可以看到,前面的上傳需要兩步,現在用filer上傳,只需要一步,並且可以指定文件夾,這裏的/path/to/sources/
就是文件路徑 - 可直接輸入http://192.168.88.129:8888/地址進行訪問.下載和前面的流程一樣.
mount掛載
- 可以將filer掛載到本地某個目錄進行管理,具體請參考https://github.com/chrislusf/seaweedfs/wiki/Mount
mkdir -p ./seaweedfs/data/mount
- 指定文件管理器掛載到/seaweedfs/data/mount目錄下
./weed mount -filer=192.168.88.129:8888 -dir=./seaweedfs/data/mount &
執行命令後,便可看到通過filer上傳的文件已經掛載到了本地/seaweedfs/data/mount目錄下.
具體信息以官方wiki爲主.