Centos8 安裝最新版fastdfs

Centos8 安裝fastdfs6.06

FastDFS是一個開源的高性能分佈式文件系統。它的主要功能包括:文件存儲,文件同步和文件訪問(文件上傳和文件下載),它可以解決高容量和負載平衡問題。FastDFS應該滿足基於照片共享站點和視頻共享站點等文件的網站的要求。

官方GitHub地址

準備安裝文件

使用 wget 命令下載壓縮包,如果沒有 wget 命令使用 yum 命令安裝

yum install wget

文件存放位置:/usr/local/src

文件名 命令
fastdfs-6.06.tar.gz wget -c “https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz” -O fastdfs-6.06.tar.gz
libfastcommon-1.0.43.tar.gz wget -c “https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz” -O libfastcommon-1.0.43.tar.gz
fastdfs-nginx-module-1.22.tar.gz wget -c “https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz” -O fastdfs-nginx-module-1.22.tar.gz
nginx-1.17.7.tar.gz wget -c http://nginx.org/download/nginx-1.17.7.tar.gz

編譯安裝

編譯環境安裝

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

編譯安裝libfatscommon

  1. 進入解壓後的目錄
cd /usr/local/src/libfastcommon-1.0.43
  1. 編譯安裝
./make.sh && ./make.sh install
  1. 檢查
ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon
出現libfastcommon.so即成功

編譯安裝fastdfs

  1. 進入解壓後的目錄
cd /usr/local/src/fastdfs-6.06
  1. 編譯安裝
./make.sh && ./make.sh install
  1. 檢查
ls /usr/bin|grep fdfs

配置FastFDS跟蹤器(Tracker)

  1. 啓用配置文件
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
  1. 修改 tracker.conf 文件
vi /etc/fdfs/tracker.conf

配置文件是否不生效,false爲生效
disabled = false
提供服務端口
port = 22122
Tracker 數據和日誌目錄地址(根目錄必須存在,子目錄會自動創建)
base_path = /fastdfs/tracker
HTTP 服務端口 默認8080,建議修改防止衝突
http.server_port = 8080

  1. 創建Tracker基礎數據目錄,即base_path對應的目錄
mkdir -p /fastdfs/tracker
  1. 啓動Tracker服務
# 啓動
systemctl start fdfs_trackerd
# 重啓
systemctl restart fdfs_trackerd
# 查看服務狀態
systemctl status fdfs_trackerd
# 檢查服務是否啓動
ps -ef | grep fdfs
# 22122端口正在被監聽,則算Tracker服務安裝成功
netstat -tulnp | grep fdfs
# 關閉
systemctl stop fdfs_trackerd
  1. 設置開機啓動
systemctl enable fdfs_trackerd.service

配置FastFDS存儲(Storage)

  1. 啓用配置文件
cd /etc/fdfs/
cp storage.conf.sample storage.conf
  1. 修改 storage.conf 文件
vi /etc/fdfs/storage.conf

Storage 數據和日誌目錄地址(根目錄必須存在,子目錄會自動創建)
base_path = /fastdfs/storage/base
逐一配置 store_path_count 個路徑,索引號基於 0
如果不配置,那就和base_path一樣
store_path0 = /fastdfs/storage
tracker_server 的列表,多個時,每個寫一行(會主動連接 tracker_server)
tracker_server = ip:22122
HTTP 服務端口 默認8888,建議修改防止衝突
http.server_port = 8888

  1. 創建Tracker基礎數據目錄,即base_path對應的目錄
# 對應base_path
mkdir -p  /fastdfs/storage/base
# 對應store_path0,有多個要創建多個
mkdir -p  /fastdfs/storage
  1. 啓動Storage服務
# 啓動
systemctl start fdfs_storaged
# 重啓
systemctl restart fdfs_storaged
# 查看服務狀態
systemctl status fdfs_storaged
# 檢查服務是否啓動
ps -ef | grep fdfs
# 22122端口正在被監聽,則算Tracker服務安裝成功
netstat -tulnp | grep fdfs
# 關閉
systemctl stop fdfs_storaged
  1. 查看Storage和Tracker是否在通信
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
  1. 設置開機自啓
systemctl enable fdfs_storaged.service

上傳測試

  1. 修改客戶端配置文件
cd /etc/fdfs/
cp client.conf.sample client.conf
vi /etc/fdfs/client.conf

Client 的數據和日誌目錄
base_path= /fastdfs/client
Tracker 端口
tracker_server=ip:22122

  1. 上傳執行命令
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf xxx.jpg

上傳成功返回文件ID號:

組名 磁盤 目錄 文件名
group1 /M00 /00 /xxx.jpg

安裝配置Nginx模塊

安裝配置fastfds-nginx-module模塊

  1. 進入解壓目錄
cd /usr/local/src/nginx-1.17.7
  1. 添加 http_stub_status_module 模塊
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
  1. 進入 /usr/local/src/fastdfs-nginx-module-1.22/src/
cd /usr/local/src/fastdfs-nginx-module-1.22/src/
  1. 編輯配置文件
vi config
# 將config文件中的/usr/local替換成/usr
:%s+/usr/local+/usr
  1. 進入 nginx 解壓目錄
cd /usr/local/src/nginx-1.17.7
  1. 添加fastdfs-nginx-module
./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.22/src/
# 編譯安裝
make && make install
  1. 複製並修改fastdfs-ngin-module中的配置文件
cp /usr/local/src/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

  1. 將http.conf,mime.types兩個文件拷貝到/etc/fdfs/目錄下
cp http.conf mime.types /etc/fdfs/
  1. 創建一個軟連接,在/fastdfs/storage文件存儲目錄下創建軟連接,將其鏈接到實際存放數據 的目錄(可以省略)
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
  1. 編輯Nginx配置
vi /usr/local/nginx/conf/nginx.conf

server {
    listen       80;# 建議修改,防止衝突
    server_name  ip;
    location ~/group([0-9])/M00 {
            root  /fastdfs/storage/data;
            ngx_fastdfs_module;
    }
}
  1. 啓動Ngnix
/usr/local/nginx/sbin/nginx

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