本文主要是介绍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 单机使用实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!