`
bwhzhl
  • 浏览: 100430 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

FastDFS简单的配置实现

 
阅读更多

1.libevent库安装

 

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.14-stable.tar.gz  
tar -zxvf libevent-2.0.14-stable.tar.gz   
cd libevent-2.0.14-stable  
./configure --prefix=/usr/local/libevent-2.0.14  
make && make install 

2.FastDFS安装

 

wget http://fastdfs.googlecode.com/files/FastDFS_v3.02.tar.gz  
tar -zxvf FastDFS_v3.02.tar.gz   
cd FastDFS  
vim make.sh
grep -A 4 '/usr/local/FastDFS' make.sh    #修改如下

TARGET_PREFIX=/usr/local/FastDFS  
TARGET_CONF_PATH=/etc/fdfs  
WITH_HTTPD=1 
WITH_LINUX_SERVICE=1 

./make.sh C_INCLUDE_PATH=/usr/local/libevent-2.0.14/include  LIBRARY_PATH=/usr/local/libevent-2.0.14/lib
./make.sh install  
ls /etc/fdfs/  
client.conf  http.conf  mime.types  storage.conf  tracker.conf 

 

3.修改相关文件

 

 echo '/usr/local/libevent-2.0.14/include/' >> /etc/ld.so.conf  
 echo '/usr/local/libevent-2.0.14/lib/' >> /etc/ld.so.conf  
 ldconfig 
mkdir -p /home/data/fastdfs 

 

注:3台服务器都如上操作

 

4.tracker节点安装

修改

/etc/fdfs/tracker.conf

如下配置

[root@DFS1 fdfs]# grep -v '^#' /etc/fdfs/tracker.conf |grep -v '^$'
disabled=false
bind_addr=192.168.1.201
port=22122
connect_timeout=30
network_timeout=60
base_path=/home/data/fastdfs
max_connections=256
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 4GB
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
http.disabled=false
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
http.need_find_content_type=true

 修改

/etc/fdfs/http.conf

如下配置

[root@DFS1 fdfs]# grep -v '^#' /etc/fdfs/http.conf |grep -v '^$'       
http.default_content_type = application/octet-stream
http.mime_types_filename=mime.types
http.anti_steal.check_token=false
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=FastDFS1234567890
http.anti_steal.token_check_fail=/home/data/fastdfs/conf/anti-steal.jpg

启动:

/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf  

 echo $?

 22

[root@DFS1 fdfs]# cat /home/data/fastdfs/logs/trackerd.log 
[2012-11-21 13:55:08] ERROR - file: ../common/fdfs_http_shared.c, line: 128, param "http.mime_types_filename" not exist or is empty
 

修改tracker.conf

[root@DFS1 fdfs]# tail -3 /etc/fdfs/tracker.conf
#use "#include" directive to include http other settings
#include http.conf
 
[root@DFS1 fdfs]# netstat -antp 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 192.168.1.201:22122         0.0.0.0:*                   LISTEN      8929/fdfs_trackerd  
tcp        0      0 192.168.1.201:8080          0.0.0.0:*                   LISTEN      8929/fdfs_trackerd  
 

4.storage节点安装

修改

 /etc/fdfs/storage.conf 

如下配置

[root@DFS2 fdfs]# grep -v '^#' /etc/fdfs/storage.conf |grep -v '^$'            
disabled=false
group_name=group1
bind_addr=192.168.1.202
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/home/data/fastdfs
max_connections=256
buff_size = 256KB
work_threads=4
disk_rw_separated = true
disk_rw_direct = false
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=/home/data/fastdfs
subdir_count_per_path=256
tracker_server=192.168.1.201: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
key_namespace=FastDFS
keep_alive=0
http.disabled=false
http.domain_name=
http.server_port=8888
http.trunk_size=256KB
http.need_find_content_type=true
[root@DFS2 fdfs]# tail -n 3 /etc/fdfs/storage.conf 
#use "#include" directive to include HTTP other settings
#include http.conf
 

 

 

 

修改

/etc/fdfs/http.conf 

配置如下

[root@DFS2 fdfs]# grep -v '^#' /etc/fdfs/http.conf |grep -v '^$'
http.default_content_type = application/octet-stream
http.mime_types_filename=mime.types
http.anti_steal.check_token=false
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=FastDFS1234567890
http.anti_steal.token_check_fail=/home/data/fastdfs/conf/anti-steal.jpg

 启动:

 /usr/local/FastDFS/bin/fdfs_storaged  /etc/fdfs/storage.conf 

 

[root@DFS2 fdfs]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 192.168.1.202:8888          0.0.0.0:*                   LISTEN      7861/fdfs_storaged  
tcp        0      0 192.168.1.202:23000         0.0.0.0:*                   LISTEN      7861/fdfs_storaged  
 

 

 

5.client配置测试

修改

/etc/fdfs/client.conf

配置如下

[root@DFS3 fastdfs]# grep -v '^#' '/etc/fdfs/client.conf' |grep  -v '^$'
connect_timeout=30
network_timeout=60
base_path=/home/data/fastdfs
tracker_server=192.168.1.201:22122
log_level=info
http.tracker_server_port=8080
 

测试上传

[root@DFS3 fastdfs]# /usr/local/FastDFS/bin/fdfs_test /etc/fdfs/client.conf  upload  /root/FastDFS_v3.02.tar.gz 
This is FastDFS client test program v3.02

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.

[2012-11-21 15:04:37] INFO - base_path=/home/data/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=group1, ip_addr=192.168.1.202, port=23000

group_name=group1, ip_addr=192.168.1.202, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBylCsfQbXgHCzAAU-MoCNswU.tar.gz
source ip address: 192.168.1.202
file timestamp=2012-11-21 15:04:38
file size=343602
file crc32=2156770053
file url: http://192.168.1.201:8080/group1/M00/00/00/wKgBylCsfQbXgHCzAAU-MoCNswU.tar.gz
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBylCsfQbXgHCzAAU-MoCNswU_big.tar.gz
source ip address: 192.168.1.202
file timestamp=2012-11-21 15:04:38
file size=343602
file crc32=2156770053
file url: http://192.168.1.201:8080/group1/M00/00/00/wKgBylCsfQbXgHCzAAU-MoCNswU_big.tar.gz

 

 

 

6.其他:

 tracker.conf 配置文件分析

tracker.conf这个配置文件是否生效,因为在启动fastdfs服务端进程时需要指定配置文件,所以需要使次配置文件生效。false是生效,true是屏蔽。
	
        disabled=false
	 
	#程序的监听地址,如果不设定则监听所有地址
	bind_addr=
	 
	#tracker监听的端口
	port=22122
	 
	#链接超时设定
	connect_timeout=30
	 
	#tracker在通过网络发送接收数据的超时时间
	network_timeout=60
	 
	#数据和日志的存放地点
	base_path=/opt/fdfs
	 
	#服务所支持的最大链接数
	max_connections=256
	 
	#工作线程数一般为cpu个数
	work_threads=4
	 
	#在存储文件时选择group的策略,0:轮训策略 1:指定某一个组 2:负载均衡,选择空闲空间最大的group
	store_lookup=2
	 
	#如果上面的store_lookup选择了1,则这里需要指定一个group
	#store_group=group2
	 
	#在group中的哪台storage做主storage,当一个文件上传到主storage后,就由这台机器同步文件到group内的其他storage上,0:轮训策略 1:根据ip地址排序,第一个 2:根据优先级排序,第一个
	store_server=0
	 
	#选择那个storage作为主下载服务器,0:轮训策略 1:主上传storage作为主下载服务器
	download_server=0
	 
	#选择文件上传到storage中的哪个(目录/挂载点),storage可以有多个存放文件的base path 0:轮训策略 2:负载均衡,选择空闲空间最大的
	store_path=0
	 
	#系统预留空间,当一个group中的任何storage的剩余空间小于定义的值,整个group就不能上传文件了
	reserved_storage_space = 4GB
	 
	#日志信息级别
	log_level=info
	 
	#进程以那个用户/用户组运行,不指定默认是当前用户
	run_by_group=
	run_by_user=
	 
	#允许那些机器连接tracker默认是所有机器
	allow_hosts=*
	 
	#设置日志信息刷新到disk的频率,默认10s
	sync_log_buff_interval = 10
	 
	#检测storage服务器的间隔时间,storage定期主动向tracker发送心跳,如果在指定的时间没收到信号,tracker人为storage故障,默认120s
	check_active_interval = 120
	 
	#线程栈的大小,最小64K
	thread_stack_size = 64KB
	 
	#storage的ip改变后服务端是否自动调整,storage进程重启时才自动调整
	storage_ip_changed_auto_adjust = true
	 
	#storage之间同步文件的最大延迟,默认1天
	storage_sync_file_max_delay = 86400
	 
	#同步一个文件所花费的最大时间
	storage_sync_file_max_time = 300
	 
	#是否用一个trunk文件存储多个小文件
	use_trunk_file = false
	 
	#最小的solt大小,应该小于4KB,默认256bytes
	slot_min_size = 256
	 
	#最大的solt大小,如果上传的文件小于默认值,则上传文件被放入trunk文件中
	slot_max_size = 16MB
	 
	#trunk文件的默认大小,应该大于4M
	trunk_file_size = 64MB
	 
	#http服务是否生效,默认不生效
	http.disabled=false
	 
	#http服务端口
	http.server_port=8080
	 
	#检测storage上http服务的时间间隔,<=0表示不检测
	http.check_alive_interval=30
	 
	#检测storage上http服务时所用请求的类型,tcp只检测是否可以连接,http必须返回200
	http.check_alive_type=tcp
	 
	#通过url检测storage http服务状态
	http.check_alive_uri=/status.html
	 
	#if need find content type from file extension name
	http.need_find_content_type=true
	 
	#用include包含进http的其他设置
	##include http.conf
 

 

 

 

storage.conf配置文件分析

	#同tracker.conf
	disabled=false
	 
	#这个storage服务器属于那个group
	group_name=group1
	 
	#同tracker.conf
	bind_addr=
	 
	#连接其他服务器时是否绑定地址,bind_addr配置时本参数才有效
	client_bind=true
	 
	#同tracker.conf
	port=23000
	connect_timeout=30
	network_timeout=60
	 
	#主动向tracker发送心跳检测的时间间隔
	heart_beat_interval=30
	 
	#主动向tracker发送磁盘使用率的时间间隔
	stat_report_interval=60
	 
	#同tracker.conf
	base_path=/opt/fdfs
	max_connections=256
	 
	#接收/发送数据的buff大小,必须大于8KB
	buff_size = 256KB
	 
	#同tracker.conf
	work_threads=4
	 
	#磁盘IO是否读写分离
	disk_rw_separated = true
	 
	#是否直接读写文件,默认关闭
	disk_rw_direct = false
	 
	#混合读写时的读写线程数
	disk_reader_threads = 1
	disk_writer_threads = 1
	 
	#同步文件时如果binlog没有要同步的文件,则延迟多少毫秒后重新读取,0表示不延迟
	sync_wait_msec=50
	 
	#同步完一个文件后间隔多少毫秒同步下一个文件,0表示不休息直接同步
	sync_interval=0
	 
	#表示这段时间内同步文件
	sync_start_time=00:00
	sync_end_time=23:59
	 
	#同步完多少文件后写mark标记
	write_mark_file_freq=500
	 
	#storage在存储文件时支持多路径,默认只设置一个
	store_path_count=1
	 
	#配置多个store_path路径,从0开始,如果store_path0不存在,则base_path必须存在
	store_path0=/home/data/
	#store_path1=/opt/fastdfs2
	 
	#subdir_count  * subdir_count个目录会在store_path下创建,采用两级存储
	subdir_count_per_path=256
	 
	#设置tracker_server
	tracker_server=x.x.x.x:22122
	 
	#同tracker.conf
	log_level=info
	run_by_group=
	run_by_user=
	allow_hosts=*
	 
	#文件在数据目录下的存放策略,0:轮训 1:随机
	file_distribute_path_mode=0
	 
	#当问及是轮训存放时,一个目录下可存放的文件数目
	file_distribute_rotate_count=100
	 
	#写入多少字节后就开始同步,0表示不同步
	fsync_after_written_bytes=0
	 
	#刷新日志信息到disk的间隔
	sync_log_buff_interval=10
	 
	#同步storage的状态信息到disk的间隔
	sync_stat_file_interval=300
	 
	#线程栈大小
	thread_stack_size=512KB
	 
	#设置文件上传服务器的优先级,值越小越高
	upload_priority=10
	 
	#是否检测文件重复存在,1:检测 0:不检测
	check_file_duplicate=0
	 
	#当check_file_duplicate设置为1时,次值必须设置
	key_namespace=FastDFS
	 
	#与FastDHT建立连接的方式 0:短连接 1:长连接
	keep_alive=0
	 
	#同tracker.conf
	http.disabled=false
	http.domain_name=
	http.server_port=8888
	http.trunk_size=256KB
	http.need_find_content_type=true
	##include http.conf
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    go-fastdfs分布式文件系统-其他

    确认OK再一键迁移)支持token下载 token=md5(file_md5+timestamp)运维简单,只有一个角色(不像fastdfs有三个角色Tracker Server,Storage Server,Client),配置自动生成每个节点对等(简化运维)所有节点都可以...

    nginx跨域配置

    介绍如何配置nginx实现跨域,简单明了,很方便。需要的自行下载

    基于MateCloud的Springboot版本,更加轻量级,前端共用artemis+源代码+文档说明

    是一个基于SpringBoot3的快速开发平台,...3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

    go-dfs:一款易用的分布式文件系统,免费,开源

    storage2项目说明本项目参考fastdfs逻辑进行简单实现,主要功能包括:文件上传临时文件上传文件删除文件下载文件多副本同步保存和删除跟踪器自动容量均衡到不同的存储组临时文件上传功能,需要二次确认,否则会被...

    FileStation:简单的文件集中存储服务(双机备份)

    实现思路:参照淘宝FastDFS 文件集中服务器管理,解决应用端为了负载均衡多机部署带来文件存储问题,集中文件IO 协议:文件上传使用html表单上传协议 上传:web可以flash跨域直接上传文件,后台可以通过SDK上传文件 ...

    黑马品优购项目

    图片存储:fastDFS集群 网页静态化:freemarker 单点登录:cas 权限管理:SpringSecurity, 跨域:cros 支付:微信扫描 短信验证:阿里大于 密码加密:BCrypt 富文本:KindEditor 事务:声明式事务 任务调度:spring...

    jeesuite-libs-其他

    包括缓存(一二级缓存、自动缓存管理)、队列、分布式定时任务、文件服务(七牛、阿里云OSS、fastDFS)、日志、搜索、代码生成、API网关、配置中心、统一认证平台、分布式锁、分布式事务、集成dubbo、spring boot支持、...

    乐优商城.xmind

    实现非常简单 gateway网关中编写一个配置类 GlobalCorsConfig 添加CORS配置信息 允许的域,不要写*,否则cookie就无法使用了 是否发送Cookie信息 允许的请求方式 允许的头信息 有效时长 添加映射路径,我们...

    单点登录源码

    FastDFS | 分布式文件系统 | [https://github.com/happyfish100/fastdfs](https://github.com/happyfish100/fastdfs) Log4J | 日志组件 | [http://logging.apache.org/log4j/1.2/]...

Global site tag (gtag.js) - Google Analytics