日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux系统:centos7下搭建Nginx和FastDFS文件管理中间件

發布時間:2025/3/17 linux 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux系统:centos7下搭建Nginx和FastDFS文件管理中间件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、FastDFS簡介

1、基礎概念

FastDFS是一個開源的輕量級分布式文件系統,它對文件進行管理,功能包括:文件存儲、文件同步、文件上傳、文件下載等,解決了大容量存儲和負載均衡的問題。

2、環境概覽

1、默認存在Gcc編譯環境,Centos7虛擬機 2、安裝LibFastCommon環境 3、FastDFS中間件安裝 4、Nginx代理服務器安裝

二、安裝LibFastCommon

核心流程

下載->解壓->編譯->安裝

## 下載 [root@localhost mysoft]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz ## 解壓 [root@localhost mysoft]# tar -zxvf V1.0.38.tar.gz [root@localhost mysoft]# cd libfastcommon-1.0.38/ ## 編譯 [root@localhost libfastcommon-1.0.38]# ./make.sh ## 安裝 [root@localhost libfastcommon-1.0.38]# ./make.sh install

三、安裝FastDFS

流程:下載->解壓->編譯->安裝->創建相關路徑->配置跟蹤器->
配置數據存儲->配置客戶端->Nginx環境配置

1、基礎安裝步驟

## 下載 [root@localhost mysoft]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz ## 解壓 [root@localhost mysoft]# tar -zxvf V5.11.tar.gz ## 編譯 [root@localhost mysoft]# cd fastdfs-5.11/ [root@localhost fastdfs-5.11]# ./make.sh ## 安裝 [root@localhost fastdfs-5.11]# ./make.sh install

2、創建相關路徑

用處后續說明。

[root@localhost data]# mkdir -p /data/fastdfs/log [root@localhost data]# mkdir -p /data/fastdfs/data [root@localhost data]# mkdir -p /data/fastdfs/tracker [root@localhost data]# mkdir -p /data/fastdfs/client

3、配置跟蹤器

Tracker – >> 跟蹤器

1)查看配置文件

注意這里目錄的轉換,這里給的是樣例,具體的配置還要自己動手。

[root@localhost fastdfs-5.11]# cd /etc/fdfs/ [root@localhost fdfs]# ll total 24 client.conf.sample storage.conf.sample storage_ids.conf.sample tracker.conf.sample

2)配置tracker.conf文件

[root@localhost fdfs]# cp tracker.conf.sample tracker.conf [root@localhost fdfs]# vim tracker.conf ## 關注如下幾個配置 ## 存儲數據和日志文件的基本路徑 base_path=/data/fastdfs/tracker ## Http服務端口 http.server_port=80 ## 默認提供服務端口 port=22122

3)啟動跟蹤器

## 啟動 [root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start ## 查看狀態 [root@localhost fdfs]# netstat -apn|grep fdfs

4、配置數據存儲

1)查看配置文件

[root@localhost fastdfs-5.11]# cd /etc/fdfs/ [root@localhost fdfs]# ll storage.conf.sample

2)配置storage.conf文件

[root@localhost fdfs]# cp storage.conf.sample storage.conf [root@localhost fdfs]# vim storage.conf ## 關注如下幾個配置 ## storage存儲data和log的跟路徑 base_path=/data/fastdfs/data ## 默認組名 group_name=group1 ## 默認端口,相同組的storage端口號必須一致 port=23000 ## 配置一個存儲路徑 store_path_count=1 store_path0=/data/fastdfs/data ## 配置跟蹤器IP和端口 tracker_server=192.168.72.130:22122

3)啟動存儲服務

## 啟動 [root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start ## 查看進程 [root@localhost fdfs]# netstat -apn|grep fdfs tcp 0:22122 LISTEN 4845/fdfs_trackerd tcp 0:45422 SYN_SENT 5410/fdfs_storaged ## 查看啟動日志 [root@localhost fdfs]# tail -f /data/fastdfs/data/logs/storaged.log ## 日志展示:單臺FastDFS安裝成功 set tracker leader: 192.168.72.130:22122 ## 查看Storage和Tracker是否在通信 [root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf Storage 1:id = 192.168.72.130ip_addr = 192.168.72.130 (localhost.localdomain) ACTIVE

5、配置客戶端測試

