分布式文件系統(tǒng)FastDFS安裝教程1(安裝、配置、部署、防盜鏈、nginx、圖片壓縮)

相關(guān)鏈接:SpringBoot項(xiàng)目中Fastdfs配置及使用2

環(huán)境準(zhǔn)備

使用的系統(tǒng)軟件

名稱(chēng) 說(shuō)明
centos 7.x
libfatscommon FastDFS分離出的一些公用函數(shù)包
FastDFS FastDFS本體
fastdfs-nginx-module FastDFS和nginx的關(guān)聯(lián)模塊
nginx nginx1.15.4

編譯環(huán)境

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

磁盤(pán)目錄

說(shuō)明 位置
所有安裝包 /usr/local/src
數(shù)據(jù)存儲(chǔ)位置 /home/dfs/

這里我為了方便把日志什么的都放到了dfs

mkdir /home/dfs #創(chuàng)建數(shù)據(jù)存儲(chǔ)目錄
cd /usr/local/src #切換到安裝目錄準(zhǔn)備下載安裝包

安裝libfatscommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #編譯安裝

安裝FastDFS

cd ../ #返回上一級(jí)目錄
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #編譯安裝
#配置文件準(zhǔn)備
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 #客戶(hù)端文件,測(cè)試用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx訪問(wèn)使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx訪問(wèn)使用

安裝fastdfs-nginx-module

cd ../ #返回上一級(jí)目錄
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

安裝nginx

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載nginx壓縮包
tar -zxvf nginx-1.15.4.tar.gz #解壓
cd nginx-1.15.4/
#添加fastdfs-nginx-module模塊
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
make && make install #編譯安裝

單機(jī)部署

/home/jrpt/fast_dfs

tracker配置

#服務(wù)器ip為 192.168.52.1
#我建議用ftp下載下來(lái)這些文件 本地修改
vim /etc/fdfs/tracker.conf
#需要修改的內(nèi)容如下
port=22122  # tracker服務(wù)器端口(默認(rèn)22122,一般不修改)
base_path=/home/dfs  # 存儲(chǔ)日志和數(shù)據(jù)的根目錄

storage配置

vim /etc/fdfs/storage.conf
#需要修改的內(nèi)容如下
port=23000  # storage服務(wù)端口(默認(rèn)23000,一般不修改)
base_path=/home/dfs  # 數(shù)據(jù)和日志文件存儲(chǔ)根目錄
store_path0=/home/dfs  # 第一個(gè)存儲(chǔ)目錄
tracker_server=192.168.52.1:22122  # tracker服務(wù)器IP和端口
http.server_port=8888  # http訪問(wèn)文件的端口(默認(rèn)8888,看情況修改,和nginx中保持一致)

client測(cè)試

vim /etc/fdfs/client.conf
#需要修改的內(nèi)容如下
base_path=/home/dfs
tracker_server=192.168.52.1:22122    #tracker服務(wù)器IP和端口
#保存后測(cè)試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

配置nginx訪問(wèn)

vim /etc/fdfs/mod_fastdfs.conf
#需要修改的內(nèi)容如下
tracker_server=192.168.52.1:22122  #tracker服務(wù)器IP和端口
url_have_group_name=true
store_path0=/home/dfs
#配置nginx.config
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
    listen       8888;    ## 該端口為storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}
#測(cè)試下載,用外部瀏覽器訪問(wèn)剛才已傳過(guò)的nginx安裝包,引用返回的ID
http://192.168.52.1:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
#彈出下載單機(jī)部署全部跑通

啟動(dòng)

防火墻

#不關(guān)閉防火墻的話無(wú)法使用
systemctl stop firewalld.service #關(guān)閉
systemctl restart firewalld.service #重啟

tracker

/etc/init.d/fdfs_trackerd start #啟動(dòng)tracker服務(wù)
/etc/init.d/fdfs_trackerd restart #重啟動(dòng)tracker服務(wù)
/etc/init.d/fdfs_trackerd stop #停止tracker服務(wù)
chkconfig fdfs_trackerd on #自啟動(dòng)tracker服務(wù)

storage

/etc/init.d/fdfs_storaged start #啟動(dòng)storage服務(wù)
/etc/init.d/fdfs_storaged restart #重動(dòng)storage服務(wù)
/etc/init.d/fdfs_storaged stop #停止動(dòng)storage服務(wù)
chkconfig fdfs_storaged on #自啟動(dòng)storage服務(wù)

nginx

/usr/local/nginx/sbin/nginx #啟動(dòng)nginx
/usr/local/nginx/sbin/nginx -s reload #重啟nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx

檢測(cè)集群

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
# 會(huì)顯示會(huì)有幾臺(tái)服務(wù)器 有3臺(tái)就會(huì) 顯示 Storage 1-Storage 3的詳細(xì)信息

說(shuō)明

配置文件

tracker_server #有幾臺(tái)服務(wù)器寫(xiě)幾個(gè)
group_name #地址的名稱(chēng)的命名
bind_addr #服務(wù)器ip綁定
store_path_count #store_path(數(shù)字)有幾個(gè)寫(xiě)幾個(gè)
store_path(數(shù)字) #設(shè)置幾個(gè)儲(chǔ)存地址寫(xiě)幾個(gè) 從0開(kāi)始

可能遇到的問(wèn)題

如果不是root 用戶(hù) 你必須在除了cd的命令之外 全部加sudo
如果不是root 用戶(hù) 編譯和安裝分開(kāi)進(jìn)行 先編譯再安裝
如果上傳成功 但是nginx報(bào)錯(cuò)404 先檢查mod_fastdfs.conf文件中的store_path0是否一致
如果nginx無(wú)法訪問(wèn) 先檢查防火墻 和 mod_fastdfs.conf文件tracker_server是否一致
如果不是在/usr/local/src文件夾下安裝 可能會(huì)編譯出錯(cuò)

nginx問(wèn)題解決記錄:
文件授權(quán):
cd /usr/local
sudo chmod -R 777 nginx
,
nginx.conf 權(quán)限不足問(wèn)題:user root owner;
訪問(wèn)不通時(shí),重新配置nginx和model,并重新加載配置文件sudo /usr/local/nginx/sbin/nginx -s reload

fastdfs啟動(dòng):
本機(jī):sudo /usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
服務(wù)器:
sudo /usr/bin/restart.sh /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
本機(jī):sudo /usr/local/bin/restart.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
服務(wù)器:
sudo /usr/bin/restart.sh /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
nginx服務(wù):
sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx -s reload
監(jiān)控:
/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf
服務(wù)器:/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

防盜鏈
/etc/fdfs/http.conf


# HTTP default content type
http.default_content_type = application/octet-stream

# MIME types mapping filename
# MIME types file format: MIME_type  extensions
# such as:  image/jpeg  jpeg jpg jpe
# you can use apache's MIME file: mime.types
http.mime_types_filename = mime.types

# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token = true

# token TTL (time to live), seconds
# default value is 600
http.anti_steal.token_ttl = 900

# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
http.anti_steal.secret_key = 12345678

# return the content of the file when check token fail
# default value is empty (no file sepecified)
http.anti_steal.token_check_fail = /Users/yangxia/Documents/a_java_all/dfs/404.jpg

# if support multi regions for HTTP Range
# default value is true
http.multi_range.enabed = true

nginx配置圖片依賴(lài)

yum install -y gd-devel
./configure --prefix=/usr/local/nginx --with-http_image_filter_module --add-module=/usr/local/src/fastdfs-nginx-module/src/
make
make install

配置nginx訪問(wèn)

vim /usr/local/nginx/conf/nginx.conf

    location ~ group1/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) {           #這段往下為生成縮略圖的配置
        ngx_fastdfs_module;
        set $w $2;
        set $h $3;           

        if ($w != "0") {
            rewrite group1/(.+)_(\d+)x(\d+)\.(jpg|gif|png|JPG|jpeg)$ group1/$1.$4 break;
        }

        if ($h != "0") {
            rewrite group1/(.+)_(\d+)x(\d+)\.(jpg|gif|png|JPG|jpeg)$ group1/$1.$4 break;
        }

        image_filter resize $w $h;
          
        image_filter_buffer 2M;

        try_files group1/$1.$4 $1.jpg;
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容