设为首页 加入收藏

TOP

详细的最新版fastdfs单机版搭建(三)
2019-09-17 18:19:36 】 浏览:98
Tags:详细 最新版 fastdfs 单机版 搭建
p;     base_path=/home/yuqing/fastdfs改为:base_path=/data/fastdfs

              store_path0=/home/yuqing/fastdfs改为:store_path0=/data/fastdfs/storage

              tracker_server=192.168.209.121:22122改为:tracker_server=192.168.1.207:22122,这个ip改成自己的

       创建storaged数据、日志目录

              [root@fastdfs2 fdfs]# mkdir -p /data/fastdfs/storage

       启动storaged

              [root@fastdfs2 fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

              查看storaged进程,如下图:

    说明storaged已经启动起来;其实也可以查看日志:/data/fastdfs/logs/storaged.log来判断storaged是否正常启动起来。

上传图片测试

       本地(win环境)安装fastdfs连接驱动

              从https://github.com/happyfish100/fastdfs-client-java下载源码,我下载的是zip包,解压后目录如下图:

    maven本地安装:mvn clean install

    

    当然也可以用ant构建:ant clean package

  书写测试代码

    代码结构如图

    fdfs_client_mine.conf:

connect_timeout = 2
network_timeout = 30
charset = UTF-8
http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890

tracker_server = 192.168.1.207:22122
View Code

              FastdfsClientTest.java

package com.lee.fastdfs.test;

import org.csource.common.Nameva luePair;
import org.csource.fastdfs.*;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;

public class FastdfsClientTest {

    //客户端配置文件
    public String conf_filename = "fdfs_client_mine.conf";
    //本地文件,要上传的文件
    public String local_filename = "G:\\IdeaProjects\\fastdfs\\src\\main\\resources\\mygirl.jpg";

    //上传文件
    @Test
    public void testUpload() {

        for(int i=0;i<10;i++){

            try {
                ClientGlobal.init(conf_filename);

                TrackerClient tracker = new TrackerClient();
                TrackerServer trackerServer = tracker.getConnection();
                StorageServer storageServer = null;

                StorageClient storageClient = new StorageClient(trackerServer,
                        storageServer);
                Nameva luePair nvp [] = new Nameva luePair[]{
                        new Nameva luePair("item_id", "100010"),
                        new Nameva luePair("width", "80"),
                        new Nameva luePair("height", "90")
                };
                String fileIds[] = storageClient.upload_file(local_filename, null,
                        nvp);

                System.out.println(fileIds.length);
                System.out.println("组名:" + fileIds[0]);
                System.out.println("路径: " + fileIds[1]);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
View Code

       上传图片:mygirl.jpg

           &nbs

首页 上一页 1 2 3 4 5 6 下一页 尾页 3/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇浅识微服务架构 下一篇领域驱动单元测试

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目