fastdfs通过docker安装

原文链接: http://www.cnblogs.com/yaun1498078591/p/11435057.html

安装前准备

# yum install -y git #下载git
# cd /data
# mkdir fastdfs
# cd fastdfs
# git clone https://github.com/happyfish100/fastdfs.git #克隆fastdfs仓库到本地
Cloning into 'fastdfs'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 1107 (delta 1), reused 1 (delta 0), pack-reused 1101
Receiving objects: 100% (1107/1107), 6.34 MiB | 26.00 KiB/s, done.
Resolving deltas: 100% (736/736), done. #克隆完毕

构建镜像

# cd /data/fastdfs/docker/dockerfile_network# docker build -t fastdfs:latest . #构建镜像
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
fastdfs latest c1c4e7f3a646 5 hours ago 493MB
# mkdir -p /data/fastdfs/tracker_data
# mkdir -p /data/fastdfs/storage_data
# mkdir -p /etc/fdfs
# cp /data/fastdfs/fastdfs/docker/dockerfile_network/conf/* /etc/fdfs/

使用docker镜像构建tracker容器(跟踪服务器,起到调度的作用)

修改tracker配置文件# vim /etc/fdfs/tracker.conf

# the base path to store data and log files
base_path=/fastdfs/storage/products
# when store_lookup set to 1, must set store_group to the group name
store_group=group0

创建tracker服务

# docker run -ti -d --name tracker -v /etc/fdfs:/etc/fdfs -v /data/fastdfs/tracker_data:/fastdfs/tracker -p 22122:22122 fastdfs:latest tracker 
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0bc17faeec29 fastdfs:latest "/home/fastdfs.sh tr…" 34 minutes ago Up 34 minutes 80/tcp, 8888/tcp, 23000/tcp, 0.0.0.0:22122->22122/tcp tracker

进入tracker容器

# docker exec -it tracker /bin/bash 
# mkdir /fastdfs/storage/products
# yum -y install net-tools 
# yum -y install telnet
# yum -y install initscripts
# ip -4 a # 查看IP
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
24: eth0@if25:  mtu 1500 qdisc noqueue state UP group default link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
172.17.0.2 # tracker service服务的IP
# ss -ntlp #查看端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 *:80 *:* users:(("nginx",pid=19,fd=6))
LISTEN 0 128 *:8888 *:* users:(("nginx",pid=19,fd=7))
明显22122端口没启动

# cd /etc/init.d
# ls
fdfs_storaged fdfs_trackerd functions netconsole network README
# ./fdfs_trackerd start # 启动tracker服务
Starting FastDFS tracker server: 
# ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 *:80 *:* users:(("nginx",pid=19,fd=6))
LISTEN 0 128 *:8888 *:* users:(("nginx",pid=19,fd=7))
LISTEN 0 128 *:22122 *:* users:(("fdfs_trackerd",pid=103,fd=5))

使用docker镜像构建storage容器(存储服务器,提供容量和备份服务)

修改storage配置文件

# vim /etc/fdfs/storage.conf 
# and storage_ids.conf must be configed correctly.
group_name=group0
# the base path to store data and log files
base_path=/fastdfs/storage/products
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/fastdfs/storage/products/statics
store_path1=/fastdfs/storage/products/thumb
#store_path1=/home/dfs2
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=172.17.0.2:22122 # tracker_server服务的IP端口

创建storage服务

# docker run -ti -d --name storage -v /etc/fdfs:/etc/fdfs -v /data/fastdfs/storage_data:/fastdfs/storage/products -e TRACKER_SERVER:172.17.0.2:22122 -p 8888:8888 -p 23000:23000 fastdfs:latest storage 
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c75062a1666 fastdfs:latest "/home/fastdfs.sh st…" 3 hours ago Up 3 hours 80/tcp, 0.0.0.0:8888->8888/tcp, 22122/tcp, 0.0.0.0:23000->23000/tcp storage

进入storage容器

# docker exec -it storage /bin/bash 
# yum -y install net-tools 
# yum -y install telnet
# yum -y install initscripts
# ip -4 a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
26: eth0@if27:  mtu 1500 qdisc noqueue state UP group default link-netnsid 0
inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
172.17.0.3 # storage service服务的IP
# ss -ntlp #查看端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 *:22122 *:* users:(("fdfs_trackerd",pid=20,fd=5))
LISTEN 0 128 *:80 *:* users:(("nginx",pid=22,fd=6))
LISTEN 0 128 *:23000 *:* users:(("fdfs_storaged",pid=168,fd=5))
LISTEN 4 128 *:8888 *:* users:(("nginx",pid=22,fd=7))
注:23000端口没启动时
# cd /etc/init.d
# ls
fdfs_storaged fdfs_trackerd functions netconsole network README
./fdfs_storaged 
Usage: ./fdfs_storaged {start|stop|status|restart|condrestart}
# ./fdfs_storaged start
# ./fdfs_storaged status # 查看是启动状态 
# ss -ntlp 查看未启动
这时,# kill -9 pid 再 # ./fdfs_storaged start 即可
用测试程序测试服务可用性(上传文件到storage容器)
# docker exec -it tracker /bin/bash 
# echo hello world > /opt/123.txt
# fdfs_test /etc/fdfs/client.conf upload /opt/123.txt 
打印如下信息即认为测试通过
This is FastDFS client test program v5.12

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.

[2019-08-27 06:31:58] DEBUG - base_path=/fastdfs/storage/products, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group: 
server 1. group_name=, ip_addr=172.17.0.3, port=23000

group_name=group0, ip_addr=172.17.0.3, port=23000
storage_upload_by_filename
group_name=group0, remote_filename=M00/00/00/rBEAA11kzl6ASXZWAAAADK8IOy0581.txt
source ip address: 172.17.0.3
file timestamp=2019-08-27 06:31:58
file size=12
file crc32=2936552237
example file url: http://172.17.0.3/group0/M00/00/00/rBEAA11kzl6ASXZWAAAADK8IOy0581.txt
storage_upload_slave_by_filename
group_name=group0, remote_filename=M00/00/00/rBEAA11kzl6ASXZWAAAADK8IOy0581_big.txt
source ip address: 172.17.0.3
file timestamp=2019-08-27 06:31:58
file size=12
file crc32=2936552237
example file url: http://172.17.0.3/group0/M00/00/00/rBEAA11kzl6ASXZWAAAADK8IOy0581_big.txt
# docker exec -it storage /bin/bash 
# cd /fastdfs/storage/products/statics/data/00/00
# cat rBEAA11kzl6ASXZWAAAADK8IOy0581.txt
hello world

 

转载于:https://www.cnblogs.com/yaun1498078591/p/11435057.html

你可能感兴趣的:(fastdfs通过docker安装)