1. 程式人生 > 其它 >ubuntu傻瓜式搭建fastDFS

ubuntu傻瓜式搭建fastDFS

  1. 安裝基礎環境

    • apt install git gcc make automake autoconf libtool wget vim -y

    • mkdir /home/dfs #建立資料儲存目錄

    • cd /usr/local/src #切換到安裝目錄準備下載安裝包

  2. 安裝libfatscommon函式庫

  3. 安裝FastDFS

    1. cd ../ #返回上一級目錄
    2. git clone https://github.com/happyfish100/fastdfs.git --depth 1 cd fastdfs/
    3. ./make.sh && ./make.sh install #編譯安裝
  4. 配置檔案準備
    (本版本有一些不需要cp命令了,已經在/etc/fdfs資料夾下了,請根據實際情況)

    1. cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
    2. cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
    3. cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端檔案,測試用
    4. cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx訪問使用
    5. cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx訪問使用
  5. 安裝fastdfs-nginx-module

    1. cd ../
    2. git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
    3. cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
  6. 安裝pcre庫

    1. wget https://ftp.pcre.org/pub/pcre/pcre-8.33.tar.gz
    2. tar zxvf pcre-8.33.tar.gz
    3. ./configure
    4. make && make install
  7. 安裝nginx

    1. wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載nginx壓縮包
    2. tar -zxvf nginx-1.15.4.tar.gz #解壓
    3. cd nginx-1.15.4/
    4. ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ # 新增fastdfs-nginx-module模組
    5. make && make install #編譯安裝
  8. 單機部署 tracker配置

    1. vim /etc/fdfs/tracker.conf
    port=22122 # tracker伺服器埠(預設22122,一般不修改)
    base_path=/home/dfs # 儲存日誌和資料的根目錄
    
  9. storage配置

    1. vim /etc/fdfs/storage.conf
    port=23000 # storage服務埠(預設23000,一般不修改)
    base_path=/home/dfs # 資料和日誌檔案儲存根目錄
      store_path0=/home/dfs # 第一個儲存目錄
    tracker_server=192.168.1.172:22122 # tracker伺服器IP和埠 
    http.server_port=8888 # http訪問檔案的埠(預設8888,看情況修改,和nginx中保持一致)
    
  10. client配置

    1. vim /etc/fdfs/client.conf
base_path=/home/dfs 
    2. tracker_server=192.168.1.172:22122 #tracker伺服器IP和埠
  1. 進行測試上傳功能

    1. fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

    2. 儲存後測試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz

  2. 配置fastdfs-nginx-module模組

    1. vim /etc/fdfs/mod_fastdfs.conf
      tracker_server=192.168.1.172:22122 #tracker伺服器IP和埠 
      url_have_group_name=true store_path0=/home/dfs
    
  3. 配置nginx

    1. vim /usr/local/nginx/conf/nginx.conf # 新增如下配置
server { 
      listen 8888; ## 該埠為storage.conf中的http.server_port相同 
      server_name localhost;
       location ~/group[0-9]/ {
      ngx_fastdfs_module; 
      } 
      error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
      root html; 
      } 
}
測試下載,用外部瀏覽器訪問剛才已傳過的nginx安裝包,引用返回的ID
  http://192.168.1.172:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
  1. 其他問題
    1. 使用/usr/local/nginx/sbin/nginx
      啟動nginx時,出現/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
      ,可以查閱pcre常見問題

彈出下載單機部署全部跑通

常用命令

tracker

  • fdfs_trackerd /etc/fdfs/tracker.conf #啟動trackerd
  • fdfs_trackerd /etc/fdfs/tracker.conf restart #重啟動tracker服務
  • fdfs_trackerd /etc/fdfs/tracker.conf stop #停止tracker服務
  • chkconfig fdfs_trackerd on #自啟動tracker服務

storage

  • fdfs_storaged /etc/fdfs/storage.conf # 啟動storage服務

  • fdfs_storaged /etc/fdfs/storage.conf restart #重動storage服務

  • fdfs_storaged /etc/fdfs/storage.conf stop #停止動storage服務 chkconfig fdfs_storaged on #自啟動storage服務

nginx

  • /usr/local/nginx/sbin/nginx #啟動nginx
  • /usr/local/nginx/sbin/nginx -s reload #重啟nginx
  • /usr/local/nginx/sbin/nginx -s stop #停止nginx
  • /usr/local/nginx/sbin/nginx -t #校驗配置檔案正確性