安裝FastDFS(on Ubuntu18.04)(FastDFS+nginx+fastdfs-nginx-module(1))

環境及版本:

  • Ubuntu18.04
  • FastDFS V6.06

系統環境是 Centos7 請移步這裏:FastDFS+nginx+fastdfs-nginx-module服務器配置(on Centos7)

1.安裝依賴環境

1.1 更新apt

sudo apt update && sudo apt upgrade

1.2 安裝build-essential包

sudo apt-get install build-essential

該命令安裝一組新的包,包含gcc,g++,make.

1.3 安裝libtool

sudo apt install libtool

GNU libtool是通用庫支持腳本.它將共享庫的使用隱藏在一個一致的可移植的接口後面.

2.下載安裝FastDFS依賴庫libfastcommon

sudo apt install git
sudo git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon
./make.sh clean && ./make.sh && ./make.sh install

3.安裝FastDFS

3.1 下載安裝FastDFS

sudo git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs
./make.sh clean && ./make.sh && ./make.sh install

3.2 設置配置文件

./setup.sh /etc/fdfs

3.3 編輯或修改 tracker, storage, clien 配置文件

請確保防火牆允許 tracker 和 storage 的端口.
tracker:

  • port:22122
  • http_server_port:8080
    storage:
  • port:23000:
  • http_server_port:8888

3.3.1 新建存放fastdfs的數據的目錄

sudo mkdir -p /home/yuqing/fastdfs

你可以改爲自己喜歡的路徑名.下面我是以此爲基礎進行配置.

3.3.1 修改 tracker.conf

sudo vi /etc/fdfs/tracker.conf
  • bind_addr = 綁定此主機的一個地址,如果留空表示綁定此主機所有地址.
  • base_path=/home/yuqing/fastdfs(此文件目錄若沒有,要自己新建,不然會報錯)
  • 其他要求請查看文檔根據實際情況配置

3.3.2 修改 storage.conf

sudo vi /etc/fdfs/storage.conf
  • base_path=/home/yuqing/fastdfs(此文件目錄若沒有,要自己新建,不然會報錯)
  • store_path0=/home/yuqing/fastdfs(此文件目錄若沒有,要自己新建,不然會報錯)
  • tracker_server:192.168.1.100:22122 改爲自己的IP
  • group_name=group1 (因爲現在先只是配一個組,所以這裏就爲group1,多個組存儲時才需要改動)
  • 其他要求請查看文檔根據實際情況配置

3.3.3 修改 client.conf

sudo vi /etc/fdfs/client.conf
  • base_path=/home/yuqing/fastdfs(此文件目錄若沒有,要自己新建,不然會報)
  • tracker_server=192.168.1.100:22122改爲自己的IP
  • 其他要求請查看文檔根據實際情況配置

3.4 運行服務器程序

3.4.1 運行 tracker 服務器

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

3.4.2 運行 storage 服務器

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

3.4.3 在Linux中,可以啓動fdfs_trackerd和fdfs_storaged作爲服務:(可選)

這一步就不用做了,因爲Ubuntu18.04上不存在/sbin/service

/sbin/service dfs_trackerd restart
/sbin/service fdfs_storaged restart

3.5 運行監控程序(可選)

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

3.6 (可選)運行測試程序

比如:

/usr/bin/fdfs_test <client_conf_filename> <operation>
/usr/bin/fdfs_test1 <client_conf_filename> <operation>

例子:上傳一個文件做測試

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h

成功會返回URL如下:

This is FastDFS client test program v6.06

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.fastken.com/ 
for more detail.

[2020-02-24 03:22:16] DEBUG - base_path=/home/yuqing/fastdfs, connect_timeout=5, network_timeout=60, tracker_server_count=1, 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

tracker_query_storage_store_list_without_group: 
	server 1. group_name=, ip_addr=192.168.1.100, port=23000

