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://www.cnblogs.com/debiao/p/6230260.html
http://blog.csdn.net/vanthyanhon/article/details/73718568

一鍵安裝腳本:

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

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