fastDFS分布式文件服务器入门

一.FastDFS介绍

1.1 FastDFS简介

​ FastDFS 开源的分布式文件系统,用纯C语言开发。只能通过专有API进行文件存取访问,不支持POSIX接口方式,不能mount使用。它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载均衡。主要解决了海量数据存储问题,特别适合以中小文件(建议范围:4KB < file_size <500MB)为载体的在线服务。

1.2 FastDFS架构

FastDFS架构包括 Tracker server和Storage server。客户端请求Tracker server进行文件上传、下载,通过Trackerserver调度最终由Storage server完成文件上传和下载。

FastDFS 系统有三个角色:跟踪服务器(Tracker Server)、存储服务器(Storage Server)和客户端(Client)。

  Tracker Server:跟踪服务器,主要做调度工作,起到均衡的作用;负责管理所有的 storage server和 group,每个 storage 在启动后会连接 Tracker,告知自己所属 group 等信息,并保持周期性心跳。通过Trackerserver在文件上传时可以根据一些策略找到Storageserver提供文件上传服务。

  Storage Server:存储服务器,主要提供容量和备份服务;以 group 为单位,每个 group 内可以有多台 storage server,数据互为备份。Storage server没有实现自己的文件系统而是利用操作系统 的文件系统来管理文件。

  Client:客户端,上传下载数据的服务器,也就是我们自己的项目所部署在的服务器。

二.FastDFS安装

FastDFS 开源地址:https://github.com/happyfish100

百度云盘:software 提取码:41h3

2.1 环境,软件版本说明

​ 操作系统:centos7

​ Fast DFS:FastDFS_v5.05

​ ngnix:ngnix-1.9.9

​ nignx模块:fastdfs-nginx-module_v1.16

​ 依赖库:libfastcommonV1.0.7

不同版本安装时有些许差别

2.2 安装

2.2.1 准备系统

