佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫(kù) > linux搭建FastDFS文件服務(wù)器的實(shí)現(xiàn)步驟

linux搭建FastDFS文件服務(wù)器的實(shí)現(xiàn)步驟

熱門標(biāo)簽:阿里云 檢查注冊(cè)表項(xiàng) 網(wǎng)站建設(shè) 智能手機(jī) 美圖手機(jī) 使用U盤裝系統(tǒng) 硅谷的囚徒呼叫中心 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式

本文主要介紹在linux服務(wù)器如何搭建FastDFS文件服務(wù)器。大概分為9個(gè)步驟,由于內(nèi)容較為繁瑣。下面帶你入坑!

首先簡(jiǎn)單介紹一下FastDFS是淘寶資深架構(gòu)師余慶老師主導(dǎo)開源的一個(gè)分布式文件系統(tǒng),用C語言編寫。適應(yīng)與中小企業(yè),對(duì)文件不分塊。

主要有Tracker(管理) 和Storage (儲(chǔ)存)。

返回路徑= 組名 /虛擬盤符{M00/00/02} /文件名

1.軟件包

下面是安裝FastDFS的安裝包

第一步:大家在瀏覽器地址欄輸入:https://sourceforge.net/projects/fastdfs/files,我們會(huì)看到如下圖所示界面。

第二步:下載FastDFS的Server安裝包,我們點(diǎn)擊上圖"FastDFS Server Source Code",會(huì)看到如下圖所示界面,我們選擇2014-12-02那個(gè)版本,因?yàn)檫@個(gè)版本是最穩(wěn)定的版本。

 

第三步:我們會(huì)看到如下圖所示界面,我們點(diǎn)擊"FastDFS_v5.05.tar.gz"進(jìn)行下載即可。

下面是下載好的

或者是自己下載

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://nginx.org/download/nginx-1.12.1.tar.gz

2.安裝gcc

檢查系統(tǒng)是否有安裝GCC

gcc –version

安裝GCC

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum -y install wget httpd-tools vim

就把gcc當(dāng)成c語言編譯器, g++當(dāng)成c++語言編譯器用就是了.(知乎)

3.安裝libfastcommon

進(jìn)入libfastcommon壓縮包目錄解壓,編譯,安裝

tar -zxvf libfastcommonV1.0.7.tar.gz

進(jìn)入解壓的libfastcommon-1.0.7目錄,編譯

./make.sh

安裝

./make.sh install 

最后,libfastcommon.so文件到usr/lib下 ,請(qǐng)按照自己的實(shí)際文件路徑修改被復(fù)制路徑

cp /data/fastDFS/software/libfastcommon-1.0.7/src/libfastcommon.so /usr/lib

4.安裝FastDFS

解壓FastDFS_v5.05.tar.gz,然后編譯安裝FastDFS

tar -zxvf FastDFS_v5.05.tar.gz
./make.sh
./make.sh install

安裝成功后將目錄conf內(nèi)的文件拷貝到/etc/fdfs目錄下:

