1. 程式人生 > >CentOS-6.9下搭建FastDFS(文章最後有一鍵安裝指令碼)

CentOS-6.9下搭建FastDFS(文章最後有一鍵安裝指令碼)

1.所需安裝包

libfastcommon-master.zip
FastDFS_v5.05.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
nginx-1.8.0.tar.gz

2.安裝libfastcommon包

① 安裝libfastcommon前需要安裝以下依賴(系統如果有帶有,就不需要安裝):
yum install -y gcc
yum install -y gcc-c++

②解壓libfastcommon-master.zip
unzip libfastcommon-master.zip

③編譯
cd libfastcommon-master
./make.sh

④安裝
./make.sh install

3.安裝FastDFS

①解壓FastDFS安裝包
tar -zxvf FastDFS_v5.05.tar.gz

②編譯
cd FastDFS
./make.sh

③安裝
./make.sh install

4.配置Tracker服務

①進入FastDFS配置檔案所在目錄:
cd /etc/fdfs/

②修改配置檔名
mv client.conf.sample client.conf
mv storage.conf.sample storage.conf
mv tracker.conf.sample tracker.conf

③開啟tracker.conf,修改如下配置:

# the base path to store data and log files 
base_path=/opt/qiuxiao/fastdfs_tracker

注:設定tracker的資料目錄(data)和日誌目錄(logs)(指定目錄不存在則要先建立)

# the tracker server port
port=22122

注:埠引數不建議修改

④啟動tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

⑤檢視服務是否啟動成功
netstat -unltp|grep fdfs
這裡寫圖片描述

⑥Tracker新增到開機自啟動
vim /etc/rc.d/rc.local
將如下命令新增到檔案中
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
這裡寫圖片描述

5.配置Storage服務

①配置storage.conf檔案

# the base path to store data and log files
base_path=/opt/qiuxiao/fastdfs_storage_log

注:日誌目錄(指定目錄不存在則要先建立)

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/opt/qiuxiao/fastdfs_storage_data

注:儲存目錄(指定目錄不存在則要先建立)

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=10.211.55.7:22122

注:Tracker伺服器IP和埠(指定目錄不存在則要先建立)

②啟動Storage服務
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

③檢視服務啟動是否成功
netstat -unltp|grep fdfs
這裡寫圖片描述

④啟動成功後,通過fdfs_monitor檢視叢集情況,即storage是否已經註冊到了racker伺服器中
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
這裡寫圖片描述

⑤tracker新增到開機自啟動
vim /etc/rc.d/rc.local
將如下命令新增到檔案中
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf restart
這裡寫圖片描述

⑥配置client.conf檔案

# the base path to store log files
base_path=/opt/qiuxiao/fastdfs_tracker

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=10.211.55.7:22122

到此為止FasdDFS部署完成
接下來進入到Nginx模組安裝

6.安裝和配置Nginx和fastdfs-nginx-module模組

①安裝依賴
yum install -y gcc(安裝libfastcommon時已經安裝過)
yum install -y gcc-c++(安裝libfastcommon時已經安裝過)
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

②建立軟連結(因為 FastDFS 主程式設定的 lib 目錄是/usr/local/lib,所以需要建立軟連結)
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

③解壓nginx和fastdfs-nginx-module
拷貝fastdfs-nginx-module模組包到/usr/local下
cp /opt/download/fastdfs-nginx-module_v1.16.tar.gz /usr/local/

解壓nginx
tar -zxvf /opt/download/nginx-1.8.0.tar.gz

解壓fastdfs-nginx-module
tar -zxvf /usr/local/fastdfs-nginx-module_v1.16.tar.gz

④編輯vim /usr/local/fastdfs-nginx-module/src/config
修改CORE_INCS行,如下如,將路徑中的local全部去掉,即:
CORE_INCS=”$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/”
這裡寫圖片描述

⑤nginx加入fastdfs-nginx-module模組
cd nginx-1.8.0
./configure –prefix=/usr/local/nginx –add-module=/usr/local/fastdfs-nginx-module/src/
看到如下結果表示模組加入成功
這裡寫圖片描述

⑥安裝nginx
a)編譯nginx
make
這裡寫圖片描述
出現如上圖所示表示編譯成功

b)安裝nginx
make install
安裝完後,進入/usr/local/目錄,看見nginx檔案目錄表示nginx安裝成功
這裡寫圖片描述

輸入/usr/local/nginx/sbin/nginx -V,顯示如下資訊,表示fastdfs-nginx-module安裝成功
這裡寫圖片描述

⑦編輯nginx.conf
vim /usr/local/nginx/conf/nginx.conf
加入如下配置:
location /group1/M00 {
root /opt/qiuxiao/fastdfs_storage_data/data;
ngx_fastdfs_module;
}
這裡寫圖片描述

⑧複製配置檔案到/etc/fdfs下,編輯mod_fastdfs.conf檔案
a)複製FastDFS下的配置檔案http.conf和mime.types到/etc/fdfs下
cp /opt/download/FastDFS/conf/http.conf /etc/fdfs/
cp /opt/download/FastDFS/conf/mime.types /etc/fdfs/

b)複製fastdfs-nginx-module模組的配置檔案mod_fastdfs.conf到/etc/fdfs下
cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

c)編輯mod_fastdfs.conf
修改配置如下:

ca)儲存日誌目錄
# the base path to store log files
base_path=/opt/qiuxiao/fastdfs_storage_info

cb)tracker伺服器地址
# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=10.211.55.7:22122

cc)storage伺服器埠號
# the port of the local storage server
# the default value is 23000
storage_server_port=23000

cd)當前伺服器group名
# the group name of the local storage server
group_name=group1

ce)檔案url是否有group名
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true

cf)儲存路徑個數,store_path個數匹配
# path(disk or mount point) count, default value is 1
# must same as storage.conf
store_path_count=1

cg)儲存路徑
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/opt/qiuxiao/fastdfs_storage_data
#store_path1=/home/yuqing/fastdfs1

ch)從副檔名找到檔案型別
http.need_find_content_type=true

ci)設定組的個數
# set the group count
# set to none zero to support multi-group
# set to 0  for single group only
# groups settings section as [group1], [group2], ..., [groupN]
# default value is 0
# since v1.14
group_count = 1

cj)放開註釋掉的[group1],配置相關配置
# group settings for group #1
# since v1.14
# when support multi-group, uncomment following section
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/opt/qiuxiao/fastdfs_storage_data
#store_path1=/home/yuqing/fastdfs1

⑨啟動nginx
建立軟連結
ln -s /opt/qiuxiao/fastdfs_storage_data/data /opt/qiuxiao/fastdfs_storage_data/data/M00

啟動nginx
/usr/local/nginx/sbin/nginx
這裡寫圖片描述

放開80埠:
/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

訪問nginx,檢視nginx啟動是否成功
這裡寫圖片描述

7.測試

①使用命令方式上傳一張本地圖片到FastDFS
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/download/fsp.jpg
這裡寫圖片描述
這裡寫圖片描述

使用上圖中的url在瀏覽器中訪問上傳的檔案
這裡寫圖片描述

一鍵安裝指令碼:

https://download.csdn.net/download/qiuxiao630320/10302878
指令碼使用說明:
將指令碼放在CentOS任意目錄下,賦予指令碼可執行許可權,然後直接執行即可,一鍵傻瓜式安裝;
相關安裝目錄請參考上面的文章
注:指令碼在CentOS6.9環境下測試可用,但要保證機器已聯網,並且yum命令正常可用(這裡的可用包括支援yum安裝,並且不會存在yum源不穩定情況)