日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

Fastdfs 分布式文件管理系统

發(fā)布時間:2023/12/16 windows 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Fastdfs 分布式文件管理系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Fastdfs 分布式文件管理系統(tǒng)

概念:
缺點(diǎn): 所有的問題文件全部存放在一臺計(jì)算機(jī)中,如果這臺計(jì)算機(jī)壞掉,那么會導(dǎo)致整個服務(wù)不可用,文件不能上傳和下載 ,如果這臺計(jì)算機(jī)磁盤損壞那么會丟失所有的文件,而且這臺計(jì)算機(jī)的磁盤空間非常的有限,很容易達(dá)到磁盤的上限,導(dǎo)致無法上傳文件

分布式文件系統(tǒng)

優(yōu)點(diǎn):解決了傳統(tǒng)方式的單點(diǎn)故障問題,如果某一個節(jié)點(diǎn)出現(xiàn)故障還有其它的節(jié)點(diǎn)可以用來讀取和寫入文件,可以提供數(shù)據(jù)的備份避免因?yàn)槠渌疟P損壞導(dǎo)致的文件丟失,還可以提供庫容的機(jī)制,無限的增加文件存放的空間上限。

Fastdfs 簡介

FastDFS是一個開源的輕量級分布式文件系統(tǒng),它對文件進(jìn)行管理,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負(fù)載均衡的問題。特別適合以文件為載體的在線服務(wù),如相冊網(wǎng)站、視頻網(wǎng)站等等,簡單、靈活、高效、采用c語言開發(fā),由阿里巴巴開發(fā)并開通。

Fastdfs 文件系統(tǒng)有兩大部分組成: 一個是客戶端 ,一個是服務(wù)端

客戶端通常指的是我們的程序,也就是我們的java 代碼,Java代碼去連接Fastdfs、操作Fastdfs ,Fastdfs 提供了專有的API訪問。

服務(wù)端有兩個部分組成: 一個是跟蹤器(tracker) 一個是存儲節(jié)點(diǎn)(storage)

跟蹤器(tracker)主要做調(diào)度的工作: 相當(dāng)于是一個紐扣,比如文件的上傳功能

1、client詢問tracker上傳到的storage,注意,它不需要附加參數(shù)

2、tracker返回一臺可用的storage

3、client直接和storage通訊完成文件上傳

存儲節(jié)點(diǎn)(storage) 用于存儲文件,包括文件和文件屬性都保存到存儲服務(wù)器磁盤上,完成文件管理的所有功能;文件存儲,文件同步,文件訪問等。

Fastdfs環(huán)境的搭建
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel ubuntu 的差什么就裝什么

說明位置
所有安裝包/usr/local/src
數(shù)據(jù)存儲位置/home/dfs/
#這里我為了方便把日志什么的都放到了dfs
mkdir /home/dfs #創(chuàng)建數(shù)據(jù)存儲目錄 cd /usr/local/src #切換到安裝目錄準(zhǔn)備下載安裝包

安裝libfastcommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1 cd libfastcommon/ ./make.sh && ./make.sh install #編譯安裝

參考:https://github.com/happyfish100/fastdfs/wiki#%E5%8D%95%E6%9C%BA%E9%83%A8%E7%BD%B2

安裝FastDFS

cd ../ #返回上一級目錄 git clone https://github.com/happyfish100/fastdfs.git --depth 1 cd fastdfs/ ./make.sh && ./make.sh install #編譯安裝 #配置文件準(zhǔn)備 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端文件,測試用 cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx訪問使用 cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx訪問使用

安裝fastdfs-nginx-module

cd ../ #返回上一級目錄 git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1 cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

安裝nginx

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載nginx壓縮包 tar -zxvf nginx-1.15.4.tar.gz #解壓 cd nginx-1.15.4/ #添加fastdfs-nginx-module模塊 ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ make && make install #編譯安裝

單機(jī)部署

tracker配置

#服務(wù)器ip為 192.168.52.1 #我建議用ftp下載下來這些文件 本地修改 vim /etc/fdfs/tracker.conf #需要修改的內(nèi)容如下 port=22122 # tracker服務(wù)器端口(默認(rèn)22122,一般不修改) base_path=/home/dfs # 存儲日志和數(shù)據(jù)的根目錄

storage配置

vim /etc/fdfs/storage.conf #需要修改的內(nèi)容如下 port=23000 # storage服務(wù)端口(默認(rèn)23000,一般不修改) base_path=/home/dfs # 數(shù)據(jù)和日志文件存儲根目錄 store_path0=/home/dfs # 第一個存儲目錄 tracker_server=192.168.52.1:22122 # tracker服務(wù)器IP和端口 http.server_port=8888 # http訪問文件的端口(默認(rèn)8888,看情況修改,和nginx中保持一致)

client測試

vim /etc/fdfs/client.conf #需要修改的內(nèi)容如下 base_path=/home/dfs tracker_server=192.168.52.1:22122 #tracker服務(wù)器IP和端口 #保存后測試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

測試上傳失敗:

1.測試失敗的話 我們需要重啟tracker和storage

