最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何使用 docker compose 搭建 fastDFS文件服務(wù)器

 更新時(shí)間:2021年10月15日 10:26:28   作者:edoclin  
這篇文章主要介紹了如何使用 docker compose 搭建 fastDFS文件服務(wù)器,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

上篇文章給大家介紹了使用docker compose安裝FastDfs文件服務(wù)器的實(shí)例詳解

今天給大家介紹如何使用 docker compose 搭建 fastDFS文件服務(wù)器,內(nèi)容詳情如下所示:

平臺(tái) :Mac M1

備注:關(guān)于 IP Address

關(guān)于 docker 的網(wǎng)絡(luò)模式,上述文中提到了 docker 的 Host 模式

如果啟動(dòng)容器的時(shí)候使用host模式,那么這個(gè)容器將不會(huì)獲得一個(gè)獨(dú)立的Network Namespace,而是和宿主機(jī)共用一個(gè) Network Namespace。容器將不會(huì)虛擬出自己的網(wǎng)卡,配置自己的 IP 等,而是使用宿主機(jī)的 IP 和端口。但是,容器的其他方面,如文件系統(tǒng)、進(jìn)程列表等還是和宿主機(jī)隔離的。

問(wèn)題在于:使用宿主機(jī)的 IP 和端口的話,配置文件中 IP 填寫(xiě) localhost的話按理說(shuō)能訪問(wèn)到容器,然而事實(shí)上卻不行。個(gè)人理解(如果理解有問(wèn)題的話煩請(qǐng)指正)的 IP Address填寫(xiě)方法如下:

啟動(dòng) tracker 時(shí)控制臺(tái)輸出:

192.168.64.2的網(wǎng)絡(luò)為:

 

192.168.65.4的網(wǎng)絡(luò)為:

文件目錄

├── docker-compose.yaml
├── nginx
│   └── nginx.conf
├── storage
│   └── data
└── tracker
│   └── conf
│       └── client.conf
└── store_path

./docker-compose.yaml

version: "2"
services:
	fastdfs-tracker:
		hostname: fastdfs-tracker
		container_name: fastdfs-tracker
		image: season/fastdfs:1.2
		network_mode: "host"
		command: tracker
		volumes:
		  - ./tracker/data:/fastdfs/tracker/data
		  - ./tracker/conf:/etc/fdfs
	fastdfs-storage:
		hostname: fastdfs-storage
		container_name: fastdfs-storage
		image: season/fastdfs:1.2
		network_mode: "host"
		volumes:
		  - ./storage/data:/fastdfs/storage/data
		  - ./store_path:/fastdfs/store_path
		environment:
		  - TRACKER_SERVER=192.168.64.2:22122
		command: storage
		depends_on:
		  - fastdfs-tracker
	fastdfs-nginx:
		hostname: fastdfs-nginx
		container_name: fastdfs-nginx
		image: season/fastdfs:1.2
		network_mode: "host"
		volumes:
		  - ./nginx/nginx.conf:/etc/nginx/conf/nginx.conf
		  - ./store_path:/fastdfs/store_path
		environment:
		  - TRACKER_SERVER=192.168.64.2:22122
		command: nginx

./tracker/conf/client.conf

# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=60

# the base path to store log files
base_path=/fastdfs/client

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# 需要修改此處 ip
tracker_server=192.168.64.2:22122

#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600

# if load FastDFS parameters from tracker server
# since V4.05
# default value is false
load_fdfs_parameters_from_tracker=false

# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V4.05
use_storage_id = false

# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V4.05
storage_ids_filename = storage_ids.conf

#HTTP settings
http.tracker_server_port=80

#use "#include" directive to include HTTP other settiongs
##include http.conf

./nginx/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
	worker_connections  1024;
}

