一、CentOS7下搭建FastDFS+Nginx實現靜態圖片服務器


在集群環境下,圖片存放在本地存在諸多限制,一般采用單獨的圖片服務器進行管理。FastDFS就是這樣一個圖片管理服務器。

環境需求,CentOS7下

一.先下載三件套,並上傳到服務器中(Nginx自行下載),地址如下

  1:libfastcommon    https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz

  2:fastdfs    https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz

  3:fastdfs-nginx-module    http://jaist.dl.sourceforge.NET/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

二.安裝FastDFS需要先將官網下載的源碼進行編譯,編譯依賴gcc環境,如果沒有gcc環境,需要安裝gcc:yum install gcc-c++ 

三.安裝FastDFS之前,先安裝libevent工具包。yum -y install libevent

四.安裝libfastcommonV1.0.7工具包。

  1、解壓縮

  2、./make.sh  //先編譯

  3、./make.sh install

五.安裝tracker和storage(如果正式開發環境一般是安裝在多台服務器上,需要多次重新安裝)

  1、解壓縮

  2、./make.sh

  3、./make.sh install。安裝后在/usr/bin/目錄下有以fdfs開頭的文件都是編譯出來的。配置文件都放到/etc/fdfs文件夾

  4、把/root/FastDFS/conf目錄下的所有的配置文件都復制到/etc/fdfs下。

  5、配置tracker服務。修改/root/FastDFS/conf/tracker.conf文件。

    base_path=/home/fastdfs/tracker

  6、配置storage服務。修改/root/FastDFS/conf/storage.conf文件。

    base_path=/home/fastdfs/storage

    store_path0=/home/fastdfs/storage

    tracker_server=192.168.10.134:22122

  7、配置client服務。修改/root/FastDFS/conf/client.conf文件。

    base_path=/home/fastdfs/client

  8、測試是否成功

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

    如果正常輸出路徑如:example file url: http://192.168.10.134/group1/M00/00/00/wKgKhlmVwZSAZYk5AABdrZgsqUU888_big.jpg

    則表示配置成功!

六.安裝nginx並添加fastdfs模塊插件

  可以使用官方提供的nginx插件。要使用nginx插件需要重新編譯。fastdfs-nginx-module_v1.16.tar.gz

  1、解壓插件壓縮包

    修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉  

  2 .先在centOS上配置好對應的依賴關系,免得麻煩

    yum install gcc-c++(之前裝過的可以省略)

    yum install -y pcre pcre-devel

    yum install -y zlib zlib-devel、

  3.對nginx重新config  

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/root/fastdfs-nginx-module/src

  4.make install.

  5.把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件復制到/etc/fdfs目錄下。編輯:、

    load_fdfs_parameters_from_tracker=true

    tracker_server=192.168.10.134:22122

    url_have_group_name = true

    store_path0=/home/fastdfs/storage

  6.安裝完成后在var文件夾下新建temp/nginx文件夾。不然無法啟動nginx。

  7.配置nginx的配置文件,在/usr/local/nginx/conf下的nginx.conf文件,在底部新增一個server  

    server {
      listen 80;
      server_name 192.168.10.134;
      location /group1/M00/{
      ngx_fastdfs_module;
      }
    }

  8.啟動nginx並測試上次文件,記下文件路徑名

    訪問路徑:http://192.168.10.134/group1/M00/00/00/wKgKhlmVwZSAZYk5AABdrZgsqUU888_big.jpg

    能正常顯示表示配置一切正常!

    其中centOS7默認是不打開80端口的,這點很坑,需要自行打開

    firewall-cmd --zone=public --add-port=80/tcp --permanent 

    systemctl stop firewalld.service  

    systemctl start firewalld.service 

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM