分布式文件系统FastDFS安装与配置(单机)

安装包如下:
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v5.05.tar.gz
libfastcommon-master.zip
nginx-1.8.0.tar.gz

一、安装libfastcommon

FastDFS 5.05版本不再依赖libevent,而依赖于libfastcommon,因此需要先安装libfastcommon。
软件包下载地址:https://github.com/happyfish100/libfastcommon

# unzip libfastcommon-master.zip
# cd libfastcommon-master
# ./make.sh
# ./make.sh install

libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,因此需要设置软链接(如果已存在,可以忽略)。

# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

二、安装FastDFS

软件包下载地址:
1、https://sourceforge.net/projects/fastdfs/files/
2、https://code.google.com/archive/p/fastdfs/downloads
3、https://github.com/happyfish100/fastdfs

# tar zxf FastDFS_v5.05.tar.gz
# cd FastDFS
# ./make.sh
# ./make.sh install

安装完成后可以看到/etc/fdfs目录下生成了3个文件:

三、配置tracker节点

# mkdir /data/fastdfs  #创建tracker的数据文件和日志存储目录
# cd /etc/fdfs
# mv tracker.conf.sample tracker.conf 
# vim tracker.conf #修改的文件内容如下(基础配置,不考虑性能调优情况下):
base_path=/data/fastdfs  #设置 tracker 的数据文件和日志目录(需预先创建)
http.server_port=6666  #设置http端口号,默认为8080
# ln -s /usr/bin/fdfs_trackerd /usr/local/bin
# ln -s /usr/bin/stop.sh /usr/local/bin
# ln -s /usr/bin/restart.sh /usr/local/bin
# service fdfs_trackerd start  #启动tracker节点

启动成功后,在/data/fastdfs目录下生成了data和logs两个目录。
查看日志如下:

检查对应端口是否监听:

四、配置storage节点

# mkdir /data/fastdfs-storage  #创建
# cd /etc/fdfs/
# mv storage.conf.sample storage.conf
# vim storage.conf#修改的文件内容如下(基础配置,不考虑性能调优情况下):
group_name=group1   #组名,可根据实际情况修改
base_path=/data/fastdfs-storage #设置storage数据文件和日志目录,需预先创建
store_path_count=1  #存储路径个数,需要和 store_path 个数匹配、
store_path0=/data/fastdfs-storage #存储路径
tracker_server=192.168.116.145:22122 # #tracker 服务器的 IP地址和端口号,如果是单机搭建,IP不要写127.0.0.1,否则启动不成功。
http.server_port=8888  #设置 http 端口号

# ln -s /usr/bin/fdfs_storaged /usr/local/bin
# service fdfs_storaged start #启动storage,启动会根据配置文件的设置自动创建多级存储目录

查看日志,内容如下,表示启动正常:

# cat /data/fastdfs-storage/logs/storaged.log
[2016-03-31 11:49:35] INFO - FastDFS v5.05, base_path=/data/fastdfs-storage, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, accept_threads=1, 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=50ms, 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=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=hash, FDHT group count=0, FDHTserver count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=, use_access_log=0, rotate_access_log=0, access_log_rotate_time=00:00, rotate_error_log=0, 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=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
data path: /data/fastdfs-storage/data, mkdir sub dir...
mkdir data path: 00 ...
mkdir data path: 01 ...
mkdir data path: 02 ...
mkdir data path: 03 ...
。。。。。
data path: /data/fastdfs-storage/data, mkdir sub dir done.

确认启动成功后,可以运行 fdfs_monitor 查看 storage服务器是否已经登记到 tracker服务器。
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2016-03-31 11:54:36] DEBUG - base_path=/data/fastdfs-storage, 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

server_count=1, server_index=0

tracker server is 192.168.116.145:22122

group count: 1