http {
	include       mime.types;
	default_type  application/octet-stream;

	#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
	#                  '$status $body_bytes_sent "$http_referer" '
	#                  '"$http_user_agent" "$http_x_forwarded_for"';

	#access_log  logs/access.log  main;

	sendfile        on;
	#tcp_nopush     on;

	#keepalive_timeout  0;
	keepalive_timeout  65;

	#gzip  on;

	server {
		listen       9800;
		server_name  localhost;

		#charset koi8-r;

		#access_log  logs/host.access.log  main;

		# 修改部分
		location / {
			root /fastdfs/store_path/data;
			ngx_fastdfs_module;
		}

		#error_page  404              /404.html;

		# redirect server error pages to the static page /50x.html
		#
		error_page   500 502 503 504  /50x.html;
		location = /50x.html {
			root   html;
		}
	}
}

SpringBoot 集成 fastDFS

添加依賴

<dependency>
	<groupId>com.github.tobato</groupId>
	<artifactId>fastdfs-client</artifactId>
	<version>1.27.2</version>
</dependency>

 

applicaiton.yaml

# 分布式文件系統(tǒng)配置
fdfs:
  #根據(jù)自己的ip進(jìn)行更改
  ip: 192.168.64.2
  #socket連接超時(shí)時(shí)長(zhǎng)
  soTimeout: 1500
  connectTimeout: 600
  #支持多個(gè)
  trackerList:
    - ${fdfs.ip}:22122
  # fastDFS 中的 nginx 的 ip 和 port
  # IDEA 提示使用 https, 
  # nginx 配置 SSL 請(qǐng)移步:
  web-server-url: http://${fdfs.ip}:9800/

FastDFSConfig.java

@Configuration
// 導(dǎo)入FastDFS-Client組件
@Import(FdfsClientConfig.class)
// 解決jmx重復(fù)注冊(cè)bean的問(wèn)題
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public aspect FastDFSConfig {
}

FastDFSUtil.java

@Component
public class FastDFSUtil {
    @Resource
    private FastFileStorageClient fastFileStorageClient;
    @Resource
    private FdfsWebServer fdfsWebServer;

