最新1 CentOS 6下FastDFS实现分布式文件系统_ngx_fastdfs_module(1),面试总结+详细解答

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

2、修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉。
在这里插入图片描述
3、对nginx重新config,添加Fastdfs-nginx-module:

mkdir -p /var/temp/nginx

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/root/fastdfs-nginx-module/src # 指定自己的路径

make
make install

4、把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下,进行编辑:
在这里插入图片描述
5、nginx的配置

server {
        listen       80;
        server_name  192.168.101.3;
    location /group1/M00/{
            ngx_fastdfs_module;
    }
}

6、将libfdfsclient.so拷贝至/usr/lib下:

cp /usr/lib64/libfdfsclient.so /usr/lib/

7、启动nginx。
在这里插入图片描述

测试http服务是否成功

1、上传图片:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/anti-steal.jpg

在这里插入图片描述
2、访问命令行输出网址:http://192.168.74.129/group1/M00/00/00/wKhKgVslH5GAKcLdAAB1_3EXRGc833_big.png
在这里插入图片描述
3、如果不行,检查22122和23000端口防火墙是否关闭,或者临时关闭防火墙:

service iptables stop  # 临时关闭防火墙

Java使用FastDFS

官方提供一个jar包:fastdfs_client_v1.20.jar。如果使用maven管理,可以添加:

<!-- https://mvnrepository.com/artifact/net.oschina.zcx7878/fastdfs-client-java -->
<dependency>
    <groupId>net.oschina.zcx7878</groupId>
    <artifactId>fastdfs-client-java</artifactId>
    <version>1.27.0.0</version>
</dependency>

使用方法:

1、把FastDFS提供的jar包添加到工程中
2、初始化全局配置。加载一个配置文件。
3、创建一个TrackerClient对象。
4、通过TrackerClient获得一个TrackerServer对象。
5、声明一个StorageServer对象,null。
6、通过TrackerServer对象和StorageServer对象获得一个StorageClient对象。
7、直接调用StorageClient对象方法上传文件即可。
创建配置文件client.conf:

tracker_server=192.168.74.129:22122

测试Java代码:

public class FastdfsTest {

    @Test
    public void testUpload() throws IOException, MyException {
        ClientGlobal.init("E:\\Intelljidea\\taotao\\taotao-manager\\taotao-manager-web\\src\\main\\resources\\properties\\client.conf");

        TrackerClient trackerClient = new TrackerClient();
        TrackerServer trackerServer = trackerClient.getConnection();

        StorageServer storageServer = null;
        StorageClient storageClient = new StorageClient(trackerServer, storageServer);

        String[] strings = storageClient.upload\_file("C:\\Users\\os\\Pictures\\十分妹子.jpg", "jpg", null);
        for (String string : strings) {
            System.out.println(string);
        }
    }
}

测试结果:
在这里插入图片描述

FastDFS工具类:FastDFSClient.java

import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;

public class FastDFSClient {

    private TrackerClient trackerClient = null;
    private TrackerServer trackerServer = null;
    private StorageServer storageServer = null;
    private StorageClient1 storageClient = null;

    public FastDFSClient(String conf) throws Exception {
        if (conf.contains("classpath:")) {
            conf = conf.replace("classpath:", this.getClass().getResource("/").getPath());
        }
        ClientGlobal.init(conf);
        trackerClient = new TrackerClient();
        trackerServer = trackerClient.getConnection();
        storageServer = null;
        storageClient = new StorageClient1(trackerServer, storageServer);
    }

    /\*\*
 \* 上传文件方法
 \* <p>Title: uploadFile</p>
 \* <p>Description: </p>
 \* @param fileName 文件全路径
 \* @param extName 文件扩展名,不包含(.)
 \* @param metas 文件扩展信息
 \* @return
 \* @throws Exception
 \*/
    public String uploadFile(String fileName, String extName, NameValuePair[] metas) throws Exception {
        String result = storageClient.upload\_file1(fileName, extName, metas);
        return result;
    }

    public String uploadFile(String fileName) throws Exception {
        return uploadFile(fileName, null, null);
    }

    public String uploadFile(String fileName, String extName) throws Exception {
        return uploadFile(fileName, extName, null);
    }

    /\*\*
 \* 上传文件方法
 \* <p>Title: uploadFile</p>
 \* <p>Description: </p>
 \* @param fileContent 文件的内容,字节数组
 \* @param extName 文件扩展名
 \* @param metas 文件扩展信息
 \* @return
 \* @throws Exception
 \*/
    public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas) throws Exception {

        String result = storageClient.upload\_file1(fileContent, extName, metas);
        return result;
    }

    public String uploadFile(byte[] fileContent) throws Exception {
        return uploadFile(fileContent, null, null);
    }

    public String uploadFile(byte[] fileContent, String extName) throws Exception {
        return uploadFile(fileContent, extName, null);
    }
}

参考链接 :

FastDFS实现分布式文件系统 :https://mp.weixin.qq.com/s/vDqYAuI1iqfGFw_LbLJlQg

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。*

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 21
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值