溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

FastDFS單機(jī)搭建

發(fā)布時(shí)間:2020-04-07 17:14:13 來(lái)源:網(wǎng)絡(luò) 閱讀:146 作者:974297362 欄目:軟件技術(shù)

簡(jiǎn)介

FastDFS 是一個(gè)開(kāi)源的高性能分布式文件系統(tǒng)(DFS)。
FastDFS 系統(tǒng)有三個(gè)角色:跟蹤服務(wù)器(Tracker Server)、存儲(chǔ)服務(wù)器(Storage Server)和客戶(hù)端(Client)。
  Tracker Server:跟蹤服務(wù)器,主要做調(diào)度工作,起到均衡的作用;負(fù)責(zé)管理所有的 storage server和 group,每個(gè) storage 在啟動(dòng)后會(huì)連接 Tracker,告知自己所屬 group 等信息,并保持周期性心跳。
  Storage Server:存儲(chǔ)服務(wù)器,主要提供容量和備份服務(wù);以 group 為單位,每個(gè) group 內(nèi)可以有多臺(tái) storage server,數(shù)據(jù)互為備份。
  Client:客戶(hù)端,上傳下載數(shù)據(jù)的服務(wù)器,也就是我們自己的項(xiàng)目所部署在的服務(wù)器。
FastDFS單機(jī)搭建

安裝

環(huán)境準(zhǔn)備

編譯源碼需要gcc gcc-c++ perl,軟件包解壓需要unzip
 yum -y install gcc gcc-c++ perl unzip

提前下載好需要的軟件包(統(tǒng)一下載在/usr/local/src目錄)

下載libfastcommon環(huán)境包:         wget https://github.com/happyfish200/libfastcommon/archive/V1.0.7.tar.gz
下載FastDFS包:         wget https://github.com/happyfish200/fastdfs/archive/V5.05.tar.gz
下載nginx源碼包:         wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
下載?fastdfs-nginx-module插件包: wget  https://github.com/happyfish200/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

1.安裝 libfastcommon
解壓并進(jìn)入

tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7

編譯、安裝

 ./make.sh
 ./make.sh install

libfastcommon.so 默認(rèn)安裝到了/usr/lib64/libfastcommon.so。但是后續(xù)我們安裝的FastDFS主程序設(shè)置的lib目錄是/usr/local/lib,因此需要?jiǎng)?chuàng)建軟鏈接。

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

2.下載安裝FastDFS
解壓并進(jìn)入

 tar -zxvf V5.05.tar.gz
 cd fastdfs-5.05

編譯、安裝

 ./make.sh
 ./make.sh install

安裝后的相應(yīng)文件與目錄如下:
fastdfs的服務(wù)腳本

/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker

fastdfs配置文件

/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sample

命令工具在 /usr/bin/。
FastDFS 服務(wù)腳本設(shè)置的 bin 目錄是 /usr/local/bin, 但實(shí)際命令安裝在 /usr/bin/ 下。我們需要建立 /usr/bin 到 /usr/local/bin 的軟鏈接

ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/fdfs_storaged /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin

3.配置FastDFS跟蹤器(Tracker)
進(jìn)入 /etc/fdfs,復(fù)制 FastDFS 跟蹤器樣例配置文件 tracker.conf.sample,并重命名為 tracker.conf

 cd /etc/fdfs
 cp tracker.conf.sample tracker.conf
 vim tracker.conf

編輯tracker.conf ,以下需要修改下,其它的默認(rèn)即可。

# Tracker 數(shù)據(jù)和日志目錄地址(根目錄必須存在,子目錄會(huì)自動(dòng)創(chuàng)建)
base_path=/home/fastdfs/tracker
# HTTP 服務(wù)端口
http.server_port=80

創(chuàng)建tracker基礎(chǔ)數(shù)據(jù)目錄,即base_path對(duì)應(yīng)的目錄

mkdir -p /home/fastdfs/tracker

啟動(dòng)Tracker

# service fdfs_trackerd start   
或
# systemctl start fdfs_trackerd

netstat -unltp|grep fdfs

FastDFS單機(jī)搭建
關(guān)閉

service fdfs_trackerd stop

4.配置 FastDFS 存儲(chǔ) (Storage)
進(jìn)入 /etc/fdfs 目錄

# cd /etc/fdfs
# cp storage.conf.sample storage.conf
# vim storage.conf

編輯storage.conf

# Storage 數(shù)據(jù)和日志目錄地址(根目錄必須存在,子目錄會(huì)自動(dòng)生成)
base_path=/home/fastdfs/storage
# 如果不配置 store_path0,那它就和 base_path 對(duì)應(yīng)的路徑一樣,此處直接注釋掉。
#store_path0=/home/fastdfs/file
# 有多個(gè) tracker server 時(shí),每個(gè) tracker server 寫(xiě)一行
tracker_server=192.168.244.8:22122
# 訪問(wèn)端口
http.server_port=80

