使用docker搭建FastDFS


拉取鏡像(使用docker-componse可以忽略)

[root@localhost ~]# docker pull phinexdaz/fdfs_tracker
[root@localhost ~]# docker pull phinexdaz/fdfs_storage

docker-componse.yml

[root@localhost fdfs]# cat docker-componse.yml 
version: '2'

services: 
    fdfs_tracker:
        image: phinexdaz/fdfs_tracker
        container_name: fdfs_tracker
        cap_add:
            - LINUX_IMMUTABLE
        ports:
            - "22122:22122"
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /opt/compose-conf/df/data/fastdfs/tracker:/data/tracker
        hostname: fdfs_tracker
        restart: always
        environment:
            - LANG=zh_CN.UTF-8
        mem_limit: 2g
        memswap_limit: 2g
        stdin_open: true
        tty: true
    fdfs_storage:
        image: phinexdaz/fdfs_storage
        links:
            - fdfs_tracker
        container_name: fdfs_storage
        cap_add:
            - LINUX_IMMUTABLE
        ports:
            - "80:80"
            - "23000:23000"
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /opt/compose-conf/df/data/fastdfs/storage:/data/storage
            
        hostname: fdfs_storage
        restart: always
        environment:
            - LANG=zh_CN.UTF-8
            - TRACKER=fdfs_tracker
        mem_limit: 2g
        memswap_limit: 2g
        stdin_open: true
        tty: true

啟動fdfs

[root@localhost fdfs]# docker-compose -f docker-componse.yml up -d
# 進入docker
[root@localhost fdfs]# docker-enter fdfs_storage
# 更改啟動腳本, 更改ip變量
[root@fdfs_storage /]# cat /entrypoint.sh 
#!/bin/bash

STORAGE_BASE_PATH="/data/storage"
STORAGE_LOG_FILE="$STORAGE_BASE_PATH/logs/storaged.log"
STORAGE_CONF_FILE="/etc/fdfs/storage.conf"

echo "start fdfs_storgaed..."

#ip=`cat /etc/hosts | grep $TRACKER | awk '{print $1}'`
ip=$TRACKER
sed -i "s/^.*tracker_server=.*$/tracker_server=$ip:22122/" /etc/fdfs/storage.conf
sed -i "s/^.*tracker_server=.*$/tracker_server=$ip:22122/" /etc/fdfs/client.conf
sed -i "s/^.*tracker_server=.*$/tracker_server=$ip:22122/" /etc/fdfs/mod_fastdfs.conf
 
fdfs_storaged "$STORAGE_CONF_FILE"
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
tail -f "$STORAGE_LOG_FILE"

# 提交鏡像
[root@localhost fdfs]# docker commit fdfs_storage phinexdaz/fdfs_storage

[root@localhost fdfs]# docker-compose -f docker-componse.yml up -d

測試

[root@localhost fdfs]# docker-enter fdfs_storage
[root@localhost fdfs]# docker-enter fdfs_storage fdfs_upload_file /etc/fdfs/client.conf /tmp/ss.txt
[root@localhost ~]# curl http://127.0.0.1:88/group1/M00/00/00/rBcAA1yi9nmAQ56OAAAABFqCAvc886.txt
123


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM