FastDFS單機版安裝教程

安裝清單如下:

一、安裝FastDFS

1. 安裝libfastcommon

先解壓安裝包到目錄

# unzip libfastcommon-1.0.36.zip 

安裝編譯工具及環境(后面Nginx也會用到這些依賴環境)

# yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-deve
# yum -y install pcre-devel openssl openssl-devel
# yum -y install zlib zlib-deve

編譯libfastcommon軟件并安裝

# ./make.sh && ./make.sh install

為libcommon 創建軟鏈接到/usr/local/lib目錄下

# 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

2. 安裝FastDFS

解壓安裝包

# tar -xvf FastDFS_v5.01.tar.gz

編譯并安裝

# cd FastDFS
# ./make.sh && ./make.sh install

安裝成功后,FastDFS會安裝在/etc/fdfs目錄下:

[root@localhost FastDFS]# ll /etc/fdfs/
total 56
-rw-r--r--. 1 root root  1461 Aug 13 06:39 client.conf
-rw-r--r--. 1 root root   858 Aug 13 06:39 http.conf
-rw-r--r--. 1 root root 31172 Aug 13 06:39 mime.types
-rw-r--r--. 1 root root  7535 Aug 13 06:39 storage.conf
-rw-r--r--. 1 root root  6990 Aug 13 06:39 tracker.conf

FastDFS安裝結束

二、安裝Tracker

1. 創建tracker工作目錄

此目錄用于保存tracker 的data和log

# mkdir -p /data/fastdfs_tracker

2.配置tracker

配置 /etc/fdfs目錄下tracker.conf

主要實現以下4個配置內容:

disabled=false 
port=22122 #默認端口號 
base_path=/data/fastdfs_tracker #我剛剛創建的目錄 
http.server_port=8080 #默認端口是8080
bind_addr=0.0.0.0 #監聽地址

完整tracker.conf 文件信息如下:

disabled=false
bind_addr=0.0.0.0
port=22122
connect_timeout=30
network_timeout=60
base_path=/opt/fastdfs_tracker
max_connections=512
accept_threads=1
work_threads=4
min_buff_size=8KB
max_buff_size=128KB
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=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html

3. 將Tracker加入開機啟動項

# cp /usr/fastdfs/FastDFS/init.d/fdfs_trackerd /etc/init.d/
# chkconfig --add fdfs_trackerd
# chkconfig fdfs_trackerd on

啟動Tracker Server

# service fdfs_trackerd start

4. 查看一下tracker的端口監聽情況

# netstat -unltp|grep fdfs

三、安裝Storage

1. 配置storage工作目錄

由于storage還需要一個目錄用來存儲數據,因此多建了兩個目錄fastdfs_storage_data,fastdfs_storage

# mkdir -p /data/fastdfs_storage
# mkdir -p /data/fastdfs_storage_data

2. 配置storage文件

修改 /etc/fdfs 目錄下 storage.conf 文件

修改要點如下:

disabled=false
group_name=group1 #組名,根據實際情況修改 
port=23000 #設置storage的端口號,同一個組的storage端口號必須一致 
base_path=/data/fastdfs_storage #設置storage數據文件和日志目錄 
store_path_count=1 #存儲路徑個數,需要和store_path個數匹配 
store_path0=/data/fastdfs_storage_data #實際文件存儲路徑 
tracker_server=192.168.78.132:22122 #我CentOS7的ip地址 
file_distribute_path_mode=1 # 存儲方式 0:輪詢 1:Hash
http.server_port=8888 #設置 http 端口號

完整信息如下:

disabled=false
group_name=group1
bind_addr=0.0.0.0
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/opt/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=1
store_path0=/opt/fastdfs_storage_data
subdir_count_per_path=256
tracker_server=192.168.78.132: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=8888

3. 將Storage加入開機啟動項

# cp /usr/fastdfs/FastDFS/init.d/fdfs_storaged /etc/init.d/
# chkconfig --add fdfs_storaged
# chkconfig fdfs_storaged on

啟動Storage Server(默認產生255*255個目錄)

# service fdfs_storaged start

4. 查看一下Storage的端口監聽情況

# netstat -unltp | grep fdfs

5. 校驗整合

到這里,fastdfs的東西都已安裝完成,最后我們還要確定一下,storage是否注冊到了tracker中去。

查看命令:

# /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf

成功后可以看到:

ip_addr =?192.168.78.132 ACTIVE

四、測試

1. 配置客戶端

修改 /etc/fdfs/目錄下的client.conf 文件

修改要點為:

base_path=/data/fastdfs_tracker #tracker服務器文件路徑 
tracker_server=192.168.78.132:22122 #tracker服務器IP地址和端口號 
http.tracker_server_port=8080 # tracker 服務器的 http端口號,必須和tracker的設置對應起來

完整client.conf 文件信息如下:

connect_timeout=30 
network_timeout=60 
base_path=/data/fastdfs_tracker 
tracker_server=192.168.78.132: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=8080

2. 模擬上傳

從個人用戶目錄上傳一個圖片,進行測試

# /usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf /df.png
group1/M00/73/38/wKhOhFt0uRqAIWxDAAAQKuWUya0709.png

組名:group1

磁盤:M00

目錄:73/38

文件名稱:wKhOhFt0uRqAIWxDAAAQKuWUya0709.jpg

定位上傳的文件位置如下:

[root@localhost FastDFS]# ll /data/fastdfs_storage_data/data/73/38
total 8
-rw-r--r--. 1 root root 4138 Aug 15 16:36 wKhOhFt0uRqAIWxDAAAQKuWUya0709.png

實際文件存儲路徑下有創建好的多級目錄。data下有256個1級目錄,每級目錄下又有256個2級子目錄,總共65536個文件,新寫的文件會以hash的方式被路由到其中某個子目錄下,然后將文件數據直接作為一個本地文件存儲到該目錄中。

如果要訪問剛上傳的圖片,我們得需要結合nginx來實現

五、安裝Nginx并實現配置

1. 安裝Nginx依賴環境

第一步已經安裝完成。

2. 安裝nginx并添加fastdfs-nginx-module

解壓nginx和fastdfs-nginx-module

# tar -xvf nginx-1.14.0.tar.gz 
# tar -xvf fastdfs-nginx-module_v1.16.tar.gz

解壓后進入nginx目錄編譯安裝nginx,并添加fastdfs-nginx-module

# ./configure --prefix=/usr/local/nginx --add-module=/usr/fastdfs/fastdfs-nginx-module/src #解壓后fastdfs-nginx-module所在的位置

之后進行編譯和安裝

# make && make isntall

安裝成功后,nginx會安裝在/usr/local/nginx,安裝后查看

[root@localhost nginx-1.14.0]# ll /usr/local/nginx/
total 16
drwxr-xr-x. 2 root root 4096 Aug 15 16:57 conf
drwxr-xr-x. 2 root root 4096 Aug 15 16:57 html
drwxr-xr-x. 2 root root 4096 Aug 15 16:57 logs
drwxr-xr-x. 2 root root 4096 Aug 15 16:57 sbin

3. 配置Storage Nginx

修改Nginx 目錄下 conf 的配置文件nginx.conf,新增location信息,具體如下:

server {listen       9991;server_name  localhost;location / {root   html;index  index.html index.htm;}location ~/group1/M00 {root /data/fastdfs_storage_data;ngx_fastdfs_module;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}

需要把fastdfs-nginx-module安裝目錄中src目錄下的mod_fastdfs.conf也拷貝到/etc/fdfs目錄下:

# cp /usr/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

對剛剛拷貝的mod_fastdfs.conf文件進行修改:

base_path=/data/fastdfs_storage #保存日志目錄 
tracker_server=192.168.78.132:22122 #tracker服務器的IP地址以及端口號 
storage_server_port=23000 #storage服務器的端口號 
url_have_group_name = true #文件 url 中是否有 group 名 
store_path0=/data/fastdfs_storage_data #存儲路徑 
group_count = 1 #設置組的個數

在文件的最后,設置group

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs_storage_data

創建M00至storage存儲目錄的符號連接:

ln -s /data/fastdfs_storage_data/data/ /data/fastdfs_storage_data/data/M00

啟動Nginx:

# /usr/local/nginx/sbin/nginx

訪問Nginx是否啟動

[root@localhost fdfs]# curl localhost:9991
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

4. 配置Tracker Nginx

在nginx.conf 文件添加一個虛擬機

upstream fdfs_group1{server 127.0.0.1:9991;
}
server {listen 80;server_name localhost;location /group1/M00 {proxy_pass http://fdfs_group1;
    }error_page 500 502 503 504 /50x.htmllocation = /50x.html {root html;}
}

完整nginx.conf配置文件如下:

worker_processes  1;events {worker_connections  1024;
}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  65;#gzip  on;server {listen       9991;server_name  localhost;location / {root   html;index  index.html index.htm;}location ~/group1/M00 {root /data/fastdfs_storage_data;ngx_fastdfs_module;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}upstream fdfs_group1{server 127.0.0.1:9991;}server {listen 80;server_name localhost;location /group1/M00 {proxy_pass http://fdfs_group1;
        }error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
}

將Nginx重新啟動

# /usr/local/nginx/sbin/nginx -s reload

訪問Nginx是否已經啟動

[root@localhost conf]# curl localhost:9991
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

5. HTTP訪問圖片資源

http://192.168.78.132/group1/M00/AD/73/wKhOhFt0xNmAN7XbAAAQKuWUya0565.png

轉載于:https://www.cnblogs.com/yifanSJ/p/9467766.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/397226.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/397226.shtml
英文地址,請注明出處:http://en.pswp.cn/news/397226.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【原創】Chrome最新版(53-55)再次爆出BUG!

2019獨角獸企業重金招聘Python工程師標準>>> 前言 今年十月份&#xff0c;我曾發布一篇文章《Chrome53 最新版驚現無厘頭卡死 BUG&#xff01;》&#xff0c;不過那個BUG在最新的 Chrome 54 中已經修正。 而今天即將發布的Chrome弱智BUG&#xff1a; 僅 Chrome 53 -…

ThinkPHP 發送post請求

function post($url, $paramarray()){ if(!is_array($param)){ throw new Exception("參數必須為array"); } $httph curl_init($url); curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($httph,CURLOP…

vue 打包路由報錯_Vue下路由History模式打包后頁面空白的解決方法

vue的路由在默認的hash模式下,默認打包一般不會有什么問題,不過hash模式由于url會帶有一個#,不美觀,而且在微信分享,授權登錄等都會有一些坑.所以history模式也會有一些應用場景.新手往往會碰到history模式打包后頁面一片空白的情況,而且沒有資源加載錯誤的報錯信息.這個其實仔…

leetcode-回文鏈表

請判斷一個鏈表是否為回文鏈表。 示例 1: 輸入: 1->2 輸出: false 示例 2: 輸入: 1->2->2->1 輸出: true進階&#xff1a;你能否用 O(n) 時間復雜度和 O(1) 空間復雜度解決此題&#xff1f; 思路&#xff1a;先遍歷鏈表&#xff0c;獲得長度。 把前半部分的鏈表逆置…

進程kswapd0與events/0消耗大量CPU的問題

http://www.nowamagic.net/librarys/veda/detail/2539 今天下午網站宕了兩次機&#xff0c;發工單給阿里云&#xff0c;發現原因是服務器的CPU 100%了。 重啟服務器后&#xff0c;使用 top 命令看看是哪些進程消耗那么大的 CPU 使用。盯了有好十幾分鐘&#xff0c;主要消耗 CPU…

索引器

namespace _03{ class Program { //請編寫一個類&#xff1a;ItcastClass,該類中有一個私有字段_names,數據類型為&#xff1a;字符串數組&#xff0c;長度為5&#xff0c;并且有5個默認的姓名。 //要求&#xff1a;為ItcastClass類編寫一個索引器&#xff0c;要求該索引器能夠…

跑三小時的monkey測試該怎么算_淺談App測試(下)~帶音頻

文 | Vicky采編&#xff5c;Emily淺談App測試(上)&#xff5e;帶音頻一、功能測試?二、性能測試(1)耗電量影響因素&#xff1a;定位、傳感器、藍牙&#xff0c;其中CPU、持續定位是兩個平臺造成耗電的主要因素。(2)流量也就是常說的耗流量&#xff0c;影響因素有重復請求&…

Flask基礎(03)--創建第一個Flask程序

# 導入Flask from flask import Flask# 創建Flask的應用程序 # 參數__name__指的是Flask所對應的模塊&#xff0c;其決定靜態文件從哪個地方開始尋找 app Flask(__name__,static_url_path/static, # 靜態文件的訪問路徑&#xff0c;默認為/staticstatic_folderstatic, # 靜態…

2016-2017-2 《Java程序設計》課程學生博客和代碼托管鏈接

2016-2017-2 《Java程序設計》課程學生博客和代碼托管鏈接 博客 1552 20155201 李卓雯20155202 張 旭20155203 杜可欣20155204 王 昊20155205 郝博雅20155206 趙 飛20155207 王雪純20155208 徐子涵20155209 林虹宇20155210 潘瀅昊20155211 解雪瑩20155212 江振思20155213 陸忠民…

C++快速排序

快速排序作為排序家族里面最為快捷的方式&#xff0c;值得思考。我們將一個數組中的某一個數定為基點&#xff0c;然后通過快速排序按照需求&#xff08;假設升序&#xff09;&#xff0c;將比基點小的數丟在基點左邊&#xff0c;把比基點大的數丟在基點右邊這樣來將基點數的正…

回顧一年的工作歷程_【設備管理公司】召開20202021年度總結計劃表彰暨工作述職會議...

點擊上方藍字關注我們2020年即將過去&#xff0c;為了總結2020年各項工作開展情況&#xff0c;同時做好2021年工作計劃與部署&#xff0c;2020年12月30日-31日&#xff0c;設備管理公司組織召開了2020-2021年度總結計劃表彰暨工作述職會議。公司領導、各部門經理、部門主管、車…

注冊驗證的時候一直出現的報錯問題,終于解決了

今天再注冊驗證表單的時候一直報錯&#xff0c;但是什么都沒有改&#xff0c;就報錯了&#xff0c;后面才知道原來是和我上次上傳圖片的時候&#xff0c;導入的2個js的順序有關系的&#xff0c; 45行和41行互相換一下位置就好了 轉載于:https://www.cnblogs.com/likeji/p/61433…

重排序

一、重排序。 1、為什么需要重排序&#xff1f; 現在的CPU一般采用流水線來執行指令。一個指令的執行被分成&#xff1a;取指、譯碼、訪存、執行、寫回、等若干個階段。然后&#xff0c;多條指令可以同時存在于流水線中&#xff0c;同時被執行。 指令流水線并不是串行的&#x…

tableau三軸該怎么做_如何用tableau繪制城市地鐵線路圖?

在用tableau繪制地鐵線路圖之前&#xff0c;當然是要獲取相關的數據啦我們以鄭州目前已開通的地鐵為例&#xff0c;分別是1、2、5號線經度、維度可在 網頁上自行搜索哦&#xff08;以谷歌地圖為準&#xff09;有了這些下面我們就要開始啦將Excel中你所需要的數據直接導入到tabl…

JS七種加密解密方法

HTML或JS加密解密 本文一共介紹了七種方法&#xff1a;   一&#xff1a;最簡單的加密解密   二&#xff1a;轉義字符"\"的妙用   三&#xff1a;使用Microsoft出品的腳本編碼器Script Encoder來進行編碼 &#xff08;自創簡單解碼&#xff09;  …

提高solr的搜索速度

之前是使用12臺機分布式搜索&#xff0c;1臺為主機做索引并分發給子機&#xff0c;8臺做大索引搜索服務&#xff0c;3 臺做小索引搜索服務&#xff0c;配置基本是內存在4-8G&#xff0c;cpu:2-8core的服務器&#xff0c;索引的大小為8G。搜索的響應時間 是150ms左右。&#xff…

哲學到編程:思想的實例化

萬古長江水&#xff0c;千年儒釋道。歷史的長流中&#xff0c;蕓蕓眾生&#xff0c;參差不齊&#xff0c;但總是能夠總結出一個“生旦凈末丑”來。儒、釋、道&#xff0c;五千年的中華文化&#xff0c;卻總是圍繞著這三種主流思想交相演繹。千年間&#xff0c;豪士俊杰&#xf…

python 字符串交集_Python序列--集合(set)

集合集合用于保存不重復元素。- 集合和列表非常相似- 不同點&#xff1a;1.集合中只能存儲不可變對象2.集合中存儲的對象是無序(不是按照元素的插入順序保存)3.集合中不能出現重復的元素集合的所有元素都放在一對”{ }” 中&#xff0c;兩個相鄰的元素之間用”,”分隔。集合最好…

mysql binlog日志查看及解碼

mysql bin log日志導出 mysqlbinlog mysql-bin.000005 > /home/17bin.log 需要添加參數&#xff08;--base64-outputdecode-rows -v&#xff09;對輸出結果解碼 mysqlbinlog --base64-outputdecode-rows -v mysql-bin.000005 > /home/17bin.log轉載于:https://www.cnbl…

【Python開發】Python的GUI用法總結

引用模塊&#xff08;tkinter&#xff09;&#xff1a; 1 from tkinter import * 主窗口設置&#xff1a; 1 # 主窗口 2 tk Tk() # 主窗口實例化 3 tk.title("文本處理工具") # 主窗口標題 4 tk.geometry("700x4001001…