FastDFS在centos上的安裝配置與使用

來源:互聯網
上載者:User

標籤:

FastDFS是一個開源的輕量級Distributed File System,它對檔案進行管理,功能包括:檔案儲存體、檔案同步、檔案訪問(檔案上傳、檔案下載)等,解決了大型存放區和負載平衡的問題。特別適合以檔案為載體的線上服務。(百科)

本文詳細介紹了FastDFS在centos系統上的詳細安裝過程,在從機上使用了nginx實現了http的訪問請求,我們開始吧。。(轉載請標明,謝謝)

fdfs工具包http://pan.baidu.com/s/1eQHCSJw

使用winscp將工具包複製到伺服器中

 

 

1、節點和關閉服務(關閉防火牆)

sudo service iptables stop 

sudo chkconfig iptables off

sudo vi /etc/selinux/config 修改 selinux=disable

2、開始安裝 fastdfs,主機Tracker、從機storage安裝方法一樣

3、檢查 gcc 編譯器系統中是否安裝

   sudo yum install -y gcc gcc-c++

4、FastDFS_v5.05依賴libfastcommon,不再依賴libevent。

5、安裝libfastcommon

 (1)安裝unzip包,將libfastcommon解壓到/usr/local下

   sudo yum install -y unzip zip

   sudo unzip libfastcommon-1.0.7.zip -d /usr/local

(2)編譯並運行

   cd /usr/local/libfastcommon-1.0.7

   sudo ./make.sh

   sudo ./make.sh install

 

   由於FastDFS主程式設定的lib目錄是/usr/local/lib,所以需要建立軟連結.

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

   sudo ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

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

   sudo  ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

6、安裝FastDFS

(1)解壓FastDFS至 /usr/local

  sudo tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local

(2)編譯並安裝

   cd /usr/local/FastDFS

   sudo ./make.sh

   sudo ./make.sh install

安裝完成,如果安裝失敗,檢查一下軟串連,主機從機都必須這樣配置

7、配置Tracker和Storage

(1)Tracker,建立 tracker.conf

  cd /etc/fdfs/

  sudo cp tracker.conf.sample tracker.conf

   建立資料存放區目錄

  mkdir /mnt/fastdfs_tracker

  修改tracker.conf設定檔

  base_path=/mnt/fastdfs_tracker

  啟動該設定檔

  fdfs_trackerd /etc/fdfs/tracker.conf

  

(2)Storage,建立 storage.conf

  cd /etc/fdfs/

    sudo cp storage.conf.sample storage.conf

    

  建立資料存放區目錄

  sudo mkdir /mnt/fastdfs_storage_info

sudo mkdir /mnt/fastdfs_storage_data

 

  修改storage.conf設定檔

  base_path=/mnt/fastdfs_storage_info

  store_path0=/mnt/fastdfs_storage_data

      tracker_server=主機IP:連接埠(預設22122)

 

第一次啟動該設定檔(該動作有點慢耐心等待)

fdfs_storaged  /etc/fdfs/storage.conf

  註:出錯請查看日誌:

 cat /mnt/fastdfs_tracker/logs/tracker.log

 cat /mnt/fastdfs_storage_info/logs/storage.log

 

 telnet檢查主從是否通訊

 http://jingyan.baidu.com/article/3c48dd34709e70e10be35835.html

 

 使用fdfs_test /etc/fdfs/client.conf upload 1.png 測試fastdf有沒有正常工作,正確顯示如:

 

8、在storage上安裝的nginx主要為了提供http的訪問服務,同時解決group中storage伺服器的同步延遲問題

(1)解壓nginx外掛程式fastdfs-nginx-module,以及依賴包 pcre、zlib

  sudo tar -zxvf  FastDFS_v5.05.tar.gz -C /usr/local

  sudo tar -zxvf  pcre-8.34.tar.gz -C /usr/local

  sudo tar -zxvf  zlib-1.2.8.tar.gz -C /usr/local

 

(2)解壓安裝nginx

sudo tar -zxvf nginx-1.7.8.tar.gz -C /usr/local

 

sudo ./configure

--prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src     --with-pcre=/usr/local/src/pcre-8.34/ --with-zlib=/usr/local/src/zlib-1.2.8

(如果提示錯誤,可能缺少依賴的軟體包,需先安裝依賴包,再次運行./configure)

 

sudo make

sudo make install

 

 

9、將FastDFS的nginx外掛程式模組的設定檔copy到FastDFS設定檔目錄。

(1)cp/usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf  /etc/fdfs/

 

(2)將fastdfs安裝包中的http.conf、mime.types 兩個檔案拷貝到/etc/fdfs中

  sudo cp /usr/local/FastDFS/conf/http.conf  /etc/fdfs/

  sudo cp /usr/local/FastDFS/conf/mime.types  /etc/fdfs/

