fast DFS 单机使用实例

2024-06-21 16:32
文章标签 使用 实例 dfs 单机 fast

本文主要是介绍fast DFS 单机使用实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

fast DFS 单机使用实例

我在一台服务器上简单测试了fastdfs。client, tracker, storage server都是同一个物理服务器。

 

1. 编译fastdfs:

 

sles207:/opt/mars/FastDFS # ./make.sh

 

storage_service.o: In function `storage_service_init':
/opt/mars/FastDFS/storage/storage_service.c:1100: undefined reference to `event_base_new'
storage_service.o: In function `work_thread_entrance':
/opt/mars/FastDFS/storage/storage_service.c:1364: undefined reference to `event_base_free'
collect2: ld returned 1 exit status
make: *** [fdfs_storaged] Error 1


没有装libevent,需下载安装。(http://monkey.org/~provos/libevent/)

 

 

2. 安装fastdfs:

 

sles207:/opt/mars/FastDFS # ./make.sh install
mkdir -p /usr/local/bin
mkdir -p /etc/fdfs
cp -f fdfs_trackerd  /usr/local/bin
if [ ! -f /etc/fdfs/tracker.conf ]; then cp -f ../conf/tracker.conf ../conf/mime.types ../conf/http.conf /etc/fdfs; fi
mkdir -p /usr/local/bin
mkdir -p /etc/fdfs
cp -f fdfs_storaged  /usr/local/bin
if [ ! -f /etc/fdfs/storage.conf ]; then cp -f ../conf/storage.conf ../conf/mime.types ../conf/http.conf /etc/fdfs; fi
mkdir -p /usr/local/bin
mkdir -p /etc/fdfs
mkdir -p /usr/local/lib
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/local/bin
cp -f libfastcommon.so.1 libfdfsclient.so.1 /usr/local/lib
if [ ! -f /etc/fdfs/client.conf ]; then cp -f ../conf/client.conf ../conf/http.conf /etc/fdfs; fi
mkdir -p /usr/local/include
mkdir -p /usr/local/include/fastcommon
mkdir -p /usr/local/include/fastdfs
cp -f ../common/common_define.h ../common/hash.h ../common/chain.h ../common/logger.h ../common/base64.h ../common/shared_func.h ../common/pthread_func.h ../common/ini_file_reader.h ../common/sockopt.h ../common/sched_thread.h ../common/http_func.h ../common/md5.h ../common/_os_bits.h ../common/local_ip_func.h /usr/local/include/fastcommon
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_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/local/include/fastdfs
#ln -fs /usr/local/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so
#ln -fs /usr/local/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so
sh ./fdfs_link_library.sh

3. 修改配置文件:

 

a. client.conf:

 

sles207:/etc/fdfs # cat client.conf 
# 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 log files
base_path=/opt/mars/fastdfs 

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=10.200.107.207 :22122

#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


#HTTP settings
http.tracker_server_port=8080

#use "#include" directive to include HTTP other settiongs
##include http.conf

 

b. storage.conf

 

sles207:/etc/fdfs # cat storage.conf 
# is this config file disabled
# false for enabled
# true for disabled
disabled=false

# the name of the group this storage server belongs to
group_name=group2 

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

# if bind an address of this host when connect to other servers 
# (this storage server as a client)
# true for binding the address configed by above parameter: "bind_addr"
# false for binding any address of this host
client_bind=true

# the storage server port
port=23000

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

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

# heart beat interval in seconds
heart_beat_interval=30

# disk usage report interval in seconds
stat_report_interval=60

# the base path to store data and log files
base_path=/opt/mars/fastdfs 

# max concurrent connections server supported
# max_connections worker threads start when this service startup
max_connections=256

# the buff size to recv / send data
# default value is 64KB
# since V2.00
buff_size = 256KB

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

# if disk read / write separated
##  false for mixed read and write
##  true for separated read and write
# default value is true
# since V2.00
disk_rw_separated = true

# if read / write file directly
# if set to true, open file will add the O_DIRECT flag to avoid file caching
# by the file system. be careful to set this parameter.
# default value is false
disk_rw_direct = false

# disk reader thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_reader_threads = 1

# disk writer thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_writer_threads = 1

# when no entry to sync, try read binlog again after X milliseconds
# 0 for try again immediately (not need to wait)
sync_wait_msec=200

# after sync a file, usleep milliseconds
# 0 for sync successively (never call usleep)
sync_interval=0

# sync start time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_start_time=00:00

# sync end time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_end_time=23:59

# write to the mark file after sync N files
# default value is 500
write_mark_file_freq=500

# path(disk or mount point) count, default value is 1
store_path_count=1

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/opt/mars/fastdfs 
#store_path1=/home/yuqing/fastdfs2

# subdir_count  * subdir_count directories will be auto created under each 
# store_path (disk), value can be 1 to 256, default value is 256
subdir_count_per_path=256

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=10.200.107.207 :22122

#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=*

# the mode of the files distributed to the data path
# 0: round robin(default)
# 1: random, distributted by hash code
file_distribute_path_mode=0

# valid when file_distribute_to_path is set to 0 (round robin), 
# when the written file count reaches this number, then rotate to next path
# default value is 100
file_distribute_rotate_count=100

# call fsync to disk when write big file
# 0: never call fsync
# other: call fsync when written bytes >= this bytes
# default value is 0 (never call fsync)
fsync_after_written_bytes=0

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

# sync binlog buff / cache to disk every interval seconds
# this parameter is valid when write_to_binlog set to 1
# default value is 60 seconds
sync_binlog_buff_interval=60

# sync storage stat info to disk every interval seconds
# default value is 300 seconds
sync_stat_file_interval=300

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

# the priority as a source server for uploading file.
# the lower this value, the higher its uploading priority.
# default value is 10
upload_priority=10

# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=

# if check file duplicate, when set to true, use FastDHT to store file indexes
# 1 or yes: need check
# 0 or no: do not check
# default value is 0
check_file_duplicate=0

# namespace for storing file indexes (key-value pairs)
# this item must be set when check_file_duplicate is true / on
key_namespace=FastDFS

# set keep_alive to 1 to enable persistent connection with FastDHT servers
# default value is 0 (short connection)
keep_alive=0

# you can use "#include filename" (not include double quotes) directive to 
# load FastDHT server list, when the filename is a relative path such as 
# pure filename, the base path is the base path of current/this config file.
# must set FastDHT server list when check_file_duplicate is true / on
# please see INSTALL of FastDHT for detail
##include /home/yuqing/fastdht/conf/fdht_servers.conf


#HTTP settings
http.disabled=false

# use the ip address of this storage server if domain_name is empty,
# else this domain name will ocur in the url redirected by the tracker server
http.domain_name=

# the port of the web server on this storage server
http.server_port=8888

http.trunk_size=256KB

# if need find content type from file extension name
http.need_find_content_type=true

#use "#include" directive to include HTTP other settings
##include http.conf

 

c. tracker.conf

 

# 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=/opt/mars/fastdfs 

# max concurrent connections this server supported
max_connections=256

 

(tracker_server不可配置为127.0.0.1, 否则有以下错误 )

sles207:/opt/mars/fastdfs/logs # vi storaged.log 

      1 [2011-04-27 02:13:03] ERROR - file: storage_func.c, line: 1083, conf file "/etc/fdfs/storage.conf", tracker: "127.0.0
        .1:22122" is invalid, tracker server ip can't be 127.0.0.1
      2 [2011-04-27 02:13:17] ERROR - file: storage_func.c, line: 1083, conf file "/etc/fdfs/storage.conf", tracker: "127.0.0
        .1:22122" is invalid, tracker server ip can't be 127.0.0.1
      3 [2011-04-27 02:13:23] ERROR - file: storage_func.c, line: 1083, conf file "/etc/fdfs/storage.conf", tracker: "127.0.0
        .1:22122" is invalid, tracker server ip can't be 127.0.0.1
~     

 

4. 启动tracker server:

                                                               
sles207:/etc/fdfs # /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf


5. 启动 storage server:


sles207:/etc/fdfs # /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

....

 

sles207:/opt/mars/fastdfs/data # ls
.data_init_flag  0B  17  23  2F  3B  47  53  5F  6B  77  83  8F  9B  A7  B3  BF  CB  D7  E3  EF  FB
00               0C  18  24  30  3C  48  54  60  6C  78  84  90  9C  A8  B4  C0  CC  D8  E4  F0  FC
01               0D  19  25  31  3D  49  55  61  6D  79  85  91  9D  A9  B5  C1  CD  D9  E5  F1  FD
02               0E  1A  26  32  3E  4A  56  62  6E  7A  86  92  9E  AA  B6  C2  CE  DA  E6  F2  FE
03               0F  1B  27  33  3F  4B  57  63  6F  7B  87  93  9F  AB  B7  C3  CF  DB  E7  F3  FF
04               10  1C  28  34  40  4C  58  64  70  7C  88  94  A0  AC  B8  C4  D0  DC  E8  F4  storage_changelog.dat
05               11  1D  29  35  41  4D  59  65  71  7D  89  95  A1  AD  B9  C5  D1  DD  E9  F5  storage_groups_new.dat
06               12  1E  2A  36  42  4E  5A  66  72  7E  8A  96  A2  AE  BA  C6  D2  DE  EA  F6  storage_servers_new.dat
07               13  1F  2B  37  43  4F  5B  67  73  7F  8B  97  A3  AF  BB  C7  D3  DF  EB  F7  storage_stat.dat
08               14  20  2C  38  44  50  5C  68  74  80  8C  98  A4  B0  BC  C8  D4  E0  EC  F8  storage_sync_timestamp.dat
09               15  21  2D  39  45  51  5D  69  75  81  8D  99  A5  B1  BD  C9  D5  E1  ED  F9  sync
0A               16  22  2E  3A  46  52  5E  6A  76  82  8E  9A  A6  B2  BE  CA  D6  E2  EE  FA
sles207:/opt/mars/fastdfs/data # 

6. 测试上传文件:


sles207:/etc/fdfs # /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h     
This is FastDFS client test program v2.09

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.csource.org/ 
for more detail.

[2011-04-27 02:18:42] INFO - base_path=/opt/mars/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0

tracker_query_storage_store_list_without_group: 
        server 1. group_name=group2, ip_addr=10.200.107.207, port=23000

group_name=group2, ip_addr=10.200.107.207, port=23000
storage_upload_by_filename
group_name=group2, remote_filename=M00/00/00/Cshrz023DILK-oIwAACH_5lVJGU05649.h
source ip address: 10.200.107.207
file timestamp=2011-04-27 02:18:42
file size=34815
file crc32=2572493925
file url: http://10.200.107.207:8080/group2/M00/00/00/Cshrz023DILK-oIwAACH_5lVJGU05649.h
storage_upload_slave_by_filename
group_name=group2, remote_filename=M00/00/00/Cshrz023DILK-oIwAACH_5lVJGU05649_big.h
source ip address: 10.200.107.207
file timestamp=2011-04-27 02:18:43
file size=34815
file crc32=2572493925
file url: http://10.200.107.207:8080/group2/M00/00/00/Cshrz023DILK-oIwAACH_5lVJGU05649_big.h
sles207:/etc/fdfs # 


sles207:/opt/mars/fastdfs/data # find . -name Cshrz023DILK-oIwAACH_5lVJGU05649_big.h
./00/00/Cshrz023DILK-oIwAACH_5lVJGU05649_big.h
sles207:/opt/mars/fastdfs/data # 
sles207:/opt/mars/fastdfs/data # find . -name Cshrz023DILK-oIwAACH_5lVJGU05649.h
./00/00/Cshrz023DILK-oIwAACH_5lVJGU05649.h
sles207:/opt/mars/fastdfs/data # 

7. 查看整个fastdfs状态:


sles207:/etc/fdfs # /usr/local/bin/fdfs_monitor /etc/fdfs/client.conf
[2011-04-27 02:21:56] INFO - base_path=/opt/mars/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0

server_count=1, server_index=0

tracker server is 10.200.107.207:22122

group count: 1

Group 1:
group name = group2
free space = 309 GB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0

        Storage 1:
                ip_addr = 10.200.107.207 (sles207.10.198.88.18)  ACTIVE
                http domain = 
                version = 2.09
                join time = 2011-04-27 02:14:56
                up time = 2011-04-27 02:14:56
                total storage = 679GB
                free storage = 309GB
                upload priority = 10
                store_path_count = 1
                subdir_count_per_path = 256
                storage_port = 23000
                storage_http_port = 8888
                current_write_path = 0
                source ip_addr = 
                total_upload_count = 1
                success_upload_count = 1
                total_append_count = 0
                success_append_count = 0
                total_set_meta_count = 2
                success_set_meta_count = 2
                total_delete_count = 0
                success_delete_count = 0
                total_download_count = 0
                success_download_count = 0
                total_get_meta_count = 0
                success_get_meta_count = 0
                total_create_link_count = 0
                success_create_link_count = 0
                total_delete_link_count = 0
                success_delete_link_count = 0
                total_upload_bytes = 34815
                success_upload_bytes = 34815
                total_append_bytes = 0
                success_append_bytes = 0
                stotal_download_bytes = 0
                success_download_bytes = 0
                total_sync_in_bytes = 0
                success_sync_in_bytes = 0
                total_sync_out_bytes = 0
                success_sync_out_bytes = 0
                total_file_open_count = 2
                success_file_open_count = 2
                total_file_read_count = 0
                success_file_read_count = 0
                total_file_write_count = 2
                success_file_write_count = 2
                last_heart_beat_time = 2011-04-27 02:21:40
                last_source_update = 2011-04-27 02:18:43
                last_sync_update = 1970-01-01 08:00:00
                last_synced_timestamp = 1970-01-01 08:00:00 
sles207:/etc/fdfs #

这篇关于fast DFS 单机使用实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1081740

相关文章

使用Go调用第三方API的方法详解

《使用Go调用第三方API的方法详解》在现代应用开发中,调用第三方API是非常常见的场景,比如获取天气预报、翻译文本、发送短信等,Go作为一门高效并发的编程语言,拥有强大的标准库和丰富的第三方库,可以... 目录引言一、准备工作二、案例1:调用天气查询 API1. 注册并获取 API Key2. 代码实现3

MySQL8.0临时表空间的使用及解读

《MySQL8.0临时表空间的使用及解读》MySQL8.0+引入会话级(temp_N.ibt)和全局(ibtmp1)InnoDB临时表空间,用于存储临时数据及事务日志,自动创建与回收,重启释放,管理高... 目录一、核心概念:为什么需要“临时表空间”?二、InnoDB 临时表空间的两种类型1. 会话级临时表

MySQL之复合查询使用及说明

《MySQL之复合查询使用及说明》文章讲解了SQL复合查询中emp、dept、salgrade三张表的使用,涵盖多表连接、自连接、子查询(单行/多行/多列)及合并查询(UNION/UNIONALL)等... 目录复合查询基本查询回顾多表查询笛卡尔积自连接子查询单行子查询多行子查询多列子查询在from子句中使

Kotlin 协程之Channel的概念和基本使用详解

《Kotlin协程之Channel的概念和基本使用详解》文章介绍协程在复杂场景中使用Channel进行数据传递与控制,涵盖创建参数、缓冲策略、操作方式及异常处理,适用于持续数据流、多协程协作等,需注... 目录前言launch / async 适合的场景Channel 的概念和基本使用概念Channel 的

C#使用SendMessage实现进程间通信的示例代码

《C#使用SendMessage实现进程间通信的示例代码》在软件开发中,进程间通信(IPC)是关键技术之一,C#通过调用WindowsAPI的SendMessage函数实现这一功能,本文将通过实例介绍... 目录第一章:SendMessage的底层原理揭秘第二章:构建跨进程通信桥梁2.1 定义通信协议2.2

使用python制作一款文件粉碎工具

《使用python制作一款文件粉碎工具》这篇文章主要为大家详细介绍了如何使用python制作一款文件粉碎工具,能够有效粉碎密码文件和机密Excel表格等,感兴趣的小伙伴可以了解一下... 文件粉碎工具:适用于粉碎密码文件和机密的escel表格等等,主要作用就是防止 别人用数据恢复大师把你刚删除的机密的文件恢

MySQL使用EXISTS检查记录是否存在的详细过程

《MySQL使用EXISTS检查记录是否存在的详细过程》EXISTS是SQL中用于检查子查询是否返回至少一条记录的运算符,它通常用于测试是否存在满足特定条件的记录,从而在主查询中进行相应操作,本文给大... 目录基本语法示例数据库和表结构1. 使用 EXISTS 在 SELECT 语句中2. 使用 EXIS

在Android中使用WebView在线查看PDF文件的方法示例

《在Android中使用WebView在线查看PDF文件的方法示例》在Android应用开发中,有时我们需要在客户端展示PDF文件,以便用户可以阅读或交互,:本文主要介绍在Android中使用We... 目录简介:1. WebView组件介绍2. 在androidManifest.XML中添加Interne

Java Stream流与使用操作指南

《JavaStream流与使用操作指南》Stream不是数据结构,而是一种高级的数据处理工具,允许你以声明式的方式处理数据集合,类似于SQL语句操作数据库,本文给大家介绍JavaStream流与使用... 目录一、什么是stream流二、创建stream流1.单列集合创建stream流2.双列集合创建str

Python使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv