docker-compose配置fastdfs集群(loading……)

(基础配置:一台tracker服务器,两台storage服务器分别属于不同的组)
1、 创建所需的文件结构
第一台服务器文件tree

[root@test1 cluster]# pwd
/home/fastdfs/cluster
[root@test1 cluster]# tree
.
├── fd_st1
│   ├── docker-compose.yml
│   ├── fast_data
│   └── storage
│       ├── Dockerfile
│       └── nginx.conf
└── fd_tr
    ├── docker-compose.yml
    ├── fast_data
    └── tracker
        ├── Dockerfile
        ├── client.conf
        ├── nginx.conf
        └── tracker.sh

6 directories, 7 files
[root@test1 cluster]#

第二台服务器文件tree

[root@test2 cluster]# pwd
/home/fastdfs/cluster
[root@test2 cluster]# tree
.
└── fd_st2
    ├── docker-compose.yml
    ├── fast_data
    └── storage
        ├── Dockerfile
        └── nginx.conf

3 directories, 3 files
[root@test2 cluster]#

2、编写root@test1服务器(fd_tr)文件夹下的配置文件
tracker:
①docker-compose.yml文件如下

version: '3'

services:
 tracker:
  build: ./tracker
  ports:
  - "22122:22122"
  - "8000:8000"
  volumes:
    - /home/fastdfs/cluster/fd_tr/fast_data:/data/fast_data
    - /home/fastdfs/cluster/fd_tr/tracker/client.conf:/etc/fdfs/client.conf

注意:22122是tracker的端口,.8000是tracker的nginx负载均衡端口

②Dockerfile文件如下

FROM morunchang/fastdfs
COPY nginx.conf /etc/nginx/conf/nginx.conf
COPY tracker.sh /tracker.sh
ENTRYPOINT sh tracker.sh

③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=/data/fast_data

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=IP地址: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

tracker_server=IP地址:22122为tracker服务器

④配置负载均衡、通过tracker服务器就可以访问的nginx.conf文件如下:

FROM morunchang/fastdfs
COPY nginx.conf /etc/nginx/conf/nginx.conf
COPY tracker.sh /tracker.sh
ENTRYPOINT sh tracker.sh

[root@test1 tracker]# cat 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;

    # 对group1做负载均衡
    upstream fdfs_group1 {
         server 192.168.180.46:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    # 对group2做负载均衡
    upstream fdfs_group2 {
         server 192.168.180.47:8080 weight=1 max_fails=2 fail_timeout=30s;
    }

    server {
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #location /group1/M00 {
            #proxy_next_upstream http_502 http_504 error timeout invalid_header;
            #proxy_pass http://fdfs_group1;
            #expires 30d;
        #}

        location /group2/M00 {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_pass http://fdfs_group2;
            expires 30d;
        }

        #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;
        }

        # 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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

注意:
# 对group1做负载均衡
upstream fdfs_group1 {
server ip:8080 weight=1 max_fails=2 fail_timeout=30s;
}
# 对group2做负载均衡
upstream fdfs_group2 {
server ip:8080 weight=1 max_fails=2 fail_timeout=30s;
}

listen端口号改为8000

⑤tracker.sh文件如下:

#!/bin/sh
/data/fastdfs/tracker/fdfs_trackerd /etc/fdfs/tracker.conf
/etc/nginx/sbin/nginx
tail -f /data/fast_data/logs/trackerd.log

3、storage1 编写root@test1服务器(fd_st1)文件夹下的配置文件
①docker-compose.yml文件如下

version: '3'

services:
 storage:
  build: ./storage
  environment:
   GROUP_NAME: group1
   TRACKER_IP: 192.168.190.132:22122
  ports:
  - "8080:8080"
  - "23000:23000"
  volumes:
    - /home/fastdfs/cluster/fd_st1/fast_data:/data/fast_data

注意:
23000是storage的端口,8080是nginx端口,TRACKER_IP是tracker的ip和端口
group1为组名

②Dockerfile文件如下

FROM morunchang/fastdfs
COPY nginx.conf /data/nginx/conf/nginx.conf
ENTRYPOINT sh storage.sh

③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       8888;
        server_name  localhost;
 
        #charset koi8-r;
   	    location ~/group([0-9])/M00 {
	     	#alias /fastdfs/storage/data;
		    ngx_fastdfs_module;
	    }
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #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;
        }
 
        # 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;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

注意:
1、listen 8888;端口是与storage.conf中的http_server_port相对应的要一样

2、配置集群这个一定要加上:
location ~/group([0-9])/M00 {
#alias /fastdfs/storage/data;
ngx_fastdfs_module;
}

4、storage2编写root@test2服务器(fd_st2)文件夹下的配置文件
①docker-compose.yml文件如下

version: '3'

services:
 storage:
  build: ./storage
  environment:
   GROUP_NAME: group2
   TRACKER_IP: 192.168.190.132:22122
  ports:
  - "8080:8080"
  - "23000:23000"
  volumes:
    - /home/fastdfs/cluster/fd_st2/fast_data:/data/fast_data

注意:
23000是storage的端口,.8080是nginx端口,TRACKER_IP是tracker的ip和端口 group2为组名

②Dockerfile文件如下

FROM morunchang/fastdfs
COPY nginx.conf /data/nginx/conf/nginx.conf
ENTRYPOINT sh storage.sh

③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       8888;
        server_name  localhost;
 
        #charset koi8-r;
   	    location ~/group([0-9])/M00 {
		    #alias /fastdfs/storage/data;
		    ngx_fastdfs_module;
	    }
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #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;
        }
 
        # 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;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

注意:
1、listen 8888;端口是与storage.conf中的http_server_port相对应的要一样
2、配置集群这个一定要加上:
location ~/group([0-9])/M00 {
#alias /fastdfs/storage/data;
ngx_fastdfs_module;
}

5、启动tranker
①docker-compose up --build -d

[root@test1 cluster]# cd fd_tr/
[root@test1 fd_tr]# ll
总用量 12
-rw-r--r-- 1 root root  211 10月 15 15:18 docker-compose.yml
drwxr-xr-x 2 root root 4096 10月 15 15:18 fast_data
drwxr-xr-x 2 root root 4096 10月 15 15:01 tracker
[root@test1 fd_tr]# docker-compose up --build -d
Creating network "fd_tr_default" with the default driver
Building tracker
Step 1/4 : FROM morunchang/fastdfs
 ---> a729ac95698a
Step 2/4 : COPY nginx.conf /etc/nginx/conf/nginx.conf
 ---> Using cache
 ---> 8a69d4512fa3
Step 3/4 : COPY tracker.sh /tracker.sh
 ---> Using cache
 ---> 94454f3a0588
Step 4/4 : ENTRYPOINT sh tracker.sh
 ---> Using cache
 ---> ea23b3c3a13c
Successfully built ea23b3c3a13c
Successfully tagged fd_tr_tracker:latest
Creating fd_tr_tracker_1 ... done
[root@test1 fd_tr]# docker ps | grep fd_tr_tracker
3b1065da6f70        fd_tr_tracker          "/bin/sh -c 'sh trac…"   About a minute ago   Up About a minute   0.0.0.0:8000->8000/tcp, 0.0.0.0:22122->22122/tcp   fd_tr_tracker_1
[root@test1 fd_tr]# ll
总用量 12
-rw-r--r-- 1 root root  211 10月 15 15:18 docker-compose.yml
drwxr-xr-x 4 root root 4096 10月 15 15:47 fast_data
drwxr-xr-x 2 root root 4096 10月 15 15:01 tracker
[root@test1 fd_tr]# tree
.
├── docker-compose.yml
├── fast_data
│   ├── data
│   │   ├── fdfs_trackerd.pid
│   │   └── storage_changelog.dat
│   └── logs
│       └── trackerd.log
└── tracker
    ├── Dockerfile
    ├── nginx.conf
    └── tracker.sh

4 directories, 7 files
[root@test1 fd_tr]#

6、启动storage
docker-compose up --build -d

[root@test2 cluster]# pwd
/home/fastdfs/cluster
[root@test2 cluster]# tree
.
└── fd_st2
    ├── docker-compose.yml
    ├── fast_data
    └── storage
        ├── Dockerfile
        └── nginx.conf

3 directories, 3 files
[root@test2 cluster]# docker-compose up --build -d

7、通过tracker_client查看配置的storage

[root@test1 tracker]# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
aa253806b3be        fd_tr_tracker          "/bin/sh -c 'sh trac…"   25 minutes ago      Up 25 minutes       0.0.0.0:8000->8000/tcp, 0.0.0.0:22122->22122/tcp   fd_tr_tracker_1

输入

[root@test1 tracker]#docker exec -it fd_tr_tracker_1 fdfs_monitor /etc/fdfs/client.conf

查看storages的配置信息

[root@test1 tracker]# docker inspect fd_st1_storage_1
  1. 编辑3个文件:
    echo “aaa” >>/opt/1.txt && echo “bbb” >>/opt/2.txt && echo “ccc” >>/opt/3.txt
  2. 上传文件:
    /usr/bin/fdfs_test /etc/fdfs/client.conf upload 1.txt
    /usr/bin/fdfs_test /etc/fdfs/client.conf upload 2.txt
    /usr/bin/fdfs_test /etc/fdfs/client.conf upload 3.txt

返回结果中会把上传完成的url 打印出来,如都成功则 复制URL在浏览器中打开看是否正常

upload:上传普通文件,包括主文件
upload_appender:上传appender文件,后续可以对其进行append、modify和truncate操作
upload_slave:上传从文件
download:下载文件
delete:删除文件
append:在appender文件后追加内容
modify:appender文件修改
set_metadata:设置文件附加属性
get_metadata:获取文件附加属性

注:如需做group与相对路径拼接放到.txt文件中的话可以参考我写的python脚本

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值