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 portport=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 filesbase_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 existstore_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 addresstracker_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 filesbase_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 addresstracker_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 filesbase_path=/opt/qiuxiao/fastdfs_storage_infocb)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 truetracker_server=10.211.55.7:22122cc)storage伺服器連接埠號碼# the port of the local storage server# the default value is 23000storage_server_port=23000cd)當前伺服器group名# the group name of the local storage servergroup_name=group1ce)檔案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 falseurl_have_group_name = truecf)儲存路徑個數,store_path個數匹配# path(disk or mount point) count, default value is 1# must same as storage.confstore_path_count=1cg)儲存路徑# store_path#, based 0, if store_path0 not exists, it's value is base_path# the paths must be exist# must same as storage.confstore_path0=/opt/qiuxiao/fastdfs_storage_data#store_path1=/home/yuqing/fastdfs1ch)從副檔名找到檔案類型http.need_find_content_type=trueci)設定組的個數# 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.14group_count = 1cj)放開注釋掉的[group1],配置相關配置# group settings for group #1# since v1.14# when support multi-group, uncomment following section[group1]group_name=group1storage_server_port=23000store_path_count=1store_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源不穩定情況)