zoukankan      html  css  js  c++  java
  • Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第十二集之FastDFS的使用】

    (自己的项目路径)相关项目在web部分中priv.lirenhe.fastdfs


    官方提供一个fastdfs开发项目,下载下来maven install

    以下内容是借鉴网上的一篇文章,但是不知道网址了,如果侵权了,望告知。

    使用方法:

    1、FastDFS提供的项目maven install

    2、初始化全局配置。加载一个配置文件。

    3、创建一个TrackerClient对象。

    4、创建一个TrackerServer对象。

    5、声明一个StorageServer对象,null

    6、获得StorageClient对象。

    7、直接调用StorageClient对象方法上传文件即可。

    @Test

    public void testUpload() throws Exception {

    // 1、把FastDFS提供的jar包添加到工程中

    // 2、初始化全局配置。加载一个配置文件。

    ClientGlobal.init("D:\workspaces-itcast\JaveEE18\taotao-manager\taotao-manager-web\src\main\resources\properties\client.conf");

    // 3、创建一个TrackerClient对象。

    TrackerClient trackerClient = new TrackerClient();

    // 4、创建一个TrackerServer对象。

    TrackerServer trackerServer = trackerClient.getConnection();

    // 5、声明一个StorageServer对象,null。

    StorageServer storageServer = null;

    // 6、获得StorageClient对象。

    StorageClient storageClient = new StorageClient(trackerServer, storageServer);

    // 7、直接调用StorageClient对象方法上传文件即可。

    String[] strings = storageClient.upload_file("D:\Documents\Pictures\images\2f2eb938943d.jpg", "jpg", null);

    for (String string : strings) {

    System.out.println(string);

    }

    }


    Client.conf

    tracker_server=192.168.25.133:22122


    以下是自己遇到的问题以及解决办法。

    由于没有打开# the storage server port导致连接超时。解决方法如下:

    https://www.cnblogs.com/nbf-156cwl/articles/FastDFS.html

    https://blog.csdn.net/jsflzhong/article/details/51647481

    1.查看打开的端口:

    #/etc/init.d/iptables status

    可以知道23000,也就是storage server port没有打开,被防火墙拦截。修改:/etc/sysconfig/iptables文件,详细如下增加命令:

    -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

    然后重启:service iptables restart


    开发需要在linux中启动的服务:

    启动tracker/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

    启动tracker  /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

    启动测试    [root@localhost /etc/fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

    启动nginx   /usr/local/nginx/sbin/nginx -s reload

    1.1 使用工具类上传图片

    @Test

    public void testFastDfsClient() throws Exception {

    FastDFSClient client = new FastDFSClient("D:\workspaces-itcast\JaveEE18\taotao-manager\taotao-manager-web\src\main\resources\properties\client.conf");

    String uploadFile = client.uploadFile("D:\Documents\Pictures\images\200811281555127886.jpg", "jpg");

    System.out.println(uploadFile);

    }

    工具类在以下链接中。

    fastdfs开发完整样例和开发包链接:https://download.csdn.net/download/mark_lirenhe/10484666

  • 相关阅读:
    leetcode 309. Best Time to Buy and Sell Stock with Cooldown
    leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee
    leetcode 32. Longest Valid Parentheses
    leetcode 224. Basic Calculator
    leetcode 540. Single Element in a Sorted Array
    leetcode 109. Convert Sorted List to Binary Search Tree
    leetcode 3. Longest Substring Without Repeating Characters
    leetcode 84. Largest Rectangle in Histogram
    leetcode 338. Counting Bits
    git教程之回到过去,版本对比
  • 原文地址:https://www.cnblogs.com/lirenhe/p/9774476.html
Copyright © 2011-2022 走看看