一、準備環境
準備如下 tar 包:
fastdfs-6.06.tar.gz |
libfastcommon-1.0.43.tar.gz |
fastdfs-nginx-module-1.22.tar.gz |
nginx-1.17.7.tar.gz |
下載下傳位址:
fastdfs-nginx-module,libfastcommon,fastdfs nginx位址1、使用 wget 指令下載下傳壓縮包,如果沒有 wget 指令使用 yum 指令安裝
yum install wget
2、下載下傳 fastdfs
wget -c "https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz" \
-O fastdfs-6.06.tar.gz
3、下載下傳 libfastcommon
wget -c "https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz" \
-O libfastcommon-1.0.43.tar.gz
4、下載下傳 fastdfs-nginx-module
wget -c "https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz" \
-O fastdfs-nginx-module-1.22.tar.gz
5、下載下傳 nginx
wget -c http://nginx.org/download/nginx-1.17.7.tar.gz
6、安裝編譯工具及庫檔案
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
7、測試環境關閉防火牆
systemctl stop firewalld.service
8、開機禁用防火牆
systemctl disable firewalld.service
9、檢視防火牆狀态
firewall-cmd --state
二、解壓并編譯安裝
1、解壓下載下傳好的包
tar -zxvf fastdfs-6.06.tar.gz
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
tar -zxvf libfastcommon-1.0.43.tar.gz
tar -zxvf nginx-1.17.7.tar.gz
2、編譯安裝
2.1、編譯安裝 libfastcommon
1、進入解壓後的目錄
cd /root/download/libfastcommon-1.0.43
./make.sh && ./make.sh install
3、檢查
ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon
出現
libfastcommon.so
即成功
2.2、編譯安裝 fastdfs
cd /root/download/fastdfs-6.06
./make.sh && ./make.sh install
ls /usr/bin|grep fdfs
4、啟用配置檔案
cd /etc/fdfs/
cp storage.conf.sample storage.conf
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
mkdir -p /fastdfs/tracker
5、修改 tracker.conf 檔案
vi /etc/fdfs/tracker.conf
base_path = /fastdfs/tracker
6、啟動 tracker 服務
/etc/init.d/fdfs_trackerd start
7、檢查服務是否啟動
ps -ef|grep fdfs`
8、修改 storage.conf 檔案
vi /etc/fdfs/storage.conf
base_path = /fastdfs/storage store_path0 = /fastdfs/storage
tracker_server = 192.168.0.154:22122
http.server_port = 80
9、建立目錄
mkdir -p /fastdfs/storage
10、啟動 storage 服務
/etc/init.d/fdfs_storaged start
11、設定開機啟動
vi /etc/rc.d/rc.local
加入配置
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
12、編輯 client.conf 檔案
vi /etc/fdfs/client.conf
修改
base_path=/fastdfs/tracker
tracker_server=192.168.0.154:22122
2.3、安裝 nginx 和 fastdfs-nginx-module
1、安裝pcre
yum -y install pcre pcre-devel
2、進入解壓目錄
cd /root/download/nginx-1.17.7
3、添加 http_stub_status_module 子產品
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
4、進入 /root/download/fastdfs-nginx-module-1.22/src/
cd /root/download/fastdfs-nginx-module-1.22/src/
5、編輯配置檔案
vi config
6、将config檔案中的/usr/local替換成/usr
:%s+/usr/local+/usr
7、進入 nginx 解壓目錄
cd /root/download/nginx-1.17.7
8、添加fastdfs-nginx-module
./configure --add-module=/root/download/fastdfs-nginx-module-1.22/src/
9、編譯安裝
make && make install
10、複制并修改fastdfs-ngin-module中的配置檔案
cp /root/download/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
修改配置
connect_timeout=10
tracker_server=192.168.0.154:22122
url_have_group_name = true
store_path0=/fastdfs/storage
11、進入fastdfd源碼conf目錄
cd /root/download/fastdfs-6.06/conf/
11、将http.conf,mime.types兩個檔案拷貝到/etc/fdfs/目錄下
cp http.conf mime.types /etc/fdfs/
12、建立一個軟連接配接,在/fastdfs/storage檔案存儲目錄下建立軟連接配接,将其連結到實際存放資料 的目錄
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
13、編輯 nginx 配置
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name 192.168.0.154;
location ~/group([0-9])/M00 {
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
}
14、啟動 nginx
/usr/local/nginx/sbin/nginx
三、測試
1、下載下傳測試圖檔到本地
wget -c "https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=0f6379cdd8ca7bcb7d2ecf298e39475b/42a98226cffc1e17f7efcc3f4590f603738de968.jpg" -O boy.jpg
2、上傳測試圖檔
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/download/boy.jpg
得到傳回檔案名
group1/M00/00/00/wKgAml4RxbyARj9lAACxR4LEYRg912.jpg
與ip拼接:
http://192.168.0.154/group1/M00/00/00/wKgAml4RxbyARj9lAACxR4LEYRg912.jpg