Docker-Compose安装单机版FastDFS

小讲一下

FastDFS是一个开源的轻量级分布式文件系统,它具有高容错性、高吞吐量、高可扩展性等优点。它可以让用户通过简单的配置和命令就可以快速地搭建起一个高性能的分布式文件系统。FastDFS主要包含两个部分,即Tracker和Storage。

  1. Tracker主要是跟踪Storage状态,记录文件所存储的Storage服务器IP地址和文件路径等信息,同时提供文件上传、下载、删除等各种接口。
  2. Storage则是实际存储文件的地方,它通过Tracker来定位上传的文件并进行存储,同时提供文件下载、删除等各种接口,同时它们之间也可以相互备份。

FastDFS使用基于TCP/IP协议的二进制数据传输协议,能够保证高效稳定的传输。同时,它使用了较少的内存和CPU资源,支持海量数据的存储,并且提供了API供开发者进行二次开发。它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等

FastDFS搭建

1、创建需要的目录 mkdir -p /Users/fastdfs/tracker/data /Users/fastdfs/storage/data /Users/fastdfs/storage/store_path
2、编写 docker-compose.yml 文件
3、编写 nginx.conf 配置文件
4、编写 storage.conf 配置文件
最终的目录结构如下:
├─fastdfs
│ │docker-compose.yml
│ │nginx.conf
│ ├─storage
│ │ ├─data
│ │ storage.conf
│ │ ├─store_path
│ ├─tracker
│ │ ├─data
5、docker-compose up -d 运行容器

docker-compose.yml

version: "3"
services:
  fastdfs-tracker:
    hostname: fastdfs-tracker
    image: season/fastdfs:1.2
    container_name: fastdfs-tracker
    privileged: true
    restart: always
    volumes:
      - ./tracker/data:/fastdfs/tracker/data
    network_mode: "host"
    command: tracker
  fastdfs-storage:
    hostname: fastdfs-storage
    image: season/fastdfs:1.2
    container_name: fastdfs-storage
    privileged: true
    restart: always
    depends_on:
      - fastdfs-tracker
    volumes:
      - ./storage/storage.conf:/fdfs_conf/storage.conf
      - ./storage/data:/fastdfs/storage/data
      - ./storage/store_path:/fastdfs/store_path
    network_mode: "host"
    environment:
      - TRACKER_SERVER=192.168.X.XXX:22122
    command: storage
  fastdfs-nginx:
    hostname: fastdfs-storage
    image: season/fastdfs:1.2
    container_name: fastdfs-nginx
    privileged: true
    restart: always
    volumes:
      - ./nginx.conf:/etc/nginx/conf/nginx.conf
      - ./storage/store_path:/fastdfs/store_path
    depends_on:
      - fastdfs-storage
    network_mode: "host"
    environment:
      - TRACKER_SERVER=192.168.X.XXX:22122
    command: 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;
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    server {
        listen       8088;
        server_name  localhost;
        #charset koi8-r;
        #缩略图需要使用插件,需要单独构建nginx镜像,此处忽略
        #location /group([0-9])/M00/.*\.(gif|jpg|jpeg|png)$ {
        #   root /fastdfs/storage/data;
        #   image on;
        #   image_output off;         
        #   image_jpeg_quality 75;
        #   image_backend off;
        #   image_backend_server http://baidu.com/docs/aabbc.png;
        #}

        # group1
        location /group1/M00 {
        # 文件存储目录
            root /fastdfs/storage/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;
        }
        location = /favicon.ico {
        log_not_found off;
        access_log off;
        }
  }
}

storage.conf

#is this config file disabled
# false for enabled
# true for disabled
disabled=false

# the name of the group this storage server belongs to
group_name=group1

# bind an address of this host
# empty for bind all addresses of this host
bind_addr=

# if bind an address of this host when connect to other servers
# (this storage server as a client)
# true for binding the address configed by above parameter: "bind_addr"
# false for binding any address of this host
client_bind=true

# the storage server port
port=23000

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

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

# heart beat interval in seconds
heart_beat_interval=30

# disk usage report interval in seconds
stat_report_interval=60

# the base path to store data and log files
base_path=/fastdfs/storage