1)查看配置文件

[root@localhost /]# cd /etc/fdfs [root@localhost fdfs]# ll total 40 client.conf.sample

2)配置client.conf文件

[root@localhost fdfs]# cp client.conf.sample client.conf [root@localhost fdfs]# vim client.conf ## 關注如下幾個配置 ## client數據和日志目錄 base_path=/data/fastdfs/client ## 配置跟蹤器IP和端口 tracker_server=192.168.72.130:22122

3)客戶端測試

調用客戶端文件上傳命令

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf

返回文件上傳的相對路徑和編號

group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

[root@localhost fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /data/img/img1.jpg group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

這樣FastDFS單臺環境就安裝好了,步驟有點繁雜,不過這就是生活。

文件成功上傳storage服務器,但是還無法查看下載。需要安裝Nginx服務器用來支持Http方式訪問文件。

四、安裝Nginx

1、下載解壓Nginx

## 下載nginx [root@localhost mysoft]# wget http://nginx.org/download/nginx-1.15.2.tar.gz ## 解壓nginx [root@localhost mysoft]# tar -zxvf nginx-1.15.2.tar.gz

2、下載解壓Fast-Nginx

## 下載fastdfs-nginx [root@localhost mysoft]#wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip ## 解壓fastdfs-nginx [root@localhost mysoft]# mv 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip fast-nginx.zip [root@localhost mysoft]# unzip fast-nginx.zip [root@localhost mysoft]# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1/ fastdfs-nginx-module

3、安裝必須依賴

## pcre-devel 環境 [root@localhost nginx-1.15.2]# yum install -y pcre pcre-devel ## zlib-devel 環境 [root@localhost nginx-1.15.2]# yum install -y zlib zlib-devel ## openssl-devel 環境 [root@localhost nginx-1.15.2]# yum install -y openssl openssl-devel

4、配置安裝

[root@localhost nginx-1.15.2]# ./configure --add-module=/usr/local/mysoft/fastdfs-nginx-module/src [root@localhost nginx-1.15.2]# make && make install

5、錯誤解決

版本問題導致,Fast-Nginx必須使用這個修復版本。

https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1 make[1]: Leaving directory `/usr/local/mysoft/nginx-1.15.2' make: *** [build] Error 2

6、查看安裝結果

如下情況則表示安裝成功了。

[root@localhost nginx-1.15.2]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.15.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src

五、測試圖片訪問

1、配置客戶端

## 移動配置文件 [root@localhost src]# pwd /usr/local/mysoft/fastdfs-nginx-module/src [root@localhost src]# ll total 76 Apr 14 2017 mod_fastdfs.conf [root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/ [root@localhost fdfs]# pwd /etc/fdfs [root@localhost fdfs]# vim mod_fastdfs.conf ## 調整如下配置 ## 鏈接超時 connect_timeout=20 ## 配置跟蹤器IP和端口 tracker_server=192.168.72.130:22122 ## 路徑包含group url_have_group_name = true # 必須和storage配置相同 store_path0=/data/fastdfs/data

2、完善FastDFS配置

[root@localhost fdfs]# cd /usr/local/mysoft/fastdfs-5.11/conf/ [root@localhost conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/

3、配置Nginx

在Nginx的80服務端口下添加如下配置。注意這里的路徑是Nginx安裝自動生成的路徑。

[root@localhost nginx]# cd /usr/local/nginx/conf/ [root@localhost conf]# vim nginx.conf server {listen 80;location ~/group([0-9])/M00 {root /data/fastdfs/data;ngx_fastdfs_module;} }

查看配置結果

[root@localhost conf]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.15.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src

這樣就配置成功了。

4、見證結束的時候

啟動Nginx服務。

## 啟動 /usr/local/nginx/sbin/nginx ## 停止 /usr/local/nginx/sbin/nginx -s stop ## 重啟 /usr/local/nginx/sbin/nginx -s reload

5、訪問上傳圖片

喵喵的,居然成功了,下篇文章見。

http://192.168.72.130 /group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

六、源代碼地址

GitHub地址:知了一笑 https://github.com/cicadasmile 碼云地址:知了一笑 https://gitee.com/cicadasmile


總結

以上是生活随笔為你收集整理的Linux系统:centos7下搭建Nginx和FastDFS文件管理中间件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。