Fastdfs安裝配置
前提:2臺(tái)tracker(tracker1,tracker2)墩划,2臺(tái)storage(storag1嗡综,storage2)
Storage掛載兩塊硬盤
[if !supportLists]一极景、[endif]編輯/etc/hosts文件(四臺(tái)機(jī)器)戴陡,添加如下
# vi /etc/hosts
10.32.4.11?? tracker1
10.32.4.12?? tracker2
10.32.4.13?? storage1
10.32.4.14?? storage2
二、下載安裝 libfastcommon(四臺(tái)機(jī)器)
libfastcommon是從 FastDFS 和 FastDHT 中提取出來的公共 C 函數(shù)庫喜庞,基礎(chǔ)環(huán)境棋返,安裝即可 。
[if !supportLists]①??? [endif]?下載libfastcommon
# wgethttps://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
[if !supportLists]②??? [endif]?解壓
# tar -zxvfV1.0.7.tar.gz
# cdlibfastcommon-1.0.7
[if !supportLists]③??? [endif]?編譯晰房、安裝
# ./make.sh
# ./make.shinstall
④ libfastcommon.so 安裝到了/usr/lib64/libfastcommon.so殊者,但是FastDFS主程序設(shè)置的lib目錄是/usr/local/lib猖吴,所以需要?jiǎng)?chuàng)建軟鏈接海蔽。
# ln -s/usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s/usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
# ln -s/usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
# ln -s/usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
三党窜、下載安裝FastDFS(四臺(tái)機(jī)器)
[if !supportLists]①??? [endif]?下載FastDFS
# wgethttps://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
[if !supportLists]②??? [endif]?解壓
# tar -zxvfV5.05.tar.gz
# cdfastdfs-5.05
[if !supportLists]③??? [endif]?編譯寺擂、安裝
# ./make.sh
# ./make.shinstall
④ 默認(rèn)安裝方式安裝后的相應(yīng)文件與目錄
A怔软、服務(wù)腳本:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_trackerd
B挡逼、配置文件(這三個(gè)是作者給的樣例配置文件):
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sample
C家坎、命令工具在 /usr/bin/目錄下:
fdfs_appender_test
fdfs_appender_test1
fdfs_append_file
fdfs_crc32
fdfs_delete_file
fdfs_download_file
fdfs_file_info
fdfs_monitor
fdfs_storaged
fdfs_test
fdfs_test1
fdfs_trackerd
fdfs_upload_appender
fdfs_upload_file
stop.sh
restart.sh
⑤ FastDFS 服務(wù)腳本設(shè)置的bin 目錄是 /usr/local/bin虱疏, 但實(shí)際命令安裝在 /usr/bin/ 下。
兩種方式:
一是修改FastDFS 服務(wù)腳本中相應(yīng)的命令路徑装蓬,也就是把 /etc/init.d/fdfs_storaged 和/etc/init.d/fdfs_tracker 兩個(gè)腳本中的 /usr/local/bin 修改成 /usr/bin牍帚。
?# vim fdfs_trackerd
使用查找替換命令進(jìn)統(tǒng)一修改:%s+/usr/local/bin+/usr/bin
# vim fdfs_storaged
使用查找替換命令進(jìn)統(tǒng)一修改:%s+/usr/local/bin+/usr/bin
[if !vml]
[endif]
二是建立 /usr/bin 到/usr/local/bin 的軟鏈接暗赶,我是用這種方式(推薦這種方式)忆首。
# ln -s /usr/bin/fdfs_trackerd??/usr/local/bin
# ln -s /usr/bin/fdfs_storaged??/usr/local/bin
# ln -s /usr/bin/stop.sh????????/usr/local/bin
# ln -s /usr/bin/restart.sh?????/usr/local/bin
四糙及、配置FastDFS跟蹤器(Tracker)(兩個(gè)tracker執(zhí)行)
配置文件詳細(xì)說明參考:FastDFS配置文件詳解
① 進(jìn)入 /etc/fdfs浸锨,復(fù)制 FastDFS 跟蹤器樣例配置文件 tracker.conf.sample迟郎,并重命名為 tracker.conf宪肖。
??????? # cd/etc/fdfs
??????? # cptracker.conf.sample tracker.conf
??????? # vimtracker.conf
② 編輯tracker.conf 控乾,標(biāo)紅的需要修改下蜕衡,其它的默認(rèn)即可慨仿。
# 配置文件是否不生效镰吆,false 為生效
disabled=false
[if !supportLineBreakNewLine]
[endif]
# 提供服務(wù)的端口
port=22122
[if !supportLineBreakNewLine]
[endif]
# Tracker 數(shù)據(jù)和日志目錄地址(根目錄必須存在,子目錄會(huì)自動(dòng)創(chuàng)建)
base_path=/ljzsg/fastdfs/tracker
[if !supportLineBreakNewLine]
[endif]
# HTTP 服務(wù)端口
http.server_port=80
③ 創(chuàng)建tracker基礎(chǔ)數(shù)據(jù)目錄,即base_path對(duì)應(yīng)的目錄
# mkdir -p /ljzsg/fastdfs/tracker
④ 防火墻中打開跟蹤端口(默認(rèn)的22122)
# vim /etc/sysconfig/iptables
[if !supportLineBreakNewLine]
[endif]
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122-j ACCEPT
[if !supportLineBreakNewLine]
[endif]
重啟防火墻:
# service iptables restart
[endif]
⑤ 啟動(dòng)Tracker
初次成功啟動(dòng),會(huì)在 /ljzsg/fdfsdfs/tracker/ (配置的base_path)下創(chuàng)建 data钮科、logs 兩個(gè)目錄绵脯。
可以用這種方式啟動(dòng)
# /etc/init.d/fdfs_trackerd start
也可以用這種方式啟動(dòng)蛆挫,前提是上面創(chuàng)建了軟鏈接悴侵,后面都用這種方式
# service fdfs_trackerd start
查看 FastDFS Tracker 是否已成功啟動(dòng) 可免,22122端口正在被監(jiān)聽捉撮,則算是Tracker服務(wù)安裝成功巾遭。
# netstat -unltp|grep fdfs
[if !vml]
[endif]
關(guān)閉Tracker命令:
# service fdfs_trackerd stop
⑥ 設(shè)置Tracker開機(jī)啟動(dòng)
# chkconfig fdfs_trackerd on
或者:
# vim /etc/rc.d/rc.local
加入配置:
/etc/init.d/fdfs_trackerd start
service fdfs_trackerd start
⑦?tracker server 目錄及文件結(jié)構(gòu)
Tracker服務(wù)啟動(dòng)成功后灼舍,會(huì)在base_path下創(chuàng)建data片仿、logs兩個(gè)目錄砂豌。目錄結(jié)構(gòu)如下:
${base_path}
? |__data
? |?? |__storage_groups.dat:存儲(chǔ)分組信息
? |?? |__storage_servers.dat:存儲(chǔ)服務(wù)器列表
? |__logs
? |?? |__trackerd.log: tracker server 日志文件
五、配置 FastDFS 存儲(chǔ)(Storage)
Storage1筐摘,storage2操作:
① 進(jìn)入 /etc/fdfs 目錄咖熟,復(fù)制 FastDFS 存儲(chǔ)器樣例配置文件 storage.conf.sample馍管,并重命名為storage.conf
# cd /etc/fdfs
# cp storage.conf.sample storage.conf
# vim storage.conf
② 編輯storage.conf
標(biāo)紅的需要修改,其它的默認(rèn)即可罗捎。
[endif]
# 配置文件是否不生效桨菜,false 為生效
disabled=false
# 指定此 storage
server 所在 組(卷)
group_name=group1
# storage server 服務(wù)端口
port=23000
# 心跳間隔時(shí)間雷激,單位為秒 (這里是指主動(dòng)向 tracker server 發(fā)送心跳)
heart_beat_interval=30
# Storage 數(shù)據(jù)和日志目錄地址(根目錄必須存在承桥,子目錄會(huì)自動(dòng)生成)
base_path=/ljzsg/fastdfs/storage
# 存放文件時(shí) storage
server 支持多個(gè)路徑凶异。這里配置存放文件的基路徑數(shù)目剩彬,通常只配一個(gè)目錄喉恋。
store_path_count=1
# 逐一配置store_path_count 個(gè)路徑,索引號(hào)基于 0氓鄙。
# 如果不配置store_path0抖拦,那它就和 base_path 對(duì)應(yīng)的路徑一樣态罪。
store_path0=/ljzsg/fastdfs/file
# FastDFS 存儲(chǔ)文件時(shí),采用了兩級(jí)目錄。這里配置存放文件的目錄個(gè)數(shù)驯遇。
# 如果本參數(shù)只為 N(如: 256)叉庐,那么 storage server 在初次運(yùn)行時(shí)玩郊,會(huì)在 store_path 下自動(dòng)創(chuàng)建 N * N 個(gè)存放文件的子目錄译红。
subdir_count_per_path=256
# tracker_server 的列表 侦厚,會(huì)主動(dòng)連接tracker_server
# 有多個(gè) tracker
server 時(shí)囱修,每個(gè) tracker server 寫一行
tracker_server=tracker1:22122
tracker_server=tracker2:22122
# 允許系統(tǒng)同步的時(shí)間段 (默認(rèn)是全天) 岛心。一般用于避免高峰同步產(chǎn)生一些問題而設(shè)定鹉梨。
sync_start_time=00:00
sync_end_time=23:59
# 訪問端口
http.server_port=80
[endif]
③ 創(chuàng)建Storage基礎(chǔ)數(shù)據(jù)目錄晌坤,對(duì)應(yīng)base_path目錄
# mkdir -p /ljzsg/fastdfs/storage
# 這是配置的store_path0路徑
# mkdir -p /ljzsg/fastdfs/file
④?防火墻中打開存儲(chǔ)器端口(默認(rèn)的 23000)
[endif]
# vim /etc/sysconfig/iptables
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000-j ACCEPT
重啟防火墻:
# service iptables restart
[endif]
[if !vml]
[endif]
⑤ 啟動(dòng)Storage
啟動(dòng)Storage前確保Tracker是啟動(dòng)的。初次啟動(dòng)成功商乎,會(huì)在 /ljzsg/fastdfs/storage 目錄下創(chuàng)建 data鹉戚、 logs 兩個(gè)目錄抹凳。
可以用這種方式啟動(dòng)
# /etc/init.d/fdfs_storaged start
也可以用這種方式,后面都用這種
# service fdfs_storaged start
查看 Storage 是否成功啟動(dòng)幸冻,23000 端口正在被監(jiān)聽洽损,就算 Storage 啟動(dòng)成功强缘。
# netstat -unltp|grep fdfs
[if !vml]
[endif]
關(guān)閉Storage命令:
# service fdfs_storaged stop
查看Storage和Tracker是否在通信:
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[if !vml]
[endif]
⑥ 設(shè)置 Storage 開機(jī)啟動(dòng)
# chkconfig fdfs_storaged on
或者:
# vim /etc/rc.d/rc.local
加入配置:
/etc/init.d/fdfs_storaged start
⑦ Storage 目錄
同Tracker,Storage 啟動(dòng)成功后商虐,在base_path下創(chuàng)建了data秘车、logs目錄,記錄著 Storage Server 的信息眯亦。
在store_path0 目錄下妻率,創(chuàng)建了N*N個(gè)子目錄:
[if !vml]
[endif]
六、文件上傳測(cè)試
① 修改 Tracker?服務(wù)器中的客戶端配置文件?(隨便一個(gè)tracker)
# cd /etc/fdfs
# cp client.conf.sample client.conf
# vim client.conf
修改如下配置即可孤里,其它默認(rèn)捌袜。
# Client 的數(shù)據(jù)和日志目錄
base_path=/ljzsg/fastdfs/client
# Tracker端口
tracker_server=tracker1:22122
② 上傳測(cè)試
?在linux內(nèi)部執(zhí)行如下命令上傳 namei.jpeg 圖片
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf namei.jpeg
上傳成功后返回文件ID號(hào):group1/M00/00/00/wKgz6lnduTeAMdrcAAEoRmXZPp870.jpeg
[if !vml]
[endif]
返回的文件ID由group、存儲(chǔ)目錄博其、兩級(jí)子目錄、fileid峰髓、文件后綴名(由客戶端指定携兵,主要用于區(qū)分文件類型)拼接而成。
[if !vml]
[endif]七并级、安裝Nginx
上面將文件上傳成功了,但我們無法下載愈涩。因此安裝Nginx作為服務(wù)器以支持Http方式訪問文件钠署。同時(shí)谐鼎,后面安裝FastDFS的Nginx模塊也需要Nginx環(huán)境。
Nginx只需要安裝到StorageServer所在的服務(wù)器即可草戈,用于訪問文件唐片。我這里由于是單機(jī)茧球,TrackerServer和StorageServer在一臺(tái)服務(wù)器上。
①?gcc 安裝
# yum install gcc-c++
②?PCRE pcre-devel 安裝
# yum install -y pcre pcre-devel
③?zlib 安裝
# yum install -y zlib zlib-devel
④?OpenSSL 安裝
# yum install -y openssl openssl-devel
① 下載nginx
# wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
② 解壓
# tar -zxvf nginx-1.12.1.tar.gz
# cd nginx-1.12.1
③ 使用默認(rèn)配置
# ./configure
④ 編譯肪凛、安裝
# make
# make install
⑤ 啟動(dòng)nginx
[endif]
# cd /usr/local/nginx/sbin/
# ./nginx
其它命令
# ./nginx -s stop
# ./nginx -s quit
# ./nginx -s reload
[endif]
⑥ 設(shè)置開機(jī)啟動(dòng)
[endif]
# vim /etc/rc.local
添加一行:
/usr/local/nginx/sbin/nginx
#
設(shè)置執(zhí)行權(quán)限
#chmod 755 rc.local
[endif]
⑦ 查看nginx的版本及模塊
/usr/local/nginx/sbin/nginx -V
[if !vml]
[endif]
⑧?防火墻中打開Nginx端口(默認(rèn)的 80)?
添加后就能在本機(jī)使用80端口訪問了。
[endif]
# vim /etc/sysconfig/iptables
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重啟防火墻:
# service iptables restart
[endif]
[if !vml]
[endif]
簡(jiǎn)單的測(cè)試訪問文件
① 修改nginx.conf
[endif]
# vim /usr/local/nginx/conf/nginx.conf
添加如下行拱烁,將 /group1/M00 映射到/ljzsg/fastdfs/file/data
location /group1/M00 {
??? alias /ljzsg/fastdfs/file/data;
}
#
重啟nginx
# /usr/local/nginx/sbin/nginx -s reload
[endif]
[if !vml]
[endif]
② 在瀏覽器訪問之前上傳的圖片、成功擅笔。
http://10.32.4.14/group1/M00/00/00/CiAEDVs7DC-AAI2YAAAnompQzds934.png
http://10.32.4.13/group1/M00/00/00/CiAEDVs7DC-AAI2YAAAnompQzds934.png
八、FastDFS 配置 Nginx 模塊
1弯淘、安裝配置Nginx模塊(兩臺(tái)storage操作)
① fastdfs-nginx-module 模塊說明
FastDFS 通過 Tracker 服務(wù)器庐橙,將文件放在 Storage 服務(wù)器存儲(chǔ)假勿, 但是同組存儲(chǔ)服務(wù)器之間需要進(jìn)行文件復(fù)制, 有同步延遲的問題态鳖。
假設(shè) Tracker 服務(wù)器將文件上傳到了 192.168.51.128废登,上傳成功后文件 ID已經(jīng)返回給客戶端。
此時(shí) FastDFS 存儲(chǔ)集群機(jī)制會(huì)將這個(gè)文件同步到同組存儲(chǔ)192.168.51.129郁惜,在文件還沒有復(fù)制完成的情況下甲锡,客戶端如果用這個(gè)文件 ID 在 192.168.51.129 上取文件,就會(huì)出現(xiàn)文件無法訪問的錯(cuò)誤兆蕉。
而 fastdfs-nginx-module 可以重定向文件鏈接到源服務(wù)器取文件,避免客戶端由于復(fù)制延遲導(dǎo)致的文件無法訪問錯(cuò)誤缤沦。
② 下載?fastdfs-nginx-module虎韵、解壓
[endif]
# 這里為啥這么長(zhǎng)一串呢,因?yàn)樽钚掳娴膍aster與當(dāng)前nginx有些版本問題缸废。
# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# 解壓
# unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# 重命名
# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1? fastdfs-nginx-module-master
[endif]
③ 配置Nginx
在nginx中添加模塊
[endif]
# 先停掉nginx服務(wù)
# /usr/local/nginx/sbin/nginx -s stop
進(jìn)入解壓包目錄
# cd /softpackages/nginx-1.12.1/
# 添加模塊
# ./configure --add-module=../fastdfs-nginx-module-master/src
重新編譯包蓝、安裝
# make && make install
[endif]
?④ 查看Nginx的模塊
# /usr/local/nginx/sbin/nginx -V
有下面這個(gè)就說明添加模塊成功
[if !vml]
[endif]
⑤ 復(fù)制 fastdfs-nginx-module 源碼中的配置文件到/etc/fdfs 目錄, 并修改
# cd /softpackages/fastdfs-nginx-module-master/src
# cp mod_fastdfs.conf /etc/fdfs/
修改如下配置企量,其它默認(rèn)
[endif]
# 連接超時(shí)時(shí)間
connect_timeout=10
# Tracker Server
tracker_server=file.ljzsg.com:22122
# StorageServer
默認(rèn)端口
storage_server_port=23000
# 如果文件ID的uri中包含/group**测萎,則要設(shè)置為true
url_have_group_name = true
# Storage 配置的store_path0路徑,必須和storage.conf中的一致
store_path0=/ljzsg/fastdfs/file
[endif]
⑥?復(fù)制 FastDFS 的部分配置文件到/etc/fdfs 目錄
# cd /softpackages/fastdfs-5.05/conf/
# cp anti-steal.jpg http.conf mime.types /etc/fdfs/
?⑦ 配置nginx届巩,修改nginx.conf
# vim /usr/local/nginx/conf/nginx.conf
修改配置硅瞧,其它的默認(rèn)
在80端口下添加fastdfs-nginx模塊
location ~/group([0-9])/M00 {
??? ngx_fastdfs_module;
}
[if !vml]
[endif]
注意:
listen 80?端口值是要與?/etc/fdfs/storage.conf 中的http.server_port=80 (前面改成80了)相對(duì)應(yīng)。如果改成其它端口恕汇,則需要統(tǒng)一腕唧,同時(shí)在防火墻中打開該端口。
location 的配置瘾英,如果有多個(gè)group則配置location ~/group([0-9])/M00 枣接,沒有則不用配group。
⑧?在/ljzsg/fastdfs/file文件存儲(chǔ)目錄下創(chuàng)建軟連接缺谴,將其鏈接到實(shí)際存放數(shù)據(jù)的目錄但惶,這一步可以省略。
# ln -s /ljzsg/fastdfs/file/data/ /ljzsg/fastdfs/file/data/M00
⑨ 啟動(dòng)nginx
# /usr/local/nginx/sbin/nginx
打印處如下就算配置成功
[if !vml]
[endif]
⑩ 在地址欄訪問湿蛔。
能下載文件就算安裝成功榆骚。注意和第三點(diǎn)中直接使用nginx路由訪問不同的是,這里配置 fastdfs-nginx-module 模塊煌集,可以重定向文件鏈接到源服務(wù)器取文件妓肢。
http://file.ljzsg.com/group1/M00/00/00/wKgz6lnduTeAMdrcAAEoRmXZPp870.jpeg
最終部署結(jié)構(gòu)圖(盜的圖):可以按照下面的結(jié)構(gòu)搭建環(huán)境。
[if !vml]
[endif]
九苫纤、tracker反向代理配置(兩臺(tái)tracter都需要)
1.下載需要的軟件
ngx_cache_purge-2.3.tar.gz??nginx-1.13.12.tar.gz
2.安裝依賴
# yum install pcre
# yum install pcre-devel
# yum install zlib
# yum install zlib-devel
3.解壓nginx和ngx_cache_purge碉钠,并編譯安裝
# ./configure --add-module=../ngx_cache_purge-2.3
# make && make install
4. 進(jìn)入/usr/local/nginx/conf,編輯nginx.conf如下:
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
??? worker_connections 1024;
??? use epoll;
}
http {
??? include mime.types;
??? default_type application/octet-stream;
??? #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
??? # '$status $body_bytes_sent "$http_referer" '
??? # '"$http_user_agent" "$http_x_forwarded_for"';
??? #access_log logs/access.log main;
??? sendfile on;
??? tcp_nopush on;
??? #keepalive_timeout 0;
??? keepalive_timeout 65;
??? #gzip on;
??? #設(shè)置緩存
??? server_names_hash_bucket_size 128;
??? client_header_buffer_size 32k;
??? large_client_header_buffers 4 32k;
??? client_max_body_size 300m;
??? proxy_redirect off;
??? proxy_set_header Host $http_host;
??? proxy_set_header X-Real-IP $remote_addr;
??? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
??? proxy_connect_timeout 90;
??? proxy_send_timeout 90;
??? proxy_read_timeout 90;
??? proxy_buffer_size 16k;
??? proxy_buffers 4 64k;
??? proxy_busy_buffers_size 128k;
??? proxy_temp_file_write_size 128k;
??? #設(shè)置緩存存儲(chǔ)路徑纲缓、存儲(chǔ)方式、分配內(nèi)存大小喊废、磁盤最大空間祝高、緩存期限
??? proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2
??? keys_zone=http-cache:200m max_size=1g inactive=30d;
??? proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;
??? #設(shè)置 group1 的服務(wù)器
??? upstream fdfs_group1 {
??????? server 10.32.4.13 weight=1 max_fails=2 fail_timeout=30s;
??????? server 10.32.4.14 weight=1 max_fails=2 fail_timeout=30s;
??? } #
#??? 設(shè)置 group2 的服務(wù)器
#?? upstream fdfs_group2 {
#
#??????? server 10.32.1.220 weight=1 max_fails=2 fail_timeout=30s;
#??????? server 192.168.50.140:8888 weight=1 max_fails=2 fail_timeout=30s;
# }
??? server {
??????? listen 80;
??????? server_name localhost;
??????? #charset koi8-r;
??????? #access_log logs/host.access.log main;
??????? #設(shè)置 group 的負(fù)載均衡參數(shù)
??????? location /group1/M0 {
??????????? proxy_next_upstream http_502 http_504 error timeout invalid_header;
??????????? proxy_cache http-cache;
??????????? proxy_cache_valid 200 304 12h;
??????????? proxy_cache_key $uri$is_args$args;
??????????? proxy_pass http://fdfs_group1;
??????????? expires 30d;
??????? }
??? #??? location /group2/M0 {
???? #?????? proxy_next_upstream http_502 http_504 error timeout invalid_header;
????? #????? proxy_cache http-cache;
?????? #???? proxy_cache_valid 200 304 12h;
??????? #??? proxy_cache_key $uri$is_args$args;
???????? #?? proxy_pass http://fdfs_group2;
????????? #? expires 30d;
??????? #}
??????? #設(shè)置清除緩存的訪問權(quán)限
??????? location ~/purge(/.*) {
??????????? allow 127.0.0.1;
??????????? allow 192.168.1.0/24;
??????????? deny all;
??? ????????proxy_cache_purge http-cache $1$is_args$args;
??????? }
??????? #error_page 404 /404.html;
??????? # redirect server error pages to the static page /50x.html
??????? #
??????? error_page 500 502 503 504 /50x.html;
??????????? location = /50x.html {
??????????? root html;
??????? }
??? }
}
檢查配置是否正確
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
4、建立nginx緩存目錄
# mkdir -p /fastdfs/cache/nginx/proxy_cache
# mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
5.啟動(dòng)nginx
# /usr/local/nginx/sbin/nginx
6.測(cè)試
http://10.32.4.11/group1/M00/00/00/CiAEDVs7DC-AAI2YAAAnompQzds934.png
http://10.32.4.11/group1/M00/00/00/CiAEDVs7DC-AAI2YAAAnompQzds934.png
出來結(jié)果
到現(xiàn)在為止配置結(jié)束污筷,也可以在前端添加nginx做反向代理
十工闺、同一組里邊再加一塊盤(storage都要做)
為group1 添加第二塊盤
編輯/etc/fdfs/storage.conf
store_path_count=2
store_path1=/data
編輯/etc/fdfs/mod_fastdfs.conf
[group1]
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/ljzsg/fastdfs/file
store_path1=/data
編輯vi /usr/local/nginx/conf/nginx.conf
location ~/group([0-9])/M01 {
??? ngx_fastdfs_module;
}
改為:
location ~/group([0-9])/M0 {
??? ngx_fastdfs_module;
}
重啟電腦即可
重啟后查看
pid=9367
[root@storage1 conf]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2018-07-03 15:47:48] DEBUG - base_path=/ljzsg/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=2, server_index=0
tracker server is 10.32.4.11:22122
group count: 1
Group 1:
group name = group1
disk total space = 2038502 MB
disk free space = 2036924 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 80
store path count = 2
subdir count per path = 256
current write server index = 0
current trunk file id = 0
??????? Storage 1:
??????????????? id = 10.32.4.13
??????????????? ip_addr = 10.32.4.13 (storage1)? ACTIVE
??????????????? http domain =
????????????????version = 5.05
??????????????? join time = 2018-07-03 10:59:42
??????????????? up time = 2018-07-03 15:40:13
??????????????? total storage = 2038502 MB
??????????????? free storage = 2036924 MB
??????????? ????upload priority = 10
??????????????? store_path_count = 2
??????????????? subdir_count_per_path = 256
??????????????? storage_port = 23000
??????????????? storage_http_port = 80
??????????????? current_write_path = 0
??????????????? source storage id =
????????????????if_trunk_server = 0
??????????????? connection.alloc_count = 256
??????????????? connection.current_count = 1
??????????????? connection.max_count = 2
??????????????? total_upload_count = 24
??????????????? success_upload_count = 24
???? ???????????total_append_count = 0
??????????????? success_append_count = 0
??????????????? total_modify_count = 0
??????????????? success_modify_count = 0
??????????????? total_truncate_count = 0
測(cè)試:
在tracker添加一張圖片
# /usr/bin/fdfs_upload_file client.conf 6.png
group1/M00/00/00/CiAEDVs7KnSAAh7IAAAnompQzds035.png
# /usr/bin/fdfs_upload_file client.conf 6.png
group1/M01/00/00/CiAEDVs7KpeAVgusAAAnompQzds340.png
訪問:
http://10.32.4.11/group1/M01/00/00/CiAEDls7KUOABJsiAAAnompQzds393.png
http://10.32.4.12/group1/M01/00/00/CiAEDls7KUOABJsiAAAnompQzds393.png
http://10.32.4.11/group1/M01/00/00/CiAEDVs7KpeAVgusAAAnompQzds340.png
http://10.32.4.12/group1/M01/00/00/CiAEDVs7KpeAVgusAAAnompQzds340.png
正常打開成功
十一、配置文件:
(tracker配置文件)
Nginx
[root@tracker1 conf]# cat nginx.conf|grep -v '#' |tr-s '\n'
user root;?
worker_processes 1;?
events {?
??? worker_connections 1024;?
??? use epoll;?
}?
http {?
??? include mime.types;?
??? default_typeapplication/octet-stream;?
??? sendfile on;?
??? tcp_nopush on;?
??? keepalive_timeout 65;?
??? server_names_hash_bucket_size128;?
??? client_header_buffer_size32k;?
??? large_client_header_buffers 432k;?
??? client_max_body_size 300m;?
??? proxy_redirect off;?
??? proxy_set_header Host$http_host;?
??? proxy_set_header X-Real-IP$remote_addr;?
??? proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;?
??? proxy_connect_timeout 90;?
??? proxy_send_timeout 90;?
??? proxy_read_timeout 90;?
??? proxy_buffer_size 16k;?
??? proxy_buffers 4 64k;?
??? proxy_busy_buffers_size128k;?
??? proxy_temp_file_write_size128k;?
??? proxy_cache_path/fastdfs/cache/nginx/proxy_cache levels=1:2?
??? keys_zone=http-cache:200mmax_size=1g inactive=30d;?
??? proxy_temp_path/fastdfs/cache/nginx/proxy_cache/tmp;?
??? upstream fdfs_group1 {?
??????? server 10.32.4.13 weight=1max_fails=2 fail_timeout=30s;?
??????? server 10.32.4.14 weight=1max_fails=2 fail_timeout=30s;?
??? server {?
??????? listen 80;?
??????? server_name localhost;?
??????? location /group1/M0 {?
??????????? proxy_next_upstreamhttp_502 http_504 error timeout invalid_header;?
??????????? proxy_cachehttp-cache;?
??????????? proxy_cache_valid 200304 12h;?
????? ??????proxy_cache_key $uri$is_args$args;?
??????????? proxy_passhttp://fdfs_group1;?
??????????? expires 30d;?
??????? }?
??????? location ~/purge(/.*) {?
??????????? allow 127.0.0.1;?
??????????? allow192.168.1.0/24;?
??????????? deny all;?
??? ????????proxy_cache_purge http-cache$1$is_args$args;?
??????? }?
??????? error_page 500 502 503 504/50x.html;?
??????????? location = /50x.html{?
??????????? root html;?
??????? }?
??? }?
}
Tracker配置
[root@tracker1 fdfs]# cat tracker.conf|grep -v ^# |tr-s '\n'
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/ljzsg/fastdfs/tracker
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=80
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
[root@tracker1 fdfs]# cat client.conf|grep -v ^# |tr-s '\n'
connect_timeout=30
network_timeout=60
base_path=/ljzsg/fastdfs/client
tracker_server=tracker1:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80
Storage配置文件
# cat storage.conf |grep -v ^# |tr -s '\n'
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/ljzsg/fastdfs/storage
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=2
store_path0=/ljzsg/fastdfs/file
store_path1=/data
subdir_count_per_path=256
tracker_server=tracker1:22122
tracker_server=tracker2:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=80
# cat mod_fastdfs.conf |grep -v ^# |tr -s '\n'
connect_timeout=2
network_timeout=30
base_path=/tmp
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=tracker1:22122
tracker_server=tracker1:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/ljzsg/fastdfs/file
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 1
[group1]
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/ljzsg/fastdfs/file
store_path1=/data
?
nginx配置
[root@storage1 conf]# cat nginx.conf|grep -v '#' |tr-s '\n'
worker_processes? 1;
events {
??? worker_connections? 1024;
}
http {
??? include?????? mime.types;
???default_type?application/octet-stream;
??? sendfile??????? on;
??? keepalive_timeout? 65;
??? server {
??????? listen?????? 80;
??????? server_name? localhost;
??????? location / {
??????????? root?? html;
??????????? index? index.html index.htm;
???? ???}
location ~/group([0-9])/M0 {
??? ngx_fastdfs_module;
}
??????? error_page?? 500 502 503 504? /50x.html;
??????? location = /50x.html {
??????????? root?? html;
??????? }
??? }
}