# max concurrent connections the server supported
# default value is 256
# more max_connections means more memory will be used
max_connections=256

# the buff size to recv / send data
# this parameter must more than 8KB
# default value is 64KB
# since V2.00
buff_size = 256KB

# accept thread count
# default value is 1
# since V4.07
accept_threads=1

# work thread count, should <= max_connections
# work thread deal network io
# default value is 4
# since V2.00
work_threads=4

# if disk read / write separated
##  false for mixed read and write
##  true for separated read and write
# default value is true
# since V2.00
disk_rw_separated = true

# disk reader thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_reader_threads = 1

# disk writer thread count per store base path
# for mixed read / write, this parameter can be 0
# default value is 1
# since V2.00
disk_writer_threads = 1

# when no entry to sync, try read binlog again after X milliseconds
# must > 0, default value is 200ms
sync_wait_msec=50

# after sync a file, usleep milliseconds
# 0 for sync successively (never call usleep)
sync_interval=0

# storage sync start time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_start_time=00:00

# storage sync end time of a day, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
sync_end_time=23:59

# write to the mark file after sync N files
# default value is 500
write_mark_file_freq=500

# path(disk or mount point) count, default value is 1
store_path_count=1

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/fastdfs/store_path
#store_path1=/home/yuqing/fastdfs2

# subdir_count  * subdir_count directories will be auto created under each
# store_path (disk), value can be 1 to 256, default value is 256
subdir_count_per_path=256

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.X.XXX:22122  
# tracker_server=tracker: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

#unix group name to run this program,
#not set (empty) means run by the group of current user
run_by_group=

#unix username to run this program,
#not set (empty) means run by current user
run_by_user=

# allow_hosts can ocur more than once, host can be hostname or ip address,
# "*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20] or
# host[01-08,20-25].domain.com, for example:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
allow_hosts=*

# the mode of the files distributed to the data path
# 0: round robin(default)
# 1: random, distributted by hash code
file_distribute_path_mode=0

# valid when file_distribute_to_path is set to 0 (round robin),
# when the written file count reaches this number, then rotate to next path
# default value is 100
file_distribute_rotate_count=100

# call fsync to disk when write big file
# 0: never call fsync
# other: call fsync when written bytes >= this bytes
# default value is 0 (never call fsync)
fsync_after_written_bytes=0

# sync log buff to disk every interval seconds
# must > 0, default value is 10 seconds
sync_log_buff_interval=10

# sync binlog buff / cache to disk every interval seconds
# default value is 60 seconds
sync_binlog_buff_interval=10

# sync storage stat info to disk every interval seconds
# default value is 300 seconds
sync_stat_file_interval=300

# thread stack size, should >= 512KB
# default value is 512KB
thread_stack_size=512KB

# the priority as a source server for uploading file.
# the lower this value, the higher its uploading priority.
# default value is 10
upload_priority=10

# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=

# if check file duplicate, when set to true, use FastDHT to store file indexes
# 1 or yes: need check
# 0 or no: do not check
# default value is 0
check_file_duplicate=0

# file signature method for check file duplicate
## hash: four 32 bits hash code
## md5: MD5 signature
# default value is hash
# since V4.01
file_signature_method=hash

# namespace for storing file indexes (key-value pairs)
# this item must be set when check_file_duplicate is true / on
key_namespace=FastDFS

# set keep_alive to 1 to enable persistent connection with FastDHT servers
# default value is 0 (short connection)
keep_alive=0

# you can use "#include filename" (not include double quotes) directive to
# load FastDHT server list, when the filename is a relative path such as
# pure filename, the base path is the base path of current/this config file.
# must set FastDHT server list when check_file_duplicate is true / on
# please see INSTALL of FastDHT for detail
##include /home/yuqing/fastdht/conf/fdht_servers.conf

# if log to access log
# default value is false
# since V4.00
use_access_log = false

# if rotate the access log every day
# default value is false
# since V4.00
rotate_access_log = false

# rotate access log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.00
access_log_rotate_time=00:00

# if rotate the error log every day
# default value is false
# since V4.02
rotate_error_log = false

# rotate error log time base, time format: Hour:Minute
# Hour from 0 to 23, Minute from 0 to 59
# default value is 00:00
# since V4.02
error_log_rotate_time=00:00

# rotate access log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_access_log_size = 0

# rotate error log when the log file exceeds this size
# 0 means never rotates log file by log file size
# default value is 0
# since V4.02
rotate_error_log_size = 0

# if skip the invalid record when sync file
# default value is false
# since V4.02
file_sync_skip_invalid_record=false

# 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

# use the ip address of this storage server if domain_name is empty,
# else this domain name will ocur in the url redirected by the tracker server
http.domain_name=

# the port of the web server on this storage server
http.server_port=8088 

实操命令

[root@localhost fastdfs]# mkdir -p  /Users/fastdfs/tracker/data  /Users/fastdfs/storage/data  /Users/fastdfs/storage/store_path
[root@localhost fastdfs]# ll
total 0
drwxr-xr-x. 4 root root 36 Apr  3 05:31 storage
drwxr-xr-x. 3 root root 18 Apr  3 05:31 tracker
[root@localhost fastdfs]# vim docker-compose.yml
[root@localhost fastdfs]# vim nginx.conf
[root@localhost fastdfs]# cd storage/
[root@localhost storage]# vim storage.conf
[root@localhost storage]# ll
total 8
drwxr-xr-x. 2 root root    6 Apr  3 05:31 data
-rw-r--r--. 1 root root 7550 Apr  3 05:40 storage.conf
drwxr-xr-x. 2 root root    6 Apr  3 05:31 store_path
[root@localhost storage]# cd ..
[root@localhost fastdfs]# ll
total 8
-rw-r--r--. 1 root root 1009 Apr  3 05:37 docker-compose.yml
-rw-r--r--. 1 root root 1349 Apr  3 05:38 nginx.conf
drwxr-xr-x. 4 root root   56 Apr  3 05:40 storage
drwxr-xr-x. 3 root root   18 Apr  3 05:31 tracker
[root@localhost fastdfs]# docker-compose up -d
[+] Running 32/32
 ✔ fastdfs-nginx Pulled                                                                                                                                                                                  570.0s 
 ✔ fastdfs-tracker Pulled                                                                                                                                                                                570.0s 
 ✔ fastdfs-storage 29 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                      569.9s 
   ✔ 8f47f7c36e43 Pull complete                                                                                                                                                                          159.3s 
   ✔ a3ed95caeb02 Pull complete                                                                                                                                                                          159.4s 
   ✔ 334b71ebe4b7 Pull complete                                                                                                                                                                          563.4s 
   ✔ 501dbd51e5b1 Pull complete                                                                                                                                                                          563.5s 
   ✔ 211d30d17a48 Pull complete                                                                                                                                                                          563.7s 
   ✔ 7917d4ca5fa0 Pull complete                                                                                                                                                                          563.9s 
   ✔ 0ea301a91e8a Pull complete                                                                                                                                                                          564.1s 
   ✔ ee98692f5a53 Pull complete                                                                                                                                                                          564.1s 
   ✔ c8bebf9feda9 Pull complete                                                                                                                                                                          564.4s 
   ✔ 082cefb501ef Pull complete                                                                                                                                                                          564.5s 
   ✔ 759bdf6d7bc8 Pull complete                                                                                                                                                                          564.8s 
   ✔ 399655568a1b Pull complete                                                                                                                                                                          564.9s 
   ✔ f98251a66673 Pull complete                                                                                                                                                                          564.9s 
   ✔ 82772e2c8763 Pull complete                                                                                                                                                                          565.0s 
   ✔ f733c99b8b90 Pull complete                                                                                                                                                                          565.5s 
   ✔ db55ddd48ab0 Pull complete                                                                                                                                                                          565.6s 
   ✔ a2fdeaafed0c Pull complete                                                                                                                                                                          566.1s 
   ✔ 039dde2808e9 Pull complete                                                                                                                                                                          566.3s 
   ✔ 3e685bc4e848 Pull complete                                                                                                                                                                          566.3s 
   ✔ 92605cb8258e Pull complete                                                                                                                                                                          566.4s 
   ✔ d91781d4d1af Pull complete                                                                                                                                                                          566.5s 
   ✔ f7e5f4b87a47 Pull complete                                                                                                                                                                          566.6s 
   ✔ 1377ff247577 Pull complete                                                                                                                                                                          566.6s 
   ✔ ab32a6faa7ef Pull complete                                                                                                                                                                          566.7s 
   ✔ 7ccf0617a3f3 Pull complete                                                                                                                                                                          566.7s 
   ✔ be86f3bc7b20 Pull complete                                                                                                                                                                          566.8s 
   ✔ aebe70250b7e Pull complete                                                                                                                                                                          566.9s 
   ✔ f32eb8e7d898 Pull complete                                                                                                                                                                          567.0s 
   ✔ 1a0b05b49f27 Pull complete                                                                                                                                                                          567.1s 