group_name=group1, ip_addr=192.168.1.100, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.h
source ip address: 192.168.1.100
file timestamp=2020-02-24 03:22:16
file size=35784
file crc32=439681668
example file url: http://192.168.1.100/group1/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.h
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510_big.h
source ip address: 192.168.1.100
file timestamp=2020-02-24 03:22:16
file size=35784
file crc32=439681668
example file url: http://192.168.1.100/group1/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510_big.h

到這裏FastDFS安裝完成.

tracker 服務器配置文件例子請查看 conf/tracker.conf

storage 服務器配置文件例子請查看 conf/storage.conf

client 配置文件例子請查看 conf/client.conf

3.7 配置選項總覽

3.7.1 服務器共同選項

item name type default Must
base_path string Y
disabled boolean false N
bind_addr string N
network_timeout int 30(s) N
max_connections int 256 N
log_level string info N
run_by_group string N
run_by_user string N
allow_hosts string * N
sync_log_buff_interval int 10(s) N
thread_stack_size string 1M N

備註:

base_path是子目錄的基路徑:
datalogs base_path必須存在,如果不存在,其子目錄將自動創建.

$base_path/data: store data files
$base_path/logs: store log files

log_level是syslog的標準日誌級別,不區分大小寫.

  • emerg: 緊急
  • alert
  • crit: 危險
  • error
  • warn: 警告
  • notice
  • info
  • debug

allow_hosts可以多個,主機可以是主機名或ip地址:

*表示匹配所有的ip地址,可以使用這樣的範圍:10.0.1.[1-15,20]

或者 host[01-08,20-25].domain.com, 例如:

allow_hosts=10.0.1.[1-15,20]
allow_hosts=host[01-08,20-25].domain.com

3.7.2 tracker服務器選項

item name type default Must
port int 22000 N
store_lookup int 0 N
store_group string N
store_server int 0 N
store_path int 0 N
download_server int 0 N
reserved_storage_space string 1GB N

備註:

  • store_lookup 的值:
    • 0:循環(默認)
    • 1:指定group
    • 2:負載均衡(從V1.1開始支持)
  • store_group是存儲文件的組的名稱
    store_lookup設置爲1時(指定組),必須將store_group設置爲指定的組名.
  • reserved_storage_space是爲系統或其他應用程序保留的存儲空間.
    如果stoarge服務器group可用的空間<=reserved_storage_space`,
    則不再有文件能夠上傳到該group(版本V1.1及以上).
    字節單位如下:
    • G or g:gigabyte(GB)
    • M or m:megabyte(MB)
    • K or k for kilobyte(KB)
    • 無字節單位(B)

3.7.3 storage服務器選項

item name type default Must
group_name string Y
tracker_server string Y
port int 23000 N
heart_beat_interval int 30(s) N
stat_report_interval int 300(s) N
sync_wait_msec int 100(ms) N
sync_interval int 0(ms) N
sync_start_time string 00:00 N
sync_end_time string 23:59 N
store_path_count int 1 N
store_path0 string base_path N
store_path# string N
subdir_count_per_path int 256 N
check_file_duplicate boolean 0 N
key_namespace string N
keep_alive boolean 0 N
sync_binlog_buff_interval int 60s N

備註:

  • tracker_server可以多個,且tracker_server格式是host:port,主機可以是主機名或ip地址.
  • store_path#, #是數字,從0開始
  • check_file_duplicate:設置爲true時,必須和FastDHT服務器一起工作,
    更多的細節請查看INSTALL of FastDHT. FastDHT下載地址:
http://code.google.com/p/fastdht/downloads/list
  • key_namespace:當check_file_duplicate爲真時,FastDHT key_namespace不能爲空,鍵命名空間應該儘可能.

FastDFS擴展篇:nginx添加fastdfs-nginx-module模塊(非覆蓋安裝)(on ubuntu18.04)(FastDFS+nginx+fastdfs-nginx-module(2))

github:FastDFS
參考:happyfish100/fastdfs/INSTALL

歡迎打賞0.095元:
在這裏插入圖片描述

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