​ 我这里用的时虚拟机,之前装好的centos7。系统准备好之后,要测试一下网络是否通畅,我这里用的桥接模式。设置静态的IP地址。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//查看一下网关,等会好知道修改那个文件
#ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::c386:6589:6b16:64cb prefixlen 64 scopeid 0x20<link>
inet6 fe80::5b9d:7b1f:bb1f:4ec3 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:dc:9a:48 txqueuelen 1000 (Ethernet)
RX packets 9130 bytes 800217 (781.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3014 bytes 518483 (506.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 1864 bytes 146189 (142.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1864 bytes 146189 (142.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

// 上面看到网关名称 enp0s3,就去修改/etc/sysconfig/network-scripts/ifcfg-enp0s3
#vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
BOOTPROTO="static" //修改为静态的
IPADDR="192.168.1.103" //本机ip地址
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
DNS1="211.99.143.33"
DNS2="58.30.131.33"
//修改好后,需要重启网络
#service network restart
//centos7 查看主机名,设置主机名
#hostname
#hostnamectl set-hostname gaofeng2

2.2.2 安装GCC

因为FastDFS是C语言编写,因此FastDFS编译时需要依赖gcc

1
2
3
4
5
//查看是否安装gcc
# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
//输出安装目录,说明已经安装过,如果未安装可以执行以下命令
# yum -y install gcc-c++

2.2.3 安装libevent

1
# yum -y install libevent

2.2.4 安装libfastcommon

FastDFS 依赖的一些类库,要下载对应的版本

下载地址: https://github.com/happyfish100/libfastcommon/releases 选择合适的版本

我这里都下载好了,存放在/usr/software目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# cd /usr/software
//解压
# tar -zxvf libfastcommonV1.0.7.tar.gz
//进入到解压后的libfastcommon目录下
# cd libfastcommon-1.0.7
//编译
# ./make.sh
// 安装
#./make.sh install
mkdir -p /usr/lib64
install -m 755 libfastcommon.so /usr/lib64
mkdir -p /usr/include/fastcommon
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_bits.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h /usr/include/fastcommon
//把src目录下的libfastcommon.so 文件复制到/usr/lib目录下
#cp libfastcommon.so /usr/lib

2.2.5 安装FastDFS

下载安装包,上传到/usr/software目录下如果是在xshellx 工具下,可以直接使用rz命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# cd /usr/software
//解压文件
# tar -zxvf FastDFS_v5.05.tar.gz
// 编译
# ./make.sh
// 安装
# ./make.sh install
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_trackerd /usr/bin
if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_storaged /usr/bin
if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender /usr/bin
if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; fi
mkdir -p /usr/include/fastdfs
cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs
if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi

进入/etc/fdfs/目录下查看是否有配置文件如果没有的话,FastDFS/conf目录下的配置文件复制过去(目录根据实际情况修改)

默认安装后,

执行命令在/usr/bin目录下

服务脚本在 /etc/init.d/目录下

配置文件在 /etc/fdfs/目录下

1
# cp /usr/software/FastDFS/conf/* /etc/fdfs/

2.2.6 配置tracker

进入/etc/fdfs目录下,查看是否有tracker.conf,如果没有,就把tracker.conf.sample文件修改为tracker.conf

1
2
3
4
5
6
7
8
9
10
11
# ls
client.conf.sample storage.conf.sample tracker.conf.sample
# cp tracker.conf.sample tracker.conf
//修改tracker.conf,vi命令:i 进入编辑状态 编辑完成后按esc退出编辑 :wq! 保存并强制退出
# vi tracker.conf
//主要修改
//base_path =/fastdfs/tracker 根目录,如果没有需要手动创建
//http.server_port=8080 端口是防止冲突 记住端口号,别忘了防火墙开放

//创建/fastdfs/tracker
# mkdir -p /fastdfs/tracker

修改防火墙配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//查看防火墙状态
# firewall-cmd --state
running
//查看已经开放的端口
# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: dhcpv6-client ssh
ports: 3306/tcp 80/tcp 8080/tcp 2181/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
// 开放 22122 和 7777 端口
# firewall-cmd --permanent --add-port=22122/tcp
success
# firewall-cmd --permanent --add-port=7777/tcp
success
//重启防火墙
#service firewalld restart

启动Tracker,第一坑即将出现

1
2
#/etc/init.d/fdfs_trackerd start
#systemctl start fdfs_tracked

Job for fdfs_trackerd.service failed because the control process exited with error code. See “systemctl status fdfs_trackerd.service” and “journalctl -xe” for details.

#systemctl status fdfs_trackerd.service
● fdfs_trackerd.service - LSB: FastDFS tracker server
Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since 四 2020-02-27 16:29:06 CST; 1min 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 3967 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=2)

2月 27 16:29:06 gaofeng1 systemd[1]: Starting LSB: FastDFS tracker server…
2月 27 16:29:06 gaofeng1 fdfs_trackerd[3967]: file /usr/local/bin/fdfs_trackerd does not exist!
2月 27 16:29:06 gaofeng1 systemd[1]: fdfs_trackerd.service: control process exited, code=exited status=2
2月 27 16:29:06 gaofeng1 systemd[1]: Failed to start LSB: FastDFS tracker server.
2月 27 16:29:06 gaofeng1 systemd[1]: Unit fdfs_trackerd.service entered failed state.
2月 27 16:29:06 gaofeng1 systemd[1]: fdfs_trackerd.service failed.

file /usr/local/bin/fdfs_trackerd does not exist! 说没有找到该文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#find / -name fdfs_trackerd
/etc/rc.d/init.d/fdfs_trackerd
/usr/bin/fdfs_trackerd
/usr/software/FastDFS/tracker/fdfs_trackerd
/usr/software/FastDFS/init.d/fdfs_trackerd

// 复制一个去/usr/local/bin目录下,后面还缺少三个文件,一块复制过去
# cp /usr/bin/fdfs_trackerd /usr/local/bin/
# cp /usr/bin/stop.sh /usr/local/bin/
# cp /usr/bin/restart.sh /usr/local/bin/
然后再次启动
#systemctl start fdfs_trackerd
查看是否启动正常
## systemctl status fdfs_trackerd

● fdfs_trackerd.service - LSB: FastDFS tracker server
Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd; bad; vendor preset: disabled)
Active: active (running) since 四 2020-02-27 16:37:26 CST; 42s ago
Docs: man:systemd-sysv-generator(8)
Process: 4010 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/fdfs_trackerd.service
└─4013 /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

2月 27 16:37:26 gaofeng1 systemd[1]: Starting LSB: FastDFS tracker server…
2月 27 16:37:26 gaofeng1 fdfs_trackerd[4010]: Starting FastDFS tracker server:
2月 27 16:37:26 gaofeng1 systemd[1]: Started LSB: FastDFS tracker server.

关闭tracker

1
2
3
# systemctl stop fdfs_trackerd      (centos7 推荐)
# service fdfs_trackerd stop
# /etc/init.d/fdfs_trackerd stop

重启tracker

1
# chkconfig fdfs_trackerd on

tracker server 目录及文件结构
Tracker服务启动成功后,会在base_path下创建data、logs两个目录。目录结构如下:

tracker server 目录及文件结构
Tracker服务启动成功后,会在base_path下创建data、logs两个目录。目录结构如下:

${base_path}
|data
| |
storage_groups.dat:存储分组信息
| |storage_servers.dat:存储服务器列表
|
logs
| |__trackerd.log: tracker server 日志文件
————————————————

2.2.7 配置storage

过程和配置tracker类似

1
2
3
# cd /etc/fdfs
# cp storage.conf.sample storage.conf
# vim storage.conf

主要配置项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 配置文件是否不生效,false 为生效
disabled=false 
# 指定此 storage server 所在 组(卷)
group_name=group1
# storage server 服务端口
port=23000
# 心跳间隔时间,单位为秒 (这里是指主动向 tracker server 发送心跳)
heart_beat_interval=30
# Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)  (注 :这里不是上传的文件存放的地址,之前版本是的,在某个版本后更改了)
base_path=/fastdfs/storage/base
# 存放文件时 storage server 支持多个路径。这里配置存放文件的基路径数目,通常只配一个目录。
store_path_count=1
# 逐一配置 store_path_count 个路径,索引号基于 0。
# 如果不配置 store_path0,那它就和 base_path 对应的路径一样。
store_path0=/fastdfs/storage
# FastDFS 存储文件时,采用了两级目录。这里配置存放文件的目录个数。 
# 如果本参数只为 N(如: 256),那么 storage server 在初次运行时,会在 store_path 下自动创建 N * N 个存放文件的子目录。
subdir_count_per_path=256
# tracker_server 的列表 ,会主动连接 tracker_server
# 有多个 tracker server 时,每个 tracker server 写一行
tracker_server=192.168.1.110:22122


# 允许系统同步的时间段 (默认是全天) 。一般用于避免高峰同步产生一些问题而设定。
sync_start_time=00:00
sync_end_time=23:59
# 访问端口 默认80  建议修改 防止冲突
http.server_port=7001

创建目录,和开放端口号

1
2
3
4
5
#mkdir -p /fastdfs/storage/base
#firewall-cmd --permanent --add-port=7001/tcp
#firewall-cmd --permanent --add-port=23000/tcp
重启防火墙
#service firewalld restart

启动storage,可能会遇到和启动tracker一样的坑,解决方法也一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# cp /usr/bin/fdfs_storaged /usr/local/bin/
可以用这种方式启动
# /etc/init.d/fdfs_storaged start
# service fdfs_storaged start
# systemctl start fdfs_storaged #centos7 推荐
# systemctl status fdfs_storaged
● fdfs_storaged.service - LSB: FastDFS storage server
Loaded: loaded (/etc/rc.d/init.d/fdfs_storaged; bad; vendor preset: disabled)
Active: active (running) since 四 2020-02-27 17:01:14 CST; 18s ago
Docs: man:systemd-sysv-generator(8)
Process: 2495 ExecStart=/etc/rc.d/init.d/fdfs_storaged start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/fdfs_storaged.service
└─2499 /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

2月 27 17:01:14 gaofeng1 systemd[1]: Starting LSB: FastDFS storage server...
2月 27 17:01:14 gaofeng1 fdfs_storaged[2495]: Starting FastDFS storage server:
2月 27 17:01:14 gaofeng1 systemd[1]: Started LSB: FastDFS storage server.

关闭storage

1
2
3
[root@localhost fdfs]# service fdfs_storaged stop
[root@localhost fdfs]# systemctl stop fdfs_storaged #centos7 推荐
[root@localhost fdfs]# /etc/init.d/fdfs_storaged stop

查看storage和tracker能否正常通信

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2020-02-27 17:04:08] DEBUG - base_path=/fastdfs/storage/base, connect_timeout=30, 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

server_count=1, server_index=0

tracker server is 192.168.1.110:22122

group count: 1

Group 1:
group name = group1
disk total space = 15550 MB
disk free space = 12729 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 7001
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
.......

设置storage开机启动

1
# chkconfig fdfs_storaged on

2.2.8 测试

需要先修改tracker服务器上的client.conf配置文件,在/etc/fdfs 目录下

1
2
3
4
# Client 的数据和日志目录  别忘了手动创建
base_path=/fastdfs/client
# Tracker端口
tracker_server=192.168.1.110:22122

先在系统根目录上传一张图片

1
2
# # /usr/bin/fdfs_upload_file /etc/fdfs/client.conf timg.jpg 
group1/M00/00/00/wKgBbl5Xh8uABINMAAB80x5XCg8444.jpg

上传成功后,会返回一个存储路径。返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。

至此,FastDFS安装成功了

配置nginx,http访问文件

修改nginx配置文件,先查看一下nginx 安装目录

1
2
3
# whereis nginx
nginx: /usr/local/nginx
# vi /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 7001; #该端口号要和storage.conf 配置文件中http.server.port端口一致
server_name 192.168.1.110;
location /group1/M00 {
alias /fastdfs/storage/data;
autoindex on;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

浏览器访问:http://192.168.1.110:7001/group1/M00/00/00/wKgBbl5Xh8uABINMAAB80x5XCg8444.jpg

图片出来有木有。

安装nginx模块fastdfs-nginx-module

前面说过,同组下的storage会自动同步文件,如果我们上传一个文件后,里面访问。这个时候恰恰文件还没有同步完成,请求又被分配到另外的storage上,那么图片就会404了。fastdfs-nginx-module就是解决这个问题的。

首先解压fastdfs-nginx-module_v1.16.tar.gz,修改/fastdfs-nginx-module/src/config文件。去掉所有的local(三个),修改成如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

#之前的
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

拷贝usr/lib64目录下库文件libfdfsclient.so

1
#cp /usr/lib64/libfdfsclient.so /usr/lib

在nginx安装目录下执行如下命令:把module添加nginx中。通过设置安装参数方式添加模块。注意模块文件所在目录,我本地是和nginx文件目录同级

1
2
3
4
5
6
7
8
9
10
11
12
13
#ls
apache-tomcat-8.5.50 fastdfs-nginx-module libfastcommon-1.0.7 nginx-1.9.9.tar.gz
apache-tomcat-8.5.50.tar.gz fastdfs-nginx-module_v1.16.tar.gz libfastcommonV1.0.7.tar.gz zookeeper-3.4.6
FastDFS FastDFS_v5.05.tar.gz nginx-1.9.9 zookeeper-3.4.6.tar.gz
#cd nginx-1.9.9
#./configure --add-module=../fastdfs-nginx-module/src
//从新编译nginx
make && make install
//安装完成后,可以查看nginx的模块,依然去/usr/local/nginx/sbin目录下 V大写
# ./nginx -V
nginx version: nginx/1.9.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --add-module=../fastdfs-nginx-module/src

复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

1
2
#cp /usr/software/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
#vi /etc/fdfs/mod_fastdfs.conf
1
2
3
4
5
6
7
8
9
10
11
12
# 连接超时时间
connect_timeout=10
# Tracker Server
tracker_server=192.168.1.110:22122
# StorageServer 默认端口
storage_server_port=23000
# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true
# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/fastdfs/storage
# the base path to store log files
base_path=/fastdfs/storage/base

复制/usr/software/FastDFS/conf 目录下的http.conf mime.types anti-steal.jpg 到etc/fdfs目录下,这个很重要,不然nginx启动失败

1
#cp http.conf mime.types /etc/fdfs/

再次修改nginx配置文件,注意头部 user root;

1
# vi /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {

listen 9888 ;
server_name 192.168.0.200;

# location /group1/M00{
# alias /fastdfs/storage/data/;
# autoindex on;
#}
location ~/group[0-9]/ {
ngx_fastdfs_module;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

}

http://192.168.1.110:7001/group1/M00/00/00/wKgBbl5XlaCARCd2AAB80x5XCg8523.jpg

访问成功!!!!

其实如果是但storage的话,就不用配置fastdfs-nginx-module

有机会的话,在研究一下集群搭建。

—tracker.conf 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# is this config file disabled
# false for enabled
# true for disabled
# 文件是否生效
disabled=false

# bind an address of this host
# empty for bind all addresses of this host
bind_addr=

# the tracker server port
#默认运行端口
port=22122

# connect timeout in seconds
# default value is 30s
connect_timeout=30

# network timeout in seconds
# default value is 30s
network_timeout=60

# the base path to store data and log files
# 根目录,没有的话需要手动创建
base_path=/home/yuqing/fastdfs

# max concurrent connections this server supported
max_connections=256

# accept thread count
# default value is 1
# since V4.07
accept_threads=1

# work thread count, should <= max_connections
# default value is 4
# since V2.00
work_threads=4

# the method of selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
store_lookup=2

# which group to upload file
# when store_lookup set to 1, must set store_group to the group name
store_group=group2

# which storage server to upload file
# 0: round robin (default)
# 1: the first server order by ip address
# 2: the first server order by priority (the minimal)
store_server=0

# which path(means disk or mount point) of the storage server to upload file
# 0: round robin
# 2: load balance, select the max free space path to upload file
store_path=0

# which storage server to download file
# 0: round robin (default)
# 1: the source storage server which the current file uploaded to
download_server=0

# reserved storage space for system or other applications.
# if the free(available) space of any stoarge server in
# a group <= reserved_storage_space,
# no file can be uploaded to this group.
# bytes unit can be one of follows:
### G or g for gigabyte(GB)
### M or m for megabyte(MB)
### K or k for kilobyte(KB)
### no unit for byte(B)
### XX.XX% as ratio such as reserved_storage_space = 10%
reserved_storage_space = 10%

#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

#unix group name to run this program,
#not set (empty) means run by the group of current user
run_by_group=

#unix username to run this program,
#not set (empty) means run by current user
run_by_user=

# allow_hosts can ocur more than once, host can be hostname or ip address,
# "*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20] or
# host[01-08,20-25].domain.com, for example:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
allow_hosts=*

# sync log buff to disk every interval seconds
# default value is 10 seconds
sync_log_buff_interval = 10

# check storage server alive interval seconds
check_active_interval = 120

# thread stack size, should >= 64KB
# default value is 64KB
thread_stack_size = 64KB

# auto adjust when the ip address of the storage server changed
# default value is true
storage_ip_changed_auto_adjust = true

# storage sync file max delay seconds
# default value is 86400 seconds (one day)
# since V2.00
storage_sync_file_max_delay = 86400

# the max time of storage sync a file
# default value is 300 seconds
# since V2.00
storage_sync_file_max_time = 300

# if use a trunk file to store several small files
# default value is false
# since V3.00
use_trunk_file = false

# the min slot size, should <= 4KB
# default value is 256 bytes
# since V3.00
slot_min_size = 256

# the max slot size, should > slot_min_size
# store the upload file to trunk file when it's size <= this value
# default value is 16MB
# since V3.00
slot_max_size = 16MB

# the trunk file size, should >= 4MB
# default value is 64MB
# since V3.00
trunk_file_size = 64MB

# if create trunk file advancely
# default value is false
# since V3.06
trunk_create_file_advance = false

# the time base to create trunk file
# the time format: HH:MM
# default value is 02:00
# since V3.06
trunk_create_file_time_base = 02:00

# the interval of create trunk file, unit: second
# default value is 38400 (one day)
# since V3.06
trunk_create_file_interval = 86400

# the threshold to create trunk file
# when the free trunk file size less than the threshold, will create
# the trunk files
# default value is 0
# since V3.06
trunk_create_file_space_threshold = 20G

# if check trunk space occupying when loading trunk free spaces
# the occupied spaces will be ignored
# default value is false
# since V3.09
# NOTICE: set this parameter to true will slow the loading of trunk spaces
# when startup. you should set this parameter to true when neccessary.
trunk_init_check_occupying = false

# if ignore storage_trunk.dat, reload from trunk binlog
# default value is false
# since V3.10
# set to true once for version upgrade when your version less than V3.10
trunk_init_reload_from_binlog = false

# the min interval for compressing the trunk binlog file
# unit: second
# default value is 0, 0 means never compress
# FastDFS compress the trunk binlog when trunk init and trunk destroy
# recommand to set this parameter to 86400 (one day)
# since V5.01
trunk_compress_binlog_min_interval = 0

# if use storage ID instead of IP address
# default value is false
# since V4.00
use_storage_id = false

# specify storage ids filename, can use relative or absolute path
# since V4.00
storage_ids_filename = storage_ids.conf

# id type of the storage server in the filename, values are:
## ip: the ip address of the storage server
## id: the server id of the storage server
# this paramter is valid only when use_storage_id set to true
# default value is ip
# since V4.03
id_type_in_filename = ip

# if store slave file use symbol link
# default value is false
# since V4.01
store_slave_file_use_link = false

# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false

# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00

# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0

# keep days of the log files
# 0 means do not delete old log files
# default value is 0
log_file_keep_days = 0

# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600

# HTTP port on this tracker server
# http访问端口号,为了防止冲突,建议修改
http.server_port=8080

# check storage HTTP server alive interval seconds
# <= 0 for never check
# default value is 30
http.check_alive_interval=30

# check storage HTTP server alive type, values are:
# tcp : connect to the storge server with HTTP port only,
# do not request and get response
# http: storage check alive url must return http status 200
# default value is tcp
http.check_alive_type=tcp

# check storage HTTP server alive uri/url
# NOTE: storage embed HTTP server support uri: /status.html
http.check_alive_uri=/status.html