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

转载于:https://www.cnblogs.com/lirenhe/p/9774476.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值