docker-compose 설정fastdfs 집단 (loading...)

17036 단어 fastDFS
(기초 설정: 트랙터 서버 한 대, 스토리지 서버 두 대가 각각 다른 그룹에 속함) 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]#


두 번째 서버 파일 트리
[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은 트랙터의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 서버
④ 부하가 균형이 잡혀 트랙터 서버를 통해 접근할 수 있는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; } # 그룹2에 부하 균형 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와 포트 그룹1입니다.
② 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;포트는 스토리지입니다.conf의 http_server_포트는 상응하는 것이 같다
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와 포트 그룹2입니다.
② 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;포트는 스토리지입니다.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

주: 그룹과 상대 경로를 연결합니다.txt 파일에 있으면 제가 쓴python 스크립트를 참고할 수 있습니다.

좋은 웹페이지 즐겨찾기