創(chuàng)建Storage基礎(chǔ)數(shù)據(jù)目錄,對(duì)應(yīng)base_path目錄

# mkdir -p /home/fastdfs/storage

啟動(dòng) Storage

# service fdfs_storaged 
#查看狀態(tài)
# netstat -unltp|grep fdfs
#關(guān)閉
# service fdfs_storaged stop

FastDFS單機(jī)搭建
查看Storage和Tracker是否在通信
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
FastDFS單機(jī)搭建
5.文件上傳測(cè)試
修改 Tracker?服務(wù)器中的客戶(hù)端配置文件?

# cd /etc/fdfs
# cp client.conf.sample client.conf
# vim client.conf

修改如下配置即可,其它默認(rèn)。

# Client 的數(shù)據(jù)和日志目錄
base_path=/home/fastdfs/client
# Tracker端口
tracker_server=192.168.244.8:22122
#tracker服務(wù)器的端口
http.tracker_server_port=8081 

上傳測(cè)試

# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf  xxx.jpg

FastDFS單機(jī)搭建
FastDFS單機(jī)搭建

安裝nginx

1.安裝nginx所需環(huán)境
PCRE pcre-devel 安裝
# yum install -y pcre pcre-devel
zlib 安裝
# yum install -y zlib zlib-devel
OpenSSL 安裝
# yum install -y openssl openssl-devel
2.安裝nginx

# tar -zxvf nginx-1.12.1.tar.gz
# cd nginx-1.12.1

# ./configure

# make
# make install

#啟動(dòng)
# cd /usr/local/nginx/sbin/
# ./nginx

# ./nginx -s stop
# ./nginx -s quit
# ./nginx -s reload

/usr/local/nginx/sbin/nginx -V

FastDFS單機(jī)搭建
修改nginx.conf

# vim /usr/local/nginx/conf/nginx.conf

#添加如下行,將 /group1/M00 映射到 /home/fastdfs/storage/data
location /group1/M00 {
alias /home/fastdfs/storage/data;
}

重啟

# /usr/local/nginx/sbin/nginx -s reload

FastDFS單機(jī)搭建
在瀏覽器訪問(wèn)之前上傳的文件、成功。
http://192.168.244.8/group1/M00/00/00/wKj0CF0cTBKAYwBiAABdrZgsqUU227.jpg

3.Nginx的fastdfs 模塊
解壓?fastdfs-nginx-module

# 解壓
# unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# 重命名
# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1 fastdfs-nginx-module

配置Nginx

# 先停掉nginx服務(wù)
# /usr/local/nginx/sbin/nginx -s stop
進(jìn)入nginx解壓包目錄
# cd /usr/local/src/nginx-1.12.1/

# 添加模塊
# ./configure --add-module=../fastdfs-nginx-module/src
重新編譯、安裝
# make && make install

#查看Nginx的版本模塊
# /usr/local/nginx/sbin/nginx -V

FastDFS單機(jī)搭建

復(fù)制 fastdfs-nginx-module 源碼中的配置文件到/etc/fdfs 目錄, 并修改

# cd /usr/local/src/fastdfs-nginx-module/src
# cp mod_fastdfs.conf /etc/fdfs/

修改如下配置,其它默認(rèn)

# 連接超時(shí)時(shí)間
connect_timeout=10
# Tracker Server
tracker_server=192.168.244.8:22122
# 如果文件ID的uri中包含/group**,則要設(shè)置為true
url_have_group_name = true
# Storage 配置的store_path0路徑,必須和storage.conf中的一致,統(tǒng)一注釋掉
#store_path0= /home/yuqing/fastdfs

復(fù)制 FastDFS 的部分配置文件到/etc/fdfs 目錄

# cd /usr/local/src/fastdfs-5.05/conf/
# cp anti-steal.jpg http.conf mime.types /etc/fdfs/

配置nginx,修改nginx.conf
在80端口下添加fastdfs-nginx模塊

location ~/group0/M00 {
ngx_fastdfs_module;
}

FastDFS單機(jī)搭建
注意:
  listen 80?端口值是要與?/etc/fdfs/storage.conf 中的 http.server_port=80 (前面改成80了)相對(duì)應(yīng)。
啟動(dòng)nginx

# /usr/local/nginx/sbin/nginx

FastDFS單機(jī)搭建
重新上傳一個(gè)圖片,能用瀏覽器打開(kāi),即安裝成功。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI