docker安装fastdfs配置

docker搭建fastdfs环境,实现http://192.168.65.129/group1/M00/00/00/wKhBgVwPT46AZKvoAAGPP2sLNds263.jpg访问图片文件。

基于morunchang/fastdfs,nginx

准备

文件准备
创建目录 /opt/fastdfs
创建目录 /opt/fastdfs/nginx
创建目录 /opt/fastdfs/nginx/conf.d
创建目录 /opt/fastdfs/static
创建文件 /opt/fastdfs/docker-compose.yaml
创建文件 /opt/fastdfs/nginx/nginx.conf
创建文件 /opt/fastdfs/nginx/conf.d/default.conf
创建文件 /opt/fastdfs/static/index.html
注:为什么要创建nginx.conf和default.conf请参考https://www.jianshu.com/p/8228d261c6ff
文件内容
docker-compose.yaml

docker-compose方式使用,不用则不需要创建

version: '3'
services:
  tracker:
    container_name: tacker
    image: morunchang/fastdfs
    command: "sh tracker.sh"
    network_mode: host
  storage:
    container_name: storage
    image: morunchang/fastdfs
    command: "sh storage.sh"
    network_mode: host
    environment:
      - TRACKER_IP=192.168.65.129:22122
      - GROUP_NAME=group1
  nginx:
    container_name: nginx
    image: nginx
    restart: always
    ports:
    - 80:80
    - 443:443
    volumes:
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/conf.d:/etc/nginx/conf.d
    - ./static:/opt/fastdfs/static #静态资源访问
nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    #location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
    #}
    location /static {
        root    /opt/fastdfs;
        index   index.html index.htm;
    }
    location / {
        proxy_pass  http://$host:8080;
    }
    #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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
index.html
<html>
    <body>
        hello,nginx
    </body>
</html>

1.命令方式

docker pull morunchang/fastdfs
docker pull nginx
docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
docker run -d --name storage --net=host -e TRACKER_IP=192.168.65.129:22122 -e GROUP_NAME=group1 morunchang/fastdfs sh storage.sh
docker run id --name nginx -v /opt/fastdfs/nginx/nginx.conf:/etc/nginx/nginx.conf -v /opt/fastdfs/nginx/conf.d:/etc/nginx/conf.d -v /opt/fastdfs/static:/opt/fastdfs/static -p 80:80 nginx

> 注:访问不到的情况下,再配置nginx
配置nginx:
    docker exec -it storage  /bin/bash
    vi /data/nginx/conf/nginx.conf
    添加如下内容:

location /group1/M00 {
    proxy_next_upstream http_502 http_504 error timeout invalid_header;

    proxy_cache http-cache;

    proxy_cache_valid 20030412h;

    proxy_cache_key $uri$is_args$args;

    proxy_pass http://fdfs_group1; #该处的group1应该是需要与创建的group-name对应,我没有试验

    expires 30d;
}

退出docker:
exit

重启storage服务:
docker restart storage

注:strorage里面默认包含nginx,暴露的端口是8080,可通过http://192.168.65.129:8080/group1/M00/00/00/wKhBgVwPT46AZKvoAAGPP2sLNds263.jpg访问

2.docker-compose方式

2.1.安装docker-compose
下载地址:https://github.com/docker/compose/releases
推荐使用命令:
    curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
2.2.运行容器
cd /opt/fastdfs
docker-compose up -d
然后参考上面的步骤,配置storage内部的nginx

开启端口

firewall-cmd --zone=public --add-port=8080/tcp --permanent

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=22122/tcp --permanent

firewall-cmd --zone=public --add-port=23000/tcp --permanent

firewall-cmd --complete-reload

firewall-cmd--zone=public --list-all

访问测试

1.图片资源

http://192.168.65.129/group1/M00/00/00/wKhBgVwPT46AZKvoAAGPP2sLNds263.jpg

2.静态资源

http://192.168.65.129/static/index.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值