[+] Running 3/3
 ✔ Container fastdfs-tracker  Started                                                                                                                                                                      0.7s 
 ✔ Container fastdfs-storage  Started                                                                                                                                                                      1.1s 
 ✔ Container fastdfs-nginx    Started                                                                                                                                                                      1.5s 
 [root@localhost RabbitMQ]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/season/fastdfs       1.2                 510c4e6ec9f3        7 years ago         228 MB
[root@localhost fastdfs]# docker ps
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS               NAMES
6649303ca6bc        season/fastdfs:1.2                   "/entrypoint.sh nginx"   21 seconds ago      Up 18 seconds                           fastdfs-nginx
c2af8f24714c        season/fastdfs:1.2                   "/entrypoint.sh st..."   21 seconds ago      Up 19 seconds                           fastdfs-storage
07dbef95a505        season/fastdfs:1.2                   "/entrypoint.sh tr..."   21 seconds ago      Up 19 seconds                           fastdfs-tracker
[root@localhost fastdfs]# firewall-cmd --state   # 查看防火墙状态
running
[root@localhost fastdfs]# systemctl stop firewalld    # 关闭防火墙
[root@localhost fastdfs]# firewall-cmd --state
not running
# 以上关闭防火墙的方法,也可以使用一下方法解决
#开放端口   此操作我并没有测试、为测试我选择的是关闭防火墙
#firewall-cmd --zone=public --permanent --add-port=8088/tcp
#firewall-cmd --zone=public --permanent --add-port=22122/tcp
#firewall-cmd --zone=public --permanent --add-port=23000/tcp
# 进入容器上传图片测试
[root@localhost fastdfs]# docker exec -it storage /bin/bash   
root@3f23b4eeab6b:/# cd fdfs_conf/
root@3f23b4eeab6b:/fdfs_conf# ls
anti-steal.jpg	client.conf  http.conf	mime.types  mod_fastdfs.conf  storage.conf  storage_ids.conf  tracker.conf
root@3f23b4eeab6b:/fdfs_conf# fdfs_upload_file storage.conf anti-steal.jpg 
group1/M00/00/00/rBMAA2Qq0xCAJAMSAABdrZgsqUU412.jpg
#浏览器测试 http://ip:8088/group1/M00/00/00/rBMAA2Qq0xCAJAMSAABdrZgsqUU412.jpg
#或者从本地上传一个图片测试也是可以的
[root@localhost images]# ll
total 304
-rw-r--r--. 1 root root 129270 Apr  3 06:28 guangzhouta.jpg
[root@localhost images]# docker cp /Users/fastdfs/images/guangzhouta.jpg 3f23b4eeab6b:/fdfs_conf/
[root@localhost images]# docker exec -it storage /bin/bash
root@3f23b4eeab6b:/# cd fdfs_conf/
root@3f23b4eeab6b:/fdfs_conf# ls
anti-steal.jpg	client.conf  guangzhouta.jpg  http.conf  mime.types  mod_fastdfs.conf  storage.conf  storage_ids.conf  tracker.conf
root@3f23b4eeab6b:/fdfs_conf# fdfs_upload_file storage.conf guangzhouta.jpg 
group1/M00/00/00/rBMAA2Qq1MiAXF4IAAH49rpuEP4603.jpg

最后

至此便是使用Docker-Compose安装单机版FastDFS的过程,希望能给您带来帮助!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值