fastdfs实现文件服务器,FastDFS:配置 Nginx FastDFS实现文件服务器(四)

前面一节,我们成功将fastdfs安装,并且采用/application/fastdfs/bin/upload指定配置文件,进行上传文件。上传操作是在storage服务上进行的,tracker似乎还没有发挥其作用,与此同时,既然有上传,就一定要有访问,否则上传就显得并没有什么意义。接下来我们就看看是如何访问已经上传到storage服务上的文件。

fastdfs的作者已经为我们开发了一套与nginx服务结合的模块fastdfs-nginx-module(下载地址已在上一节中提供),提供nginx服务器访问的,并且nginx必须安装在storage服务器上才可以正常访问。所以接下来我们就采用nginx搭建,并访问fastdfs文件,如果有不了解nginx的同学,可以去查看我的nginx文章。

安装fastdfs-nginx-module

[root@storage tools]# tar -xf fastdfs-nginx-module-1.22.tar.gz

[root@storage tools]# cd fastdfs-nginx-module-1.22

[root@storage tools]# cp mod_fastdfs.conf /etc/fdfs/ ####将mod_fastdfs.conf拷贝到/etc/fdfs/下

[root@storage tools]# vim ./src/config

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then

ngx_module_type=HTTP

ngx_module_name=$ngx_addon_name

ngx_module_incs="/application/fastdfs/include" #####这里改为上一节中fastdfs的include文件夹

ngx_module_libs="-lfastcommon -lfdfsclient"

ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"

ngx_module_deps=

CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

. auto/module

else

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 /application/fastdfs/include" #####这里改为上一节中fastdfs的include文件夹

CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"

CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

安装Nginx(这里我就不讲了,自己去看我写的nginx安装)

在nginx配置过程中,需要添加一个模块--add-module=/application/tools/fastdfs-nginx-module-1.22/src

./configure --prefix=/application/nginx-1.16.1 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --add-module=/application/tools/fastdfs-nginx-module-1.22/src

如果编译过程中出现:/usr/bin/ld: cannot find -lfdfsclient

修改/etc/fdfs/mod_fastdfs.conf

[root@storage nginx-1.16.1]# vim /etc/fdfs/mod_fastdfs.conf

base_path=/application/fastdfs/tmp ###存放日志等信息

tracker_server=172.16.1.210:22122 ###配置tracker监听器

group_name=su ###group名称一致

url_have_group_name = true ####在url中显示组名

store_path0=/application/fastdfs/storage ####storagePath

修改/application/nginx/nginx.conf

[root@storage nginx-1.16.1]# vim conf/nginx.conf

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#access_log logs/access.log main;

sendfile on;

keepalive_timeout 65;

#gzip on;

server {

listen 8888;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location /su/M00 {

ngx_fastdfs_module;

}

}

}

启动Nginx

[root@storage ld.so.conf.d]# cd /application/nginx-1.16.1/

[root@storage nginx-1.16.1]# sbin/nginx

ngx_http_fastdfs_set pid=74973

[root@storage nginx-1.16.1]# ps -ef|grep nginx

root 74974 1 0 15:28 ? 00:00:00 nginx: master process sbin/nginx

www 74975 74974 0 15:28 ? 00:00:00 nginx: worker process

root 74977 1106 0 15:28 pts/1 00:00:00 grep --color=auto nginx

[root@storage nginx-1.16.1]#

###如果启动过程中出现:sbin/nginx: error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory

[root@storage nginx-1.16.1]# vim /etc/ld.so.conf.d/libfdfsclient.conf

/usr/local/lib/ ####libfdfsclient.so库文件的地址

[root@storage nginx-1.16.1]# ldconfig ##更新缓存

08bf39cc660e410fbb51b26f659c1f63.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值