fastDFS的配置
1、配置及启动Tracker Server
A、修改%FastDFS%/conf/tracker.conf文件,修改如下
#可以自己指定目录位置,但目录必须存在,用于存储日志及storage server等信息,否则tracker server无法启动
- base_path=/home/yuqing/fastdfs -> base_path=/home/soar/fastdfs_tracker
#改成你想要的http端口,将来http下载文件的端口就是他了
- http.server_port=8080 -> http.server_port=8090
#http支持
- ##include http.conf -> #include http.conf
#默认4GB,如果空间不足,建议调小,否则会报no free space的异常,无法正常启动
- reserved_storage_space = 4GB -> reserved_storage_space = 1GB
#tracker server对storage server供服务的端口,使用默认的即可,也可以自定义
- port=22122
B、将http.conf文件拷贝到/etc/fdfs目录下,执行
- sudo cp %FastDFS%/conf/http.conf /etc/fdfs/
注:为了支持http,必须将这个文件拷贝到此目录,否则无法启动,报param http.XXX not exist or is empty类似的错误
C、进入/usr/local/bin/目录,启动tracker服务器,执行
- sudo fdfs_trackerd %FastDFS%/conf/tracker.conf
注:在执行此过程中或许会报错:
fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
解决办法:
原因一般有两个, 一个是操作系统里确实没有包含该共享库(lib*.so.*文件)或者共享库版本不对, 遇到这种情况那就去网上下载并安装上即可.
另外一个原因就是已经安装了该共享库, 但执行需要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.
所以安装共享库后要注意共享库路径设置问题, 如下:
1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下, 搜索出可共享的动态链接库(格式如lib*.so*), 进而创建出动态装入程序(ld.so)所需的连接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态链接库名字列表.
2) 如果共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
3) 如果共享库文件安装到了其它"非/lib或/usr/lib" 目录下, 但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH, 然后运行程序的时候就会去这个目录中找共享库.
LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到共享库. 可以设置多个搜索目录, 这些目录之间用冒号分隔开. 比如安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则可以在.bashrc或.bash_profile或shell里加入以下语句即可:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.
4)如果程序需要的库文件比系统目前存在的村文件版本低,可以做一个链接
比如:
error while loading shared libraries: libncurses.so.4: cannot open shared
object file: No such file or directory
ls /usr/lib/libncu*
/usr/lib/libncurses.a /usr/lib/libncurses.so.5
/usr/lib/libncurses.so /usr/lib/libncurses.so.5.3
可见虽然没有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
建一个链接就好了
ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4
使用whereis libevent
找寻libevent的安装目录,我发现我的是默认在usr/local下面,我采用第二种方法得到了解决。
D、进入/home/soar/fastdfs_tracker/logs/trackerd.log查看tracker的启动日志,如果看到类似
- [2010-11-04 16:21:25] INFO - FastDFS v2.02, base_path=/home/soar/fastdfs_tracker, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=4MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s
- [2010-11-04 16:21:25] INFO - HTTP supported: server_port=8090, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, check_active_interval=30, check_active_type=tcp, check_active_uri=/status.html
恭喜你,tracker server已经启动成功!
2、配置及启动Storage Server
A、修改%FastDFS%/conf/storage.conf文件,修改如下:
#可以自定义,但必须存在此目录,用于存储storage相关的log、group内的相关信息
- base_path=/home/yuqing/fastdfs -> /home/soar/fastdfs_storge
#文件的存储位置,在一台storage server上可以指定多个存储位置
- store_path0=/home/yuqing/fastdfs -> store_path0=/home/soar/fastdfs_storge
#必须指定
- group_name=group1
#修改成tracker server的IP和端口信息
- tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122
#http支持
- ##include http.conf ->#include http.conf
B、进入/usr/local/bin/目录,启动storage服务器,执行
- sudo fdfs_storaged %FastDFS%/conf/storage.conf
C、进入/home/soar/fastdfs_tracker/logs/storage.log查看storage服务器启动日志,如果看到类似
- [2010-11-04 16:37:16] INFO - FastDFS v2.02, base_path=/home/soar/fastdfs_storge, store_path_count=1, subdir_count_per_path=256, group_name=group1, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=200ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=60s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=
- [2010-11-04 16:37:16] INFO - HTTP supported: server_port=8888, http_trunk_size=262144, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0
- [2010-11-04 16:37:16] INFO - file: storage_param_getter.c, line: 48, storage_ip_changed_auto_adjust=1
- [2010-11-04 16:37:19] INFO - file: tracker_client_thread.c, line: 274, successfully connect to tracker server 10.0.2.15:22122, as a tracker client, my ip is 10.0.2.15
恭喜你,storage server已经启动成功!
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=/opt/fdfs
#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