Linux服务器上使用docker配置FastDFS

1. 查找fastdfs容器

docker search fastdfs

2. 拉取镜像

docker pull ygqygq2/fastdfs-nginx

3. 环境

docker run -d --network=host --name tracker -v /usr/local/fdfs/tracker:/var/fdfs ygqygq2/fastdfs-nginx tracker
docker run -d --network=host --name storage0 -e TRACKER_SERVER=101.37.175.1:22122 -v /usr/local/fdfs/storage0:/var/fdfs ygqygq2/fastdfs-nginx storage

4. 开放端口

vim /usr/lib/firewalld/services/ssh.xml
	
	
systemctl restart firewalld

5. 在idea上做测试

5.1 导入依赖


        com.github.tobato
        fastdfs-client
        1.26.1-RELEASE

5.2 在主启动类添加注解

@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)

5.3 在测试启动类里

package com.qf.user_web;

import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.FileInputStream;

@SpringBootTest
class UserWebApplicationTests {

@Autowired
private FastFileStorageClient client;

@Test
public void testFastDFS() throws Exception {

    // 1. 准备要上传的文件
    File file = new File("E:\\ideaItemSet\\SpringDubbo\\1911_shop\\shop_web\\user_web\\src\\main\\resources\\static\\upload\\02.jpg");

    //2. 把文件转成一个流
    FileInputStream ips = new FileInputStream(file);

    //3. 把图片上传到fastDFS服务器
    StorePath storePath = client.uploadImageAndCrtThumbImage(ips,file.length(),"png",null);

    //4. 获取图片返回的路径
    System.out.println("storePath.getFullPath() = " + storePath.getFullPath());

}

}

5.4 关闭Linux上的tomcat

ps -ef | grep tomcat
kill -9 端口号    或者  docker stop mytomcat

5.5 更改LInux上的tomcat端口号 ,改为80

vim /usr/local/tomcat-8.5.50/conf/server.xml

在这里插入图片描述

5.6 进入storage0 容器,改端口号

docker exec -it storage0 /bin/bash
cd /usr/local/nginx/conf
cd /usr/local/nginx/conf/conf.d
vi storage.conf

5.7 启动Nginx

cd /usr/local/nginx/sbin
./nginx
ps -ef | grep nginx

5.8 查看图片在LInux哪个目录

按住Ctrl+P+Q退出容器
cd /usr/local/fdfs/storage0
cd /data/00/00

5.9 关闭防火墙

systemctl stop firewalld

你可能感兴趣的:(学习)