1. 程式人生 > >檔案伺服器搭建(ubuntu16.0.04+fastdfs+nginx)

檔案伺服器搭建(ubuntu16.0.04+fastdfs+nginx)

檔案伺服器搭建(ubuntu16.0.04+fastdfs+nginx)

1、環境

ubuntu 16.0.4(visualbox虛擬的ubuntu伺服器)
fastdfs 5.11
nginx 1.12 實現檔案伺服器上檔案的訪問

2、資源準備

3、搭建

  • 編譯安裝 libfastcommon
> ./make.sh   #編譯  
> ./make.sh install   # 安裝   
> ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
#建立符號連結
  • 編譯安裝 fastdfs
> ./make.sh  #編譯 
> ./make.sh install #安裝 
  • 配置tracker.conf
> cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
> vi /etc/fdfs/tracker.conf

 修改內容:
> base_path=/home/fastdfs
  • 配置storage.conf
> cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
> vi /etc/fdfs/storage.conf 修改內容: > base_path=/home/fastdfs > tracker_server=10.0.2.15:22122 > store_path0=/home/fastdfs
  • 配置 http.conf mime.types
> cp fastdfs-5.11/conf/http.conf /etc/fdfs/  
> cp fastdfs-5.11/conf/mime.types /etc/fdfs/
  • 配置client.conf
> cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf   
> vi /etc/fdfs/client.conf
修改內容
> base_path=/home/fastdfs
>  tracker_server=10.0.2.15:22122
>  include http.conf   #開啟該行程式碼  預設是註釋掉的
  • 啟動tracker
> /etc/init.d/fdfs_trackerd start

其他命令
/etc/init.d/fdfs_trackerd stop #停止
/etc/init.d/fdfs_trackerd restart #重啟
  • 啟動storage
> /etc/init.d/fdfs_storaged start  

其他命令
/etc/init.d/fdfs_storaged stop #停止
/etc/init.d/fdfs_storaged restart #重啟
  • 檢視啟動情況
> ps -aux|grep fdfs

顯示內容如下 代表啟動成功;如果失敗,進入目錄/home/fastdfs 檢視錯誤日誌資訊

root      1543  0.0  0.2 145628  2260 ?        Sl   08:50   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root      1596  0.0  6.4  82272 65800 ?        Sl   08:50   0:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root      1699  0.0  0.0  14224   968 pts/0    S+   11:01   0:00 grep --color=auto fdfs

  • 測試fastdfs安裝情況
>  fdfs_test /etc/fdfs/client.conf upload /home/test.png  
This is FastDFS client test program v5.11


Copyright (C) 2008, Happy Fish / YuQing


FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.


[2018-06-08 11:06:33] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0


tracker_query_storage_store_list_without_group: 
    server 1. group_name=, ip_addr=10.0.2.15, port=23000


group_name=group1, ip_addr=10.0.2.15, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399.jpg
source ip address: 10.0.2.15
file timestamp=2018-06-08 11:06:33
file size=4096
file crc32=4105284023
example file url: http://10.0.2.15/group1/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg
source ip address: 10.0.2.15
file timestamp=2018-06-08 11:06:33
file size=4096
file crc32=4105284023
example file url: http://10.0.2.15/group1/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg

  • 安裝nginx
> apt-get install libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev 
> tar -zxvf /home/ubuntu/source/nginx-1.12.2.tar.gz
> cd /home/ubuntu/source/nginx
> ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src/  # --prefix:安裝目錄;--add-module:fastdfs-nginx-module檔案路徑
> make  #編譯 
> make install #安裝 
> vi /usr/local/nginx/conf/nginx.conf #新增檔案服務站點配置


新增內容如下
location /M00 {
    root /home/fastdfs/data;
    ngx_fastdfs_module;
}
  • 啟動和檢查
> /usr/local/nginx/sbin/nginx

其他命令
>/usr/local/nginx/sbin/nginx -s stop #停止
>/usr/local/nginx/sbin/nginx -s reload #重新載入配置檔案

檢查nginx啟動情況

> ps -aux|grep nginx

正常情況下資訊,如果啟動失敗,進入/usr/local/nginx/logs/ 目錄檢視錯誤資訊

root      1607  0.0  0.0  32480   456 ?        Ss   08:50   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    1608  0.0  0.3  33060  3372 ?        S    08:50   0:00 nginx: worker process
root      1756  0.0  0.1  14224  1088 pts/0    S+   11:28   0:00 grep --color=auto nginx

訪問剛測試上傳的圖片

http://10.0.2.15/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg

4、歸納總結

整個安裝過程比較簡單,注意好安裝的每一個細節.至此安裝結束.
我安裝是在本機的虛擬機器安裝。採用的連結模式:網路地址轉換(NAT);
這種情況下需要新增埠轉發,配置如下:

主機IP 主機埠 子系統IP 子系統埠
本地IP 22122 10.0.2.15 22122
本地IP 23000 10.0.2.15 23000
本地IP 8005 10.0.2.15 80
22122:tracker服務埠
23000:檔案上傳服務storage埠
80:nginx 檔案站點服務埠