1. 程式人生 > 其它 >java 程式設計技術 FastDFS 安裝和配置

java 程式設計技術 FastDFS 安裝和配置

 fastdfs結構說明

 

一 、FastDFS--tracker安裝

1  FastDFS安裝環境

FastDFS是C語言開發,建議在linux上執行,本教程使用Centos7.4作為安裝環境。

安裝gcc 依賴環境 yum install gcc-c++ -y

  1.  安裝libevent

2.1  yum -y install libevent

3  安裝libfastcommon

1、上傳壓縮包檔案libfastcommonV1.0.7.tar.gz 到 /usr/local目錄下,並解壓。

2、tar -zxvf libfastcommonV1.0.7.tar.gz

3、進入到解壓後的資料夾中

 4、進行編譯 ./make.sh

5、如果出現編譯perl 不識別 執行下面這段命令

# yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget

 安裝 ./make.sh install

 注意:libfastcommon安裝好後會自動將庫檔案拷貝至/usr/lib64下,由於FastDFS程式引用usr/lib目錄所以需要將/usr/lib64下的庫檔案拷貝至/usr/lib下。

# cp /usr/lib64/libfastcommon.so /usr/lib

  1. tracker編譯安裝
  2. 上傳資料FastDFS_v5.05.tar.gz到 /usr/local 目錄下

2、解壓編譯安裝

tar -zxvf FastDFS_v5.05.tar.gz

cd FastDFS

./make.sh   

./make.sh install

3、安裝成功之後,將安裝目錄下的conf下的檔案拷貝到/etc/fdfs/下。

cd conf

cp  *  /etc/fdfs/

4、修改配置檔案

vim  /etc/fdfs/tracker.conf

 

  1. 建立fastdfs資料夾
  2. mkdir  /opt/fastdfs

5 設定啟動項

mkdir  /usr/local/fdfs  

拷貝安裝目錄下stop.sh 和restart.sh 到/usr/local/fdfs/

cp restart.sh  /usr/local/fdfs/

cp stop.sh  /usr/local/fdfs/

 修改啟動指令碼

vim /etc/init.d/fdfs_trackerd

 

 把啟動指令碼中的路徑按照上圖修改

修改完畢後

註冊服務

chkconfig  --add  fdfs_trackerd

 

然後可以用service fdfs_trackerd start 啟動測試 如下圖

 

二、FastDFS--storage安裝

1 修改配置檔案

vim /etc/fdfs/storage.conf

 

 

2 建立fdfs_storage資料夾

mkdir /opt/fastdfs/fdfs_storage

3 設定啟動服務

vim  /etc/init.d/fdfs_storaged

 

 chkconfig  - -add  fdfs_storaged

啟動服務

service fdfs_storaged start

 

4功能檔案目錄總結說明

/opt/fastdfs/

資料檔案及日誌

/usr/bin/fdfs_trackerd 、 fdfs_storaged

啟動執行程式

/usr/local/fdfs/ stop.sh 、 restart.sh

關閉、重啟指令碼

/etc/init.d/fdfs_tracked 、fdfs_storaged

服務啟動指令碼

/etc/fdfs/

配置檔案

 

5 上傳圖片測試

FastDFS安裝成功可通過/usr/bin/fdfs_test測試上傳、下載等操作。

 

修改/etc/fdfs/client.conf

[root@localhost ~]# vim /etc/fdfs/client.conf

base_path=/opt/fastdfs

tracker_server=192.168.67.163:22122

 比如將/root下的日誌上傳到FastDFS中:

/usr/bin/fdfs_test  /etc/fdfs/client.conf  upload  /root/winteriscoming.jpg

 對應的上傳路徑:

/opt/fastdfs/fdfs_storage/data /00/00/wKhDo1qipbiAJC6iAAB1tayPlqs094_big.jpg

 

三、FastDFS整合nginx

1 安裝前配置fastdfs-nginx-module

上傳fastdfs-nginx-module_v1.16.tar.gz上傳到 /usr/local,並解壓

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

編輯配置檔案:修改config檔案將/usr/local/路徑改為/usr/

vim fastdfs-nginx-module/src/config

 將FastDFS-nginx-module/src下的mod_fastdfs.conf拷貝至/etc/fdfs/下

[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/

並修改mod_fastdfs.conf的內容:

vim /etc/fdfs/mod_fastdfs.conf

 繼續修改

 繼續修改 url中包含group名稱

 繼續修改  #指定檔案儲存路徑

 將libfdfsclient.so拷貝至/usr/lib下

[root@localhost src]# cp /usr/lib64/libfdfsclient.so /usr/lib/

2 安裝fastdfs-nginx-module

建立nginx/client目錄

[root@localhost src]# mkdir -p /var/temp/nginx/client

cd nginx的原始程式目錄

 
 

配置成功

 編譯

[root@localhost nginx-1.12.2]# make

安裝

[root@localhost nginx-1.12.2]# make install

3 編輯nginx.conf

vim /usr/local/nginx/conf/nginx.conf

server {

        listen       80;

        server_name  file.gmall.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

        location /group1/M00/ {

             ngx_fastdfs_module;

        }

啟動nginx

/usr/local/nginx/sbin/nginx

設定開機啟動

[root@iZ2zednyjjxxq7k3i2dwsfZ nginx-1.12.2]# vim /etc/rc.d/rc.local

 

需要關閉防火牆

service iptables stop

永久關閉 chkconfig  iptables  off

測試

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/ty.jpg

 顯示結果:

 

4  問題排查

開啟vim /usr/local/nginx/conf/nginx.conf

 然後去logs/error.log 檢視報錯。

四、 附:nginx註冊服務指令碼

#!/bin/bash

#chkconfig:2345 21 91

#decription: nginx-server

nginx=/usr/local/nginx/sbin/nginx

case "$1" in

        start)

                netstat -anlpt | grep nginx

            if

                [ $? -eq 0 ]

             then

                echo " the nginx-server is already running"

            else

                echo " ther nginx-server is starting to run"

                $nginx

            fi

         ;;

       stop)

              netstat -anlpt | grep nginx

                if

                [ $? -eq 0 ]

              then

                   $nginx -s stop

                   if [ $? -eq 0 ]

                      then

                          echo " the nginx-server is stopped "

                   else

                          echo " failed to stop the nginx-server"

                  fi

            else

               echo " the nginx-server has stopped you needn't to stop it "

            fi

         ;;

     restart)

                 $nginx -s reload

             if

                 [ $? -eq 0 ]

               then

                  echo "the nginx-server is restarting "

              else

                  echo " the nginx-server failed to restart"

             fi

         ;;

 

        status)

                   netstat -anlpt | grep nginx

             if

                 [ $? -eq 0 ]

               then

                   echo " the nginx-server is running "

            else

                   echo " the nginx-server is not running ,please try again"

             fi

       ;;

 

        status)

                   netstat -anlpt | grep nginx

             if

                 [ $? -eq 0 ]

               then

                   echo " the nginx-server is running "

            else

                   echo " the nginx-server is not running ,please try again"

             fi

         ;;

        *)

               echo "please enter { start|stop|status|restart}"

        ;;

esac