Group 1:
group name = group1
disk total space = 201586 MB
disk free space = 190886 MB
trunk free space = 0 MB
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
current trunk file id = 0

     Storage 1:
          id = 192.168.116.145
          ip_addr = 192.168.116.145  ACTIVE
          http domain =
          version = 5.05
          join time = 2016-03-31 11:49:35
          up time = 2016-03-31 11:49:35
          total storage = 201586 MB
          free storage = 190886 MB
          upload priority = 10
          store_path_count = 1
          subdir_count_per_path = 256
          storage_port = 23000
          storage_http_port = 8888
          current_write_path = 0
          source storage id =
          if_trunk_server = 0
          connection.alloc_count = 256
          connection.current_count = 0
          connection.max_count = 0
          total_upload_count = 0
          success_upload_count = 0
          total_append_count = 0
          success_append_count = 0
          total_modify_count = 0
          success_modify_count = 0
          total_truncate_count = 0
          success_truncate_count = 0
          total_set_meta_count = 0
          success_set_meta_count = 0
          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 = 0
          success_upload_bytes = 0
          total_append_bytes = 0
          success_append_bytes = 0
          total_modify_bytes = 0
          success_modify_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 = 0
          success_file_open_count = 0
          total_file_read_count = 0
          success_file_read_count = 0
          total_file_write_count = 0
          success_file_write_count = 0
          last_heart_beat_time = 2016-03-31 11:54:35
          last_source_update = 1970-01-01 08:00:00
          last_sync_update = 1970-01-01 08:00:00
          last_synced_timestamp = 1970-01-01 08:00:00

看到“192.168.116.145  ACTIVE”即可确认 storage 运行正常。

五、给storage安装nginx并配置

主要目的是为了提供 http 的访问服务,同时解决 group 中 storage服务器的同步延迟问题。
nginx需要添加fastdfs-nginx-module模块。
下载地址:http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

# tar zxf fastdfs-nginx-module_v1.16.tar.gz
# tar zxf nginx-1.8.0.tar.gz
# cd nginx-1.8.0
# ./configure --prefix=/data/nginx --add-module=/data/soft/fastdfs-nginx-module/src
# make
# make install

make时报错如下:

.......
/data/soft/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:894: 错误:‘struct fdfs_http_context’没有名为‘if_modified_since’的成员
/data/soft/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:897: 错误:‘struct fdfs_http_context’没有名为‘if_modified_since’的成员
/data/soft/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:927: 错误:‘struct fdfs_http_context’没有名为‘range’的成员
/data/soft/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:933: 错误:‘struct fdfs_http_context’没有名为‘if_range’的成员
/data/soft/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:933: 错误:‘true’未声明(在此函数内第一次使用)
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 错误 1
make[1]: Leaving directory `/data/soft/nginx-1.8.0'
make: *** [build] 错误 2

解决办法:
执行以下2条命令,然后重新make

# ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
# ln -sv /usr/include/fastdfs /usr/local/include/fastdfs

拷贝相关文件到/etc/fdfs目录下:

# cp /data/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# cp /data/soft/FastDFS/conf/mime.types /etc/fdfs/
# cp /data/soft/FastDFS/conf/http.conf /etc/fdfs/
# cp /data/soft/FastDFS/conf/anti-steal.jpg /etc/fdfs/

修改nginx.conf的配置:

listen       9999;
location ~/group[1-3]/M00 {
            root /data/fastdfs-storage/data;
            ngx_fastdfs_module;
        }

修改/etc/fdfs/mod_fastdfs.conf的配置:

base_path=/data/fastdfs-storage  #保存日志目录
tracker_server=192.168.116.145:22122  #tracker 服务器的 IP 地址以及端口号
url_have_group_name = true #文件 url 中是否有 group 名
store_path0=/data/fastdfs-storage # 存储路径
http.need_find_content_type=true  # 从文件扩展名查找文件类型 (nginx 时 为true)
group_count = 3  #设置组的个数,事实上这次只使用了group1
在文件末添加如下内容:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage

[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs-storage

建立 M00 至存储目录的符号连接:

# ln -s /data/fastdfs-storage/data /data/fastdfs-storage/data/M00

启动nginx:

# /data/nginx/sbin/nginx

查看nginx的error日志,如果类似下以内容,表明配置成功:

六、给tracker安装nginx并配置

安装路径为:/data/nginx2
安装过程略。
nginx.conf配置如下:

upstream fdfs_group1 {
        server 127.0.0.1:9999;
    }

location /group1/M00 {
        proxy_pass http://fdfs_group1;
    }

启动nginx:

# /data/nginx2/sbin/nginx

配置客户端文件:

# cd /etc/fdfs/
# mv client.conf.sample client.conf  #修改内容如下:
base_path=/data/fastdfs-storage  #日志存放路径
tracker_server=192.168.116.145:22122  #tracker 服务器 IP 地址和端口号
http.tracker_server_port=6666  # tracker 服务器的 http 端口号,必须和tracker的设置对应起来

测试文件上传:

通过上图可以看到文件上传后存储的路径为:group1/M00/00/00/wKh0kVb8xZuAdQGUAAfp5oSKTdo388.jpg

通过nginx访问:

 

posted on 2016-04-11 14:33  K‘e0llm  阅读(13488)  评论(0编辑  收藏  举报

导航