(3)編輯/usr/local/nginx/conf設定檔目錄下的nginx.conf,設定添加storage資訊並儲存。

  sudo vi /usr/local/nginx/conf/nginx.conf

 

將server段中的listen連接埠號碼改為8080:

listen       8080;

在server段中添加:

location ~/group1/M00 {

      root /mnt/fastdfs_storage_data;

    ngx_fastdfs_module;

}

可以設定多個組,上面只設定了一個組‘group1’根據具體情況而定

location ~/group[1-3]/M00 {

      root /mnt/fastdfs_storage_data;

    ngx_fastdfs_module;

}

(4)編輯/etc/fdfs設定檔目錄下的mod_fastdfs.conf,設定storage資訊並儲存。

sudo vi /etc/fdfs/mod_fastdfs.conf

 

一般只需改動以下幾個參數即可:

base_path=/fdfs/storage           #儲存日誌目錄

tracker_server=主機IP:22122 #tracker伺服器的IP地址以及連接埠號碼

storage_server_port=23000         #storage伺服器的連接埠號碼

group_name=group1                 #當前伺服器的group名

url_have_group_name = true        #檔案url中是否有group名

store_path_count=1                #儲存路徑個數,需要和store_path個數匹配

store_path0=/fdfs/storage         #儲存路徑

http.need_find_content_type=true  #從副檔名尋找檔案類型(nginx時為true)

有的版本沒有該選項不要管它

根據你上面設定的組個數設定

group_count = 1                  #設定組的個數

在末尾增加1個組的具體資訊:(設定幾組就添加幾組)

[group1]

group_name=group1

storage_server_port=23000

store_path_count=1

store_path0=/mnt/fastdfs_storage_data

/*[group2]

group_name=group2

storage_server_port=23000

store_path_count=1

store_path0=/mnt/fastdfs_storage_data

[group3]

group_name=group3

storage_server_port=23000

store_path_count=1

store_path0=/mnt/fastdfs_storage_data*/

 

 

(5)建立M00至儲存目錄的軟串連

sudo ln -s /mnt/fastdfs_storage_data  /mnt/fastdfs_storage_data/M00

 

測試軟串連有沒有設定成功

ll /fdfs/storage/data/M00

lrwxrwxrwx. 1 root root 19 3月  26 03:44 /fdfs/storage/data/M00 -> /fdfs/storage/data/

 

10、運行nginx

(1)運行nginx之前,先要把防火牆中對應的連接埠開啟(本例中為8080)。

不是root使用者都要sudo

[[email protected] nginx-1.4.7]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT

[[email protected] nginx-1.4.7]# /etc/init.d/iptables save

 

(2)啟動nginx,確認啟動是否成功。(查看是否對應連接埠8080是否開始監聽)

 

[[email protected] nginx-1.4.7]# /usr/local/nginx/sbin/nginx

ngx_http_fastdfs_set pid=40638

[[email protected] nginx-1.4.7]# netstat -unltp | grep nginx

tcp    0    0.0.0.0:8080            0.0.0.0:*              LISTEN      40639/nginx

 

也可查看nginx的日誌是否啟動成功或是否有錯誤。

 

[[email protected] nginx-1.4.7]# cat /usr/local/nginx/logs/error.log

ngx_http_fastdfs_process_init pid=40640

[2014-03-26 03:47:17] INFO - local_host_ip_count: 2,  127.0.0.1  從機IP

[2014-03-26 03:47:17] INFO - fastdfs apache / nginx module v1.15, response_mode=proxy, base_path=/tmp, url_have_group_name=1, group_count=3, connect_timeout=2, network_timeout=30, tracker_server_count=1, if_alias_prefix=, local_host_ip_count=2, need_find_content_type=1, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, load_fdfs_parameters_from_tracker=1, storage_sync_file_max_delay=86400s, use_storage_id=0, storage server id count=0, flv_support=1, flv_extension=flv

[2014-03-26 03:47:17] (設定幾組顯示幾組)

INFO - group 1. group_name=group1, storage_server_port=23000, path_count=1, store_path0=/mnt/fastdfs_storage_data

[2014-03-26 03:47:17] 

INFO - group 2. group_name=group2, storage_server_port=23000, path_count=1, store_path0=/mnt/fastdfs_storage_data

[2014-03-26 03:47:17] 

INFO - group 3. group_name=group3, storage_server_port=23000, path_count=1, store_path0=/mnt/fastdfs_storage_data

 

在error.log中沒有錯誤,既啟動成功。可以開啟瀏覽器,直接存取http://從機:8080,查看是否彈出nginx歡迎頁面。

 

查看從機上傳的檔案:

http://10.120.20.191:8080/group1/M00/00/00/wKgAOVWsnq-AOMfVAADroWmJH48190_big.png

 

 

 

FastDFS在centos上的安裝配置與使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.