网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
1、修改配置/etc/fdfs/client.conf
2、启动测试
/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg
搭建nginx提供http服务
1、解压插件压缩包fastdfs-nginx-module_v1.16.tar.gz
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);
![img](https://img-blog.csdnimg.cn/img_convert/0e31d93f7c856cb0e323663f5c0d5fac.png)
![img](https://img-blog.csdnimg.cn/img_convert/cdb10a95676cdaf08c4ef77d161a1eed.png)
![img](https://img-blog.csdnimg.cn/img_convert/faab2009fb06c3417f5359bf5847d094.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
0e8sr-1715380642761)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**