    public String uploadFile(MultipartFile file) throws IOException {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null);
        String fullPath = storePath.getFullPath();
        getResAccessUrl(fullPath);
        return fullPath;
    }

    public String uploadFile(File file) {
        try {
            FileInputStream inputStream = new FileInputStream(file);
            StorePath storePath = fastFileStorageClient.uploadFile(inputStream, file.length(), FilenameUtils.getExtension(file.getName()), null);
            return storePath.getFullPath();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public byte[] downloadFile(String filePath) {
        StorePath storePath = StorePath.parseFromUrl(filePath);
        return fastFileStorageClient.downloadFile(storePath.getGroup(), storePath.getPath(), new DownloadByteArray());
    }

    public Boolean deleteFile(String filePath) {
        if (StringUtils.isEmpty(filePath)) {
            return false;
        }
        try {
            StorePath storePath = StorePath.parseFromUrl(filePath);
            fastFileStorageClient.deleteFile(storePath.getGroup(), storePath.getPath());
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 封裝文件完整 URL 地址
     *
     * @param path
     * @return
     */
    public String getResAccessUrl(String path) {
        return fdfsWebServer.getWebServerUrl() + path;
    }
}

FastDFSController.java

@RestController
@RequestMapping("/fast-dfs")
public class FastDFSController {
    /**
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("")
    @Transactional
    public void uploadFile(MultipartFile file, String cuisineId) throws IOException {
        String s = fastDfsUtil.uploadFile(file);
        String resAccessUrl = fastDfsUtil.getResAccessUrl(s);
    }

    /**
     * @param response
     * @throws IOException
     */
    @GetMapping("")
    public void downloadFile(String filePath, HttpServletResponse response) throws IOException {
        byte[] bytes = fastDfsUtil.downloadFile(filePath);

        String[] split = filePath.split("/");
        String fileName = split[split.length - 1];
        // 設(shè)置強(qiáng)制下載不打開(kāi)
        response.setContentType("application/force-download");

        fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
        IOUtils.write(bytes, response.getOutputStream());
    }

    /**
     * 流媒體的方式播放視頻,只能從頭看到尾,不能手動(dòng)點(diǎn)擊重新看已經(jīng)看過(guò)的內(nèi)容
     * @param filePath
     * @param response
     * @throws IOException
     */
    @GetMapping("/play")
    public void streamMedia(String filePath, HttpServletResponse response) throws IOException {
        byte[] bytes = fastDfsUtil.downloadFile(filePath);
        IOUtils.copy(new ByteArrayInputStream(bytes), response.getOutputStream());
        response.flushBuffer();
    }
}

到此這篇關(guān)于如何使用 docker compose 搭建 fastDFS文件服務(wù)器的文章就介紹到這了,更多相關(guān)docker compose 搭建 fastDFS內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • docker下安裝Nginx的方法

    docker下安裝Nginx的方法

    這篇文章主要介紹了docker下安裝Nginx的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • 如何在Docker中設(shè)置容器間通信的權(quán)限和訪問(wèn)控制策略

    如何在Docker中設(shè)置容器間通信的權(quán)限和訪問(wèn)控制策略

    文章介紹了使用Docker網(wǎng)絡(luò)進(jìn)行訪問(wèn)控制的方法,包括自定義Bridge網(wǎng)絡(luò)、基于容器名稱(chēng)的訪問(wèn)控制和使用網(wǎng)絡(luò)策略(如Calico)進(jìn)行更精細(xì)的控制
    2024-11-11
  • Docker部署Kafka以及Spring Kafka實(shí)現(xiàn)

    Docker部署Kafka以及Spring Kafka實(shí)現(xiàn)

    這篇文章主要介紹了Docker部署Kafka以及Spring Kafka實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • Docker目錄遷移的實(shí)現(xiàn)示例

    Docker目錄遷移的實(shí)現(xiàn)示例

    Docker默認(rèn)目錄比較小,容器日志過(guò)多就會(huì)導(dǎo)致無(wú)法運(yùn)行,本文主要介紹了Docker目錄遷移的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-06-06
  • docker實(shí)現(xiàn)redis集群搭建的方法步驟

    docker實(shí)現(xiàn)redis集群搭建的方法步驟

    本文主要介紹了docker實(shí)現(xiàn)redis集群搭建的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Docker容器部署前端Vue服務(wù)(小白教程)

    Docker容器部署前端Vue服務(wù)(小白教程)

    本文主要介紹了Docker容器部署前端Vue服務(wù),文中根據(jù)實(shí)例編碼詳細(xì)介紹的十分詳盡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Docker本地目錄掛載的實(shí)現(xiàn)步驟

    Docker本地目錄掛載的實(shí)現(xiàn)步驟

    本文主要介紹了Docker本地目錄掛載的實(shí)現(xiàn)步驟
    2024-02-02
  • Docker stop停止/remove刪除所有容器

    Docker stop停止/remove刪除所有容器

    這篇文章主要介紹了Docker stop停止/remove刪除所有容器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • docker如何安裝mysql

    docker如何安裝mysql

    這篇文章主要介紹了docker如何安裝mysql,總結(jié)了安裝心得,幫助大家更好的使用docker鏡像,感興趣的朋友可以了解下
    2020-10-10
  • 淺談docker-compose網(wǎng)絡(luò)設(shè)置之networks

    淺談docker-compose網(wǎng)絡(luò)設(shè)置之networks

    這篇文章主要介紹了淺談docker-compose網(wǎng)絡(luò)設(shè)置之networks,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09

最新評(píng)論

栾城县| 连云港市| 呼和浩特市| 明水县| 永城市| 班玛县| 鹤岗市| 中方县| 宁城县| 嘉鱼县| 北碚区| 抚远县| 西和县| 惠水县| 吉林市| 长宁县| 西平县| 敦化市| 和顺县| 延长县| 资中县| 萝北县| 汉川市| 招远市| 威远县| 肃宁县| 宁武县| 类乌齐县| 蒲江县| 浪卡子县| 河津市| 新绛县| 福安市| 商丘市| 乐清市| 长岛县| 庄河市| 栾川县| 会泽县| 龙游县| 安顺市|