分布式文件系统 - FastDFS 在UBUNTU下安装

本文记录了在Ubuntu系统中安装分布式文件系统FastDFS的过程,包括启动和关闭FastDFS服务的特殊方法,解决启动nginx时的依赖问题,以及配置Nginx模块和上传测试遇到的权限和404错误。通过修改配置文件和调整防火墙规则,最终成功实现FastDFS与Nginx的整合并能正常访问文件。
摘要由CSDN通过智能技术生成

分布式文件系统 - FastDFS 在 CentOS 下配置安装部署

按照该博主的介绍,大部分安装操作正常,只是在创建软连接的时候报错。

所以只好用笨办法启动和关闭:

启动tracker:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

启动storage:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

关闭  stop    重启  restart。

查看启动状态:

root@VM-0-17-ubuntu:/usr/local/bin# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2018-04-22 14:58:14] 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 111.231.73.14:22122

group count: 1

Group 1:
group name = group1
disk total space = 50267 MB
disk free space = 44322 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 = 111.231.73.14
                ip_addr = 111.231.73.14  ACTIVE
                http domain =
                version = 5.05
                join time = 2018-04-22 14:57:29
                up time = 2018-04-22 14:57:29
                total storage = 50267 MB
                free storage = 44322 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 = 1
                connection.max_count = 1
                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 = 2018-04-22 14:58:07
                last_source_update = 1970-01-01 08:00:00
                last_sync_update = 1970-01-01 08:00:00

测试,上传一个图片:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/apache-tomcat-8.5.28/webapps/myinvoice/11.jpg

上传结果:

 http://111.231.73.14/group1/M00/00/00/rBEAEVrcMrGAAWbeAAEK0T_vltA970_big.jpg

然后是安装nginx,分布式文件系统 - FastDFS 配置 Nginx 模块及上传测试

有几处需要注意的地方:

1.下载fastdfs-nginx-module,按照博主的方式下载下来在make 操作nginx时报错:所以我下了linux版本的压缩包,

    https://download.csdn.net/download/zgf19930504/9574275,在解压缩之后,记得要修改(你的保存路径)/src下的config文件内容为:

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

2.在启动nginx时报错:/usr/local/nginx/sbin/nginx: error while loading shared libraries: libfastcommon.so: cannot open shared object file: No such file or directory.

可以创建软连接http://blog.itpub.net/7734666/viewspace-1292485/,或者直接拷贝/usr/lib64下的libfastcommon.so文件和

libfdfsclient.so文件到/usr/local/lib和/usr/lib目录下。然后再次启动nginx,如果现实PID则正常:

ngx_http_fastdfs_set pid=18468

可是我在访问nginx却打不开欢迎页。。。

找到nginx日志位置:

/usr/local/nginx/logs

查看错误日志:

fastdfs_process_init pid=24318
[2018-04-22 19:32:02] ERROR - file: shared_func.c, line: 960, open file /etc/fdfs/mod_fastdfs.conf fail, errno: 13, error info: Permission denied
[2018-04-22 19:32:02] ERROR - file: ../fastdfs-nginx-module/src//common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 13
2018/04/22 19:32:02 [alert] 24317#0: worker process 24318 exited with fatal code 2 and cannot be 

意思是说没有权限操作:/etc/fdfs/mod_fastdfs.conf

执行:

 chmod 777 mod_fastdfs.conf

重启nginx,可以正常登陆欢迎页!

nginx正常启动后,尝试保存图片:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/apache-tomcat-8.5.28/webapps/myinvoice/11.jpg

保存结果:

This is FastDFS client test program v5.05

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.

[2018-04-24 10:50:57] DEBUG - base_path=/data/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=111.231.73.14, port=23000

group_name=group1, ip_addr=111.231.73.14, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/rBEAEVrem5GAfYlSAAEK0T_vltA102.jpg
source ip address: 172.17.0.17
file timestamp=2018-04-24 10:50:57
file size=68305
file crc32=1072666320
example file url: http://111.231.73.14/group1/M00/00/00/rBEAEVrem5GAfYlSAAEK0T_vltA102.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/rBEAEVrem5GAfYlSAAEK0T_vltA102_big.jpg
source ip address: 172.17.0.17
file timestamp=2018-04-24 10:50:57
file size=68305
file crc32=1072666320
example file url: http://111.231.73.14/group1/M00/00/00/rBEAEVrem5GAfYlSAAEK0T_vltA102_big.jpg

但是在浏览器上打开生成的url,报404.。。

找到nginx的日志:

/usr/local/nginx/logs

发现错误原因为:

ERROR - file: ../fastdfs-nginx-module/src//common.c, line: 877, 
stat file: /data/fastdfs/storage/data/00/00/rBEAEVrdUnmAf3GgAAEK0T_vltA352_big.jpg fail,
 errno: 13, error info: Permission denied

解决方式:

找到nginx的安装路径:

/usr/local/nginx/conf

修改nginx.conf,在开始位置加上:

user root;

保存,重启nginx,再次访问url地址,可以正常访问!

如果是在云服务器上测试,在安全组内把80,22122,23000,9000这些端口都要打开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值