環境介紹
服務器: 阿里雲Centos7.4
FastDFS版本: fastdfs-5.11
搭建過程
1.安裝編譯環境
yum install git gcc gcc-c++ make automake vim wget libevent -y
2.安裝libfastcommon基礎庫
mkdir /root/fastdfs
cd /root/fastdfs
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
#編譯&&安裝
./make.sh && ./make.sh install
3.安裝FastDFS
cd /root/fastdfs
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
tar -zxvf V5.11.tar.gz
cd fastdfs-5.11
./make.sh && ./make.sh install
#配置文件準備
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
cp /root/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs
cp /root/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs
修改tracker配置文件
vim /etc/fdfs/tracker.conf
#需要修改的內容如下
port=22122
base_path=/home/fastdfs
修改storage配置文件
vim /etc/fdfs/storage.conf
#需要修改的內容如下
port=23000
base_path=/home/fastdfs # 數據和日誌文件存儲根目錄
store_path0=/home/fastdfs # 第一個存儲目錄
tracker_server=自己的ip:22122
# http訪問文件的端口(默認8888,看情況修改,和nginx中保持一致)
http.server_port=8888
4.啓動
mkdir /home/fastdfs -p
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
查看所有運行的端口 確認是否啓動成功
netstat -ntlp
5.測試上傳
vim /etc/fdfs/client.conf
修改client配置文件
#需要修改的內容如下
base_path=/home/fastdfs
#tracker服務器IP和端口
tracker_server=自己的ip:22122
放個圖片測試上傳
#保存後測試,返回ID表示成功 如:group1/M00/00/00/xxx.png
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/fastdfs/1.jpg
返回結果:group1/M00/00/00/wKjTiF7h5EWASb5aAACGZa9JdFo611.png
上傳成功
6.安裝fastdfs-nginx-module
cd /root/fastdfs
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
解壓
tar -xvf V1.20.tar.gz
cd fastdfs-nginx-module-1.20/src
vim config
修改第5 行 和 15 行 修改成
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
cp mod_fastdfs.conf /etc/fdfs
vim /etc/fdfs/mod_fastdfs.conf
#需要修改的內容如下
tracker_server=自己的ip:22122
url_have_group_name=true
store_path0=/home/fastdfs
mkdir -p /var/temp/nginx/client
7.安裝nginx
cd /root/fastdfs
wget http://nginx.org/download/nginx-1.15.6.tar.gz
tar -zxvf nginx-1.15.6.tar.gz
cd nginx-1.15.6/
yum -y install pcre-devel openssl openssl-devel
# 添加fastdfs-nginx-module模塊
./configure --add-module=/root/fastdfs/fastdfs-nginx-module-1.20/src
編譯安裝
make && make install
查看模塊是否安裝上
/usr/local/nginx/sbin/nginx -V
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
}
/usr/local/nginx/sbin/nginx
8.下載測試
關閉防火牆
systemctl stop firewalld
http://ip:8888/group1/M00/00/00/xxx.png
http://ip:8888/group1/M00/00/00/rBB66178UBuANJUuAAF_lLTfkr4986.jpg