2.依次在終端輸入:
pkill -9 fdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

配置nginx訪問

vim /etc/fdfs/mod_fastdfs.conf #需要修改的內(nèi)容如下 tracker_server=192.168.52.1:22122 #tracker服務(wù)器IP和端口 url_have_group_name=true store_path0=/home/dfs #配置nginx.config vim /usr/local/nginx/conf/nginx.conf #添加如下配置 server {listen 8888; ## 該端口為storage.conf中的http.server_port相同server_name localhost;location ~/group[0-9]/ {ngx_fastdfs_module;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} } #測試下載,用外部瀏覽器訪問剛才已傳過的nginx安裝包,引用返回的ID http://172.18.3.94:8888/group1/M00/00/00/rBIDXl_0IIuAYDbiAAmOgczu2y4488.jpg #彈出下載單機(jī)部署全部跑通

測試下載 :

要想在瀏覽器上下載,我們需要配置nginx訪問, 需要安裝fastdfs-nginx-module,和安裝nginx 配置好以后即可訪問。

http://172.18.3.94:8888/group1/M00/00/00/rBIDXl_0IIuAYDbiAAmOgczu2y4488.jpg

fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/rBIDXl_tjFaAMazxAAmOgczu2y4728.jpg

nginx 擴(kuò)展模塊的執(zhí)行流程

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來直接上傳(img-rRy6jYUb-1615345390941)(/home/pf/.config/Typora/typora-user-images/image-20210105194508872.png)]

集成fastdfs

1.導(dǎo)入依賴

<dependency><groupId>FastDfs</groupId><artifactId>classes</artifactId><version>1.27</version> </dependency>

如果下載不了 我們就去官網(wǎng)把zip下載下來,解壓。 打成jar的形式

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來直接上傳(img-y8zS91Ln-1615345390964)(/home/pf/.config/Typora/typora-user-images/image-20201223213031423.png)].

參考:https://blog.csdn.net/dongdingzhuo/article/details/78731704#commentBox

導(dǎo)入jar包

<dependency><groupId>org.apache</groupId><artifactId>fastdfs-client</artifactId><scope>system</scope><version>1.0</version><systemPath>${project.basedir}/src/main/resources/jar/fastdfs-client-java-1.29-SNAPSHOT.jar</systemPath> </dependency> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding><compilerArguments><extdirs>${project.basedir}/src/main/resources/jar</extdirs></compilerArguments></configuration> </plugin> <resources><resource><directory>${basedir}/src/main/resources</directory><filtering>true</filtering><includes><include>**/*.txt</include></includes></resource><resource><directory>${basedir}/src/main/resources</directory><targetPath>config/</targetPath><includes><include>**/*.xml</include></includes></resource><resource><directory>${basedir}/src/main/resources</directory><filtering>true</filtering><includes><include>**/*.properties</include></includes></resource><resource><directory>${basedir}/src/main/resources</directory><excludes><exclude>**/*.properties</exclude></excludes></resource><resource><directory>${basedir}/src/main/resources</directory><targetPath>BOOT-INF/lib/</targetPath><includes><include>**/*.jar</include></includes></resource></resources></build>

配置nginx

修改nginx.conf配置

建議打開:user root;

worker_processes配置成CPU核心數(shù)的2倍;

配置日志文件存放目錄:

? access_log /home/zf/nginx/factoryTest/access.log;

? error_log /home/zf/nginx/factoryTest/error.log;

http模塊加入文件上傳大小:client_max_body_size 100M;

如部署前端項(xiàng)目:gzip on可開啟;

如需加入自定義配置文件:http模塊配置include conf.d/*.conf;

2. 加入開機(jī)啟動項(xiàng)

-添加開機(jī)啟動服務(wù)

sudo vim /lib/systemd/system/nginx.service

-加入以下內(nèi)容

[Unit]

Description=nginx service

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

-設(shè)置開機(jī)啟動

systemctl daemon-reload

systemctl enable nginx.service

3. 相關(guān)命令

-啟動:systemctl start nginx

-停止:systemctl stop nginx

-查看服務(wù)狀態(tài):systemctl status nginx

-重啟:systemctl restart nginx

報(bào)錯: nginx 啟動失敗 我們應(yīng)該在usr/local/nginx下配置 而不是在usr/local/src/naginx 下配置 src 一般放的是源碼

FastDFS中fdfs_trackerd和fdfs_storaged的啟動、重啟、終止命令

啟動:
sudo service fdfs_trackerd start sudo service fdfs_storaged start 12
重啟:
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 12
終止:
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop 12

注意點(diǎn):
我們要是使用終止命令或者使用 kill -9 fdfs進(jìn)程id 來終結(jié)fdfs_storaged服務(wù)的,然后用上面的啟動命令是啟動不了的,因?yàn)閘og日志問題,會出現(xiàn)下面的錯誤

一般在我們跟換ip地址的時候,重啟fdfs服務(wù),就使用重啟命令就行。

總結(jié)

以上是生活随笔為你收集整理的Fastdfs 分布式文件管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。