本文档说明在fastdfs-node1和fastdfs-node2两台主机上安装部署FastDFS双节点。 fastdfs-node1 ip:192.168.110.96 安装tracker1,storage1 fastdfs-node2 ip:192.168.110.206 安装tracker2,storage2
1、拉取fastdfs docker镜像(两台服务器都操作)
[root@fastdfs-node1 ~]# docker pull morunchang/fastdfs
2、安装fastdfs tracker
2.1 在node01和node02上安装tracker
在fastdfs-node1和fastdfs-node2上分别执行以下操作 注意:以下操作指令在fastdfs-node1中执行,在fastdfs-node2操作时,将tracker1改为tracker2
一、创建文件夹
[root@fastdfs-node1 ~]# mkdir -p /apps/fastdfs/tracker1/data /apps/fastdfs/tracker1/conf
二、写入/apps/fastdfs/tracker1/conf/tracker.conf
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=30
base_path=/data/fast_data
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group1
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
三、运行tracker1的docker容器
[root@fastdfs-node1 ~]# docker run -d --name tracker1 --net=host --restart always -v /etc/localtime:/etc/localtime -v /apps/fastdfs/tracker1/data:/data/fast_data/ -v /apps/fastdfs/tracker1/conf/tracker.conf:/etc/fdfs/tracker.conf morunchang/fastdfs sh tracker.sh
四、查看docker日志是否启动正常
[root@fastdfs-node1 ~]# docker logs tracker1
五、开启防火墙端口:22122(若是关闭防火墙此操作可不做)
firewall-cmd --zone=public --add-port=22122/tcp --permanent
firewall-cmd --reload
3、安装fastdfs storage
3.1 在fastdfs-node1和fastdfs-node2上安装storage
在fastdfs-node1和fastdfs-node2上分别执行以下操作 注意:以下操作指令在fastdfs-node1中执行,在fastdfs-node2操作时,将storage1改为storage2
一、创建文件夹
[root@fastdfs-node1 ~]# mkdir -p /apps/fastdfs/storage1/data /apps/fastdfs/storage1/conf
二、写入/apps/fastdfs/storage1/conf/storage.conf
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23002
connect_timeout=30
network_timeout=30
heart_beat_interval=30
stat_report_interval=60
base_path=/data/fast_data
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/data/fast_data
subdir_count_per_path=256
tracker_server=192.168.110.96:22122
tracker_server=192.168.110.206:22122
log_level=debug
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = true
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=80
三、写入/apps/fastdfs/storage1/conf/nginx.conf
worker_processes 1;
error_log /data/fast_data/logs/nginx-error.log;
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 /data/fast_data/logs/nginx-access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ /group1/M00 {
root /data/fast_data/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
四、写入/apps/fastdfs/storage1/conf/mod_fastdfs.conf
connect_timeout=30
network_timeout=30
base_path=/data/fast_data
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=192.168.110.96:22122
tracker_server=192.168.110.206:22122
storage_server_port=23002
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/data/fast_data
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
http.default_content_type = application/octet-stream
http.mime_types_filename=/etc/nginx/conf/mime.types
五、写入/apps/fastdfs/storage1/conf/storage.sh
#!/bin/sh
/data/fastdfs/storage/fdfs_storaged /etc/fdfs/storage.conf
/etc/nginx/sbin/nginx
tail -f /data/fast_data/logs/storaged.log
六、写入/apps/fastdfs/storage1/conf/client.conf
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=30
# the base path to store log files
base_path=/data/fastdfs/test
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.110.96:22122
tracker_server=192.168.110.206: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
七、运行docker容器
docker run -d --name storage1 --net=host --restart always \
-v /etc/localtime:/etc/localtime \
-v /apps/fastdfs/storage1/data:/data/fast_data/ \
-v /apps/fastdfs/storage1/conf/storage.sh:/storage.sh \
-v /apps/fastdfs/storage1/conf/storage.conf:/etc/fdfs/storage.conf \
-v /apps/fastdfs/storage1/conf/nginx.conf:/etc/nginx/conf/nginx.conf \
-v /apps/fastdfs/storage1/conf/mod_fastdfs.conf:/etc/fdfs/mod_fastdfs.conf \
-v /apps/fastdfs/storage1/conf/client.conf:/data/fastdfs/conf/client.conf \
morunchang/fastdfs sh storage.sh
八、查看docker日志是否正常
[root@fastdfs-node1 ~]# docker logs storage1
九、开启防火墙端口:23002、9101(防火墙关闭状态不用操作)
firewall-cmd --zone=public --add-port=23002/tcp --add-port=80/tcp --permanent
firewall-cmd --reload
4、验证fastdfs是否安装成功
说明:以下操作在fastdfs-node1中进行。
4.1查看FastDFS监控状态
[root@fastdfs-node1 ~]# docker exec -it storage1 fdfs_monitor /data/fastdfs/conf/client.conf
参数说明:
tracker_server_count:2 --表示2个Tracker Server
tracker server is 192.168.110.96:22122 --表示Leader Tracker
group count: 1 --表示有1个group
group name = group1 --组名称是group1
storage server count = 2 --组内有2个storage
active server count = 2 --活动的storage有2个
storage server port = 23002 --storage的端口
storage HTTP port = 80 --storage的文件访问端口
store path count = 1 --storage只挂了一个存储目录
total_upload_count = 11 --总共上传了多少个文件
total_upload_bytes = 691405 --总共上传了多少字节
success_upload_bytes = 691405 --成功上传了多少字节
total_download_count = 2 --总共下载了多少文件(使用java客户端)
4.2上传文件到FastDFS
[root@fastdfs-node1 ~]# docker exec -it storage1 bash
root@fastdfs-node1:/# cd /data/fastdfs/conf
root@fastdfs-node1:/data/fastdfs/conf# fdfs_test client.conf upload anti-steal.jpg
文件上传成功后,会提示文件访问地址,同时会自动同步到storage2,因此也可以通过storage2的IP,访问文件。
由于storage1的http端口配置为80,所以访问地址是: (示例地址)http://192.168.110.96/group1/M00/00/00/wKhuzmXqhWKACYVPAABdrZgsqUU553.jpg storage2的访问地址是: (示例地址)http://192.168.110.206/group1/M00/00/00/wKhuzmXqhWKACYVPAABdrZgsqUU553.jpg
错误整理:在访问网页时一直访问不到(上面配置文件已添加忽略此条)
进入文件查看nignx错误日志
[root@fastdfs-node1 00]# docker exec -it storage1 bash
root@fastdfs-node1:/# cat /data/fast_data/logs/nginx-error.log
在/apps/fastdfs/storage1/conf/mod_fastdfs.conf文件中添加
http.default_content_type = application/octet-stream
http.mime_types_filename=/etc/nginx/conf/mime.types
然后停止storage1容器并重新启动就可以了
4.3下载文件
fastdfs安装配置成功。
原文:https://blog.csdn.net/zhanngle/article/details/88770028原文有上述报错进行修复