cp /data/fastDFS/software/FastDFS/conf/* /etc/fdfs/

5.安裝tracker

進(jìn)入/etc/fdfs目錄,修改tracker.conf文件。如果不存在,就拷貝tracker.conf.sample文件為tracker.conf,然后再修改:

base_path=/home/yuqing/fastdfs >>> base_path=/home/logs/fastdfs (注解:日志文件)

http.server_port=8080 >>> http.server_port=80 (注解:端口,80是方便默認(rèn))

store_group=group1 (注解:組名)

其中,/home/

logs

/fastdfs目錄如果不存在,就創(chuàng)建一個(gè)。

之后,就啟動(dòng)tracker,并查看是啟動(dòng)成功(出現(xiàn)如下提示,表示啟動(dòng)成功):restart重啟

fdfs_trackerd /etc/fdfs/tracker.conf start
netstat -unltp | grep tracker

6.安裝storage

由于storage和tracker運(yùn)行的都是fastDFS程序,每一臺(tái)服務(wù)器都部署一臺(tái)fasfDFS,一臺(tái)服務(wù)器是tracker,一臺(tái)是storage

修改storage.conf文件。如果不存在,就拷貝storage.conf.sample文件為storage.conf,然后再修改:

base_path=/home/yuqing/fastdfs >>> base_path=/home/logs/storage (日志路徑)

store_path0=/home/yuqing/fastdfs >>> store_path0=/home/data/storage  (實(shí)際儲(chǔ)存文件路徑,可以配置多個(gè))

tracker_server=192.168.209.121:22122 >>> tracker_server=192.168.2.231:22122 (連接tracker服務(wù)器地址)

group_name=group1 (必須和tracker的組名相同)http.server_port=80 (這個(gè)端口也要改)

其中,如果/home/logs/storage/home/data/storage不存在,就創(chuàng)建該目錄

然后,就啟動(dòng)storage,并查看是否成功(出現(xiàn)如下提示,表示啟動(dòng)成功):

fdfs_storaged /etc/fdfs/storage.conf start
netstat -unltp | grep storage

最后,查看trackerstorage是不是在通信:

fdfs_monitor /etc/fdfs/storage.conf

如下提示,出現(xiàn)ACTIVE,表示二者均正常啟動(dòng),至此就可以進(jìn)行上傳文件測(cè)試了。

7.測(cè)試圖片上傳

Tracker和storage都已經(jīng)安裝完成,使用命令測(cè)試文件上傳:
FastDFS提供一個(gè)文件上傳命令:usr/bin/fdfs_test 測(cè)試文件上傳。測(cè)試上傳需要連接tracker服務(wù)器,連接storage服務(wù)器。因此需要指定一個(gè)配置文件:client.conf配置文件,通過Client.conf連接tracker服務(wù)器。

修改/etc/fdfs下client.conf

base_path=/home/logs/client (日志目錄)
tracker_server=192.168.2.231:22122  (tracker端口)

測(cè)試命令

/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

如下圖返回地址則成功

8.安裝Nginx。

安裝Nginx所需的其他環(huán)境,gcc在上面裝過了。本人安裝沒走這一步

#gcc安裝 
yum install gcc-c++

#PCRE pcre-devel 安裝
yum install -y pcre pcre-devel

# zlib 安裝
yum install -y zlib zlib-devel

#OpenSSL 安裝
yum install -y openssl openssl-devel

解壓、編譯、安裝。

tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure
make
make install

9.安裝fastdfs-nginx-module

首先解壓fastdfs-nginx-module_v1.16.tar.gz,修改/fastdfs-nginx-module/src/config文件。去掉所有的local(三個(gè))

拷貝usr/lib64目錄下庫(kù)文件libfdfsclient.so

cp /usr/lib64/libfdfsclient.so /usr/lib 

在nginx安裝目錄下執(zhí)行如下命令:把module添加nginx中。通過設(shè)置安裝參數(shù)方式添加模塊。

cd nginx-1.12.1
./configure --add-module=../fastdfs-nginx-module/src

注意:我這里nginx-1.12.1和fastdfs-nginx-module在同一級(jí)目錄,所以這樣寫

重新安裝編譯

make && make install

查看Nginx的模塊

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

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

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

進(jìn)入/etc/fdfs/修改mod_fastdfs.conf如下配置,其他默認(rèn)

# 連接超時(shí)時(shí)間
connect_timeout=10

# Tracker Server
tracker_server=192.168.2.231:22122

# StorageServer 默認(rèn)端口
storage_server_port=23000

# 如果文件ID的uri中包含/group**,則要設(shè)置為true
url_have_group_name = true

# Storage 配置的store_path0路徑,必須和storage.conf中的一致
store_path0=/home/data/storage

# the base path to store log files
base_path=/home/logs/storage

配置iNginx ,進(jìn)入/usr/local/nginx/conf目錄下修改nginx.conf

注意:無論你在哪解壓安裝的。必須進(jìn)這個(gè)目錄/usr/local/nginx/conf下修改nginx.conf

vim nginx.conf

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

在80端口下添加fastdfs-nginx模塊

location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
}

注意下面#user nobody;改成 #user root;

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  192.168.2.231;
        location ~/group([0-9])/M00 {
            ngx_fastdfs_module;
        }
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

注意:

listen 80 端口值是要與 /etc/fdfs/storage.conf 中的 http.server_port=80 (前面改成80了)相對(duì)應(yīng)。如果改成其它端口,則需要統(tǒng)一,同時(shí)在防火墻中打開該端口。

location 的配置,如果有多個(gè)group則配置location ~/group([0-9])/M00 ,沒有則不用配group。

在文件存儲(chǔ)目錄下創(chuàng)建軟連接,將其鏈接到實(shí)際存放數(shù)據(jù)的目錄,注意這個(gè)文件存儲(chǔ)的位置后面多個(gè)data目錄是系統(tǒng)自動(dòng)生成的

ln -s /home/data/storage/data /home/data/storage/data/M00

啟動(dòng)nginx

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

#設(shè)置開機(jī)啟動(dòng)
vim /etc/rc.local
/usr/local/nginx/sbin/nginx

# 設(shè)置執(zhí)行權(quán)限
chmod 755 rc.local

查看Nginx是否啟動(dòng)

ps -ef | grep nginx

OK記得云服務(wù)的安全組 和防火墻設(shè)置需要方通 80、22122、 23000 這個(gè)不會(huì)的請(qǐng)參考騰訊云服務(wù)器tomcat端口無法訪問 中的防火墻設(shè)置

在地址欄中訪問成功 http://192.175.231.128/group1/M00/00/00/rBAACVzBeU2AQBKJAAOHDqS1H9o350.jpg

報(bào)錯(cuò)!不存在的。有問題110,120,119

注意:

1.group2同組的Storage2和Storage3 FastDFS服務(wù)端口必須一致: port=23000。

2.一臺(tái)服務(wù)器可以裝多個(gè)組(group)但不能裝同組的多個(gè)Storage,日志會(huì)報(bào)錯(cuò)誤,日志報(bào)錯(cuò)原因是"注意1"

3.Version 4.05之前fastdfs內(nèi)部綁定了libevent作為http服務(wù)器.Version 4.05之后的版本刪除了內(nèi)置的web http服務(wù),內(nèi)置的web http服務(wù)是個(gè)累贅,不用也罷!

4.啟動(dòng)storage server時(shí),一直處于僵死狀態(tài).啟動(dòng)storage server,storage將連接tracker server,如果連不上,將一直重試。直到連接成功,啟動(dòng)才算真正完成!如果集群中有2臺(tái)tracker server,而

其中一臺(tái)tracker沒有啟動(dòng),可能會(huì)導(dǎo)致storage server一直處于僵死狀態(tài)。

到此這篇關(guān)于linux搭建FastDFS文件服務(wù)器的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)linux搭建FastDFS文件服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:黃山 賀州 湖北 懷化 湘潭 煙臺(tái) 山南 通遼

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《linux搭建FastDFS文件服務(wù)器的實(shí)現(xiàn)步驟》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    山西省| 呼玛县| 东丽区| 沙湾县| 若尔盖县| 横峰县| 澎湖县| 嘉祥县| 太和县| 元阳县| 綦江县| 灌云县| 永顺县| 苗栗县| 永宁县| 博爱县| 通化县| 万宁市| 高陵县| 浦县| 雷波县| 东乌珠穆沁旗| 武平县| 堆龙德庆县| 双牌县| 桦南县| 区。| 长岛县| 多伦县| 南部县| 萝北县| 九龙城区| 秦安县| 通辽市| 襄城县| 黔东| 无为县| 石泉县| 兴隆县| 南丹县| 金平|