前面一节,我们成功将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

那么:https://www.cnblogs.com/mswangblog/p/6624531.html

 

修改/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

则:https://blog.csdn.net/u014608280/article/details/80393097?utm_source=blogxgwz7

[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    ##更新缓存

 

 

访问测试
http://10.0.0.211:8888/su/M00/00/00/rBAB016dNaSAPIZ6AABO9_-mAZc640.jpg

最后修改于 2020-04-20 13:53:01
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