fastdfs安装与配置
FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等
192.168.12.22(tracker)操作
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
tar zxvf FastDFS_v5.07.tar.gz
cd FastDFS
./make.sh
./make.sh install
cd /cacti/FastDFS/conf
mkdir -p /home/yuqing/fastdfs
ln -s /cacti/FastDFS/conf/tracker.conf /etc/fdfs/
egrep -v "#" /etc/fdfs/tracker.conf
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/fastdfs
max_connections=256
accept_threads=1
work_threads=4
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
/etc/init.d/fdfs_trackerd start
------------以上操作在另一台服务器上操作--192.168.12.25(storaged)-------------------------------
ln -s /cacti/FastDFS/conf/storage.conf /etc/fdfs/
vi storage.conf
tracker_server=192.168.12.22:22122(改成你tracker服务器的ip)
egrep -v "#" /etc/fdfs/storage.conf
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/fastdfs
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=/fastdfs
subdir_count_per_path=256
tracker_server=192.168.12.22: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
/etc/init.d/fdfs_storaged start
测试上传12.22操作
ln -s /cacti/FastDFS/conf/client.conf /etc/fdfs/
egrep -v "#" /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/home/yuqing/fastdfs
tracker_server=192.168.12.22: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=80
/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.jpg
This is FastDFS client test program v5.07
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.
[2015-12-05 22:46:22] DEBUG - base_path=/fastdfs, 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
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.12.25, port=23000
group_name=group1, ip_addr=192.168.12.25, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
source ip address: 192.168.12.25
file timestamp=2015-12-05 22:46:22
file size=1354
file crc32=1635612871
example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg
source ip address: 192.168.12.25
file timestamp=2015-12-05 22:46:22
file size=1354
file crc32=1635612871
example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg
查看原图
ls /fastdfs/data/00/00
wKgMGVZi9umANr4BAAAFSmF9eMc486.jpg wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg-m
wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg-m
fastdfs命令
#上传文件:/usr/bin/fdfs_upload_file <config_file> <local_filename>
#下载文件:/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]
#删除文件:/usr/bin/fdfs_delete_file <config_file> <file_id>
推荐的FastDFS部署方案
文件上传和删除等操作:使用FastDFS client API,目前提供了C、PHP extension和Java的client API
文件下载采用HTTP方式:使用nginx或者apache扩展模块,不推荐使用FastDFS内置的web server
不要做RAID,直接挂载单盘,每个硬盘作为一个mount point
最大并发连接数设置
参数名:max_connections
缺省值:256
说明:FastDFS采用预先分配好buffer队列的做法,分配的内存大小为: max_connections * buff_size,因此配置的连接数越大,消耗的内存越多。不建议配置得过大,以避免无谓的内存开销
工作线程数设置
参数名: work_threads
缺省值:4
说明:为了避免CPU上下文切换的开销,以及不必要的资源消耗,不建议将本参数设置得过大。为了发挥出多个CPU的效能,系统中的线程数总和,应等于CPU总数。
对于tracker server,公式为:
work_threads + 1 = CPU数
对于storage,公式为:
work_threads + 1 + (disk_reader_threads + disk_writer_threads) * store_path_count = CPU数
storage目录数设置
参数名:subdir_count_per_path
缺省值:256
说明:FastDFS采用二级目录的做法,目录会在FastDFS初始化时自动创建。存储海量小文件,打开了trunk存储方式的情况下,建议将本参数适当改小,比如设置为32,此时存放文件的目录数为 32 * 32 = 1024。假如trunk文件大小采用缺省值64MB,磁盘空间为2TB,那么每个目录下存放的trunk文件数均值为:2TB / (1024 * 64MB) = 32个
storage磁盘读写线程设置
disk_rw_separated:磁盘读写是否分离
disk_reader_threads:单个磁盘读线程数
disk_writer_threads:单个磁盘写线程数
如果磁盘读写混合,单个磁盘读写线程数为读线程数和写线程数之后
对于单盘挂载方式,磁盘读写线程分别设置为1即可
如果磁盘做了RAID,那么需要酌情加大读写线程数,这样才能最大程度地发挥磁盘性能
storage同步延迟相关设置
sync_binlog_buff_interval:将binlog buffer写入磁盘的时间间隔,取值大于0,缺省值为60s
sync_wait_msec:如果没有需要同步的文件,对binlog进行轮询的时间间隔,取值大于0,缺省值为100ms
sync_interval:同步完一个文件后,休眠的毫秒数,缺省值为0
为了缩短文件同步时间,可以将上述3个参数适当调小即可