FastDFS單機(jī)搭建

簡介

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

在樂昌等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站建設(shè)、做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站制作,樂昌網(wǎng)站建設(shè)費(fèi)用合理。

安裝

環(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ù)和日志目錄地址(根目錄必須存在,子目錄會自動(dòng)創(chuàng)建)
base_path=/home/fastdfs/tracker
# HTTP 服務(wù)端口
http.server_port=80

創(chuàng)建tracker基礎(chǔ)數(shù)據(jù)目錄,即base_path對應(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 存儲 (Storage)
進(jìn)入 /etc/fdfs 目錄

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

編輯storage.conf

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

創(chuàng)建Storage基礎(chǔ)數(shù)據(jù)目錄,對應(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.文件上傳測試
修改 Tracker 服務(wù)器中的客戶端配置文件

# 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 

上傳測試

# /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ī)搭建
在瀏覽器訪問之前上傳的文件、成功。
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了)相對應(yīng)。
啟動(dòng)nginx

# /usr/local/nginx/sbin/nginx

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

新聞標(biāo)題:FastDFS單機(jī)搭建
文章分享:http://bm7419.com/article28/iihjjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、企業(yè)網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)自適應(yīng)網(wǎng)站、小程序開發(fā)App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)