FastDFS的安裝和使用

FastDFS的安裝和使用

本文是基於CentOS 7.3系統環境,進行FastDFS的安裝和使用

  • Nginx-1.5.1
  • CentOS 7.3

一、FastDFS簡介

(1) 什麼是FastDFS

FastDFS是一個開源的輕量級分佈式文件系統,它對文件進行管理,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負載均衡的問題。特別適合以文件爲載體的在線服務,如相冊網站、視頻網站等等。

二、FastDFS的安裝和使用

(1) 安裝準備軟件

yum install gcc-c++ perl
yum install pcre pcre-devel 
yum install zlib zlib-devel 
yum install openssl openssl--devel  
yum install libevent

(2) 下載安裝包

(3) 解壓nginx安裝包

tar -zxvf nginx-1.5.1.tar.gz  

(4) 創建和tracker和storage目錄

mkdir /usr/local/nginx/tracker
mkdir /usr/local/nginx/storage

(5) 解壓libfastcommon安裝包

tar -zxvf libfastcommon-1.0.38.tar.gz

(6) 編譯並安裝libfastcommon

# 進入nginx-1.7.4目錄
cd  libfastcommon-1.0.38
./make.sh 
./make.sh install      

(7) 解壓fastdfs安裝包

tar -zxvf fastdfs-5.11.tar.gz

(8) 編譯並安裝fastdfs

# 進入nginx-1.7.4目錄
cd  fastdfs-5.11
./make.sh 
./make.sh install      

(9) 驗證是否安裝成功

ll /etc/init.d/ | grep fdfs
# 出現以下內容說明安裝成功
-rwxr-xr-x. 1 root root   961 Apr 28 09:59 fdfs_storaged
-rwxr-xr-x. 1 root root   963 Apr 28 09:59 fdfs_trackerd  

[root@localhost fastdfs-5.11]# cd /etc/fdfs/
[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# cp storage.conf.sample storage.conf

(10) 複製配置文件模板

cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
cp storage.conf.sample storage.conf

(11) 配置fdfs_trackerd

vi /etc/fdfs/tracker.conf
# the base path to store data and log files
base_path=/usr/local/nginx/tracker

(12) 啓動fdfs_trackerd

service fdfs_trackerd start
ps -ef | grep fdfs_trackerd

(13) 設置開機自啓動fdfs_trackerd

chkconfig fdfs_trackerd on 

(14) 配置fdfs_storaged

vi /etc/fdfs/storage.conf
# the base path to store data and log files
base_path=/usr/local/nginx/storage
store_path0=/usr/local/nginx/storage
tracker_server=192.168.0.208:22122

(15) 啓動fdfs_storaged

service fdfs_storaged start
ps -ef | grep fdfs_storaged

(16) 設置開機自啓動fdfs_storaged

chkconfig fdfs_storaged on 

(17) 開放防火牆相關端口

firewall-cmd --add-port=22122/tcp --permanent
firewall-cmd --add-port=23000/tcp --permanent
firewall-cmd --reload

(18) 解壓fastdfs-nginx-module安裝包

tar -xzvf fastdfs-nginx-module-1.20.tar.gz
cd fastdfs-nginx-module-1.20/src

(19) 配置fastdfs-nginx-module

vi config
#
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

(20) 配置nginx與FastDFS關聯

cp mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
# 修改以下內容
connect_timeout=20
tracker_server=192.168.0.208:22122
url_have_group_name=true
store_path0=/usr/local/nginx/storage

(21) 拷貝相關配置文件

cd /root/FastDFS/fastdfs-5.11/conf
cp http.conf mime.types /etc/fdfs/

(22) 編譯nginx

cd /root/nginx-1.16.1
./configure --add-module=/root/FastDFS/fastdfs-nginx-module-1.20/src/
make
make install

(23) 配置nginx

vi nginx.conf
# 添加下面的內容
location ~/group([0-9])/ {
                ngx_fastdfs_module;
        }

(24) 重啓nginx

./nginx -s stop
./nginx

(25) nginx自啓動

chmod 777 /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx 
chkconfig nginx on

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章