fastdfs部署

举报
凤凰涅槃 发表于 2022/12/10 22:20:37 2022/12/10
【摘要】 fastdfs部署官方github支持官方解释:FastDFS 是一个开源的高性能分布式文件系统。它的主要功能包括:文件存储、文件同步和文件访问(文件上传和文件下载),它可以解决高容量和负载均衡问题。FastDFS应该能满足图片分享网站、视频分享网站等以文件为基础服务的网站的要求。FastDFS有两个角色:tracker和storage。跟踪器负责文件访问的调度和负载均衡。storage ...

fastdfs部署

官方github支持

官方解释:FastDFS 是一个开源的高性能分布式文件系统。它的主要功能包括:文件存储、文件同步和文件访问(文件上传和文件下载),它可以解决高容量和负载均衡问题。FastDFS应该能满足图片分享网站、视频分享网站等以文件为基础服务的网站的要求。
FastDFS有两个角色:tracker和storage。跟踪器负责文件访问的调度和负载均衡。storage 存储文件,其功能是文件管理,包括:文件存储,文件同步,提供文件访问接口。它还管理元数据,这些元数据是表示文件键值对的属性。例如:width=1024,键为“width”,值为“1024”。
跟踪器和存储包含一个或多个服务器。跟踪器或存储集群中的服务器可以随时加入或移除集群,而不影响在线服务。跟踪器集群中的服务器是对等的。
按文件卷/组组织的存储服务器以获得高容量。存储系统包含一个或多个卷,这些卷之间的文件是独立的。整个存储系统的容量等于所有卷容量的总和。一个文件卷包含一台或多台存储服务器,这些服务器之间的文件是相同的。一个文件卷中的服务器相互备份,所有这些服务器都是负载均衡的。将存储服务器添加到卷时,该卷中已经存在的文件会自动复制到这台新服务器上,复制完成后,系统会将这台服务器在线切换为提供存储服务。
当整个存储容量不足时,您可以添加一个或多个卷来扩展存储容量。为此,您需要添加一台或多台存储服务器。
文件的标识由两部分组成:卷名和文件名。

个人理解:FastDFS 是一个开源的高性能分布式文件系统。FastDFS能满足图片分享网站、视频分享网站等以文件为基础服务的网站的要求。简单说就是为图片分享网站、视频分享网站等以文件为基础服务的网站服务。
优势:对于用户来说,不用管内部图片、视频存放位置。它能够自动存放好,并且反馈一个URL地址供你调用

角色 名词 功能
tracker 跟踪器 负责文件访问的调度和负载均衡
storage 存储 文件管理,包括:文件存储,文件同步,提供文件访问接口。它还管理元数据,这些元数据是表示文件键值对的属性

环境说明

系统:centos 7

内核:3.10.0-1160.62.1.el7.x86_64

防火墙:

方式1)关闭防火墙
systemctl stop firewalld (关闭firewalld )
方式2)开启防火墙,开放80端口(我是80,自行选择)
systemctl start firewalld(开启firewalld )
firewall-cmd --zone=public --add-port=80/tcp --permanent (添加开放端口)
firewall-cmd --reload(加载配置)
firewall-cmd --zone= public --query-port=80/tcp(查看端口是否开启)

一、环境配置

  • 实验能否访问外网(决定是下包还是传包)

ping www.baidu.com

在这里插入图片描述

可以很粗暴的认为,能ping通有网

那就能下载,没网的服务器就找到有网的机器,下载好了再上传吧。

  • 获取软件包

先创建一个文件夹,把所有包都放在一个目录下,好找。

[root@lsigzmdun5 ~]# cd  /opt/
[root@lsigzmdun5 opt]# ls
avalokita  bcm-agent  bsm-agent  hosteye  rh
[root@lsigzmdun5 opt]# mkdir fastdfs_package  # 创建包存储文件夹
[root@lsigzmdun5 opt]# cd fastdfs_package/
[root@lsigzmdun5 fastdfs_package]# 

下载四个官网软件包:
fastdfs-5.04
libfastcommon-1.0.43.zip
fastdfs-nginx-module-1.20.zip
nginx-1.20.2.tar.gz

传完如下:

[root@lsigzmdun5 fastdfs_package]# ls
fastdfs-5.04.zip  fastdfs-nginx-module-1.20.zip  libfastcommon-1.0.43.zip nginx-1.20.2.tar.gz
  • 下载依赖(后期nginx安装需要)
 yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc zip unzip libevent

二、部署

  • 部署libfastcommon-1.0.43

[root@lsigzmdun5 fastdfs_package]# unzip libfastcommon-1.0.43.zip #解压
Archive:  libfastcommon-1.0.43.zip
c8c75666cf9b17adaf58883174ddd8631d628c01
   creating: libfastcommon-1.0.43/
    ... ... 
[root@lsigzmdun5 fastdfs_package]# cd libfastcommon-1.0.43  #进入目录
[root@lsigzmdun5 libfastcommon-1.0.43]#  ./make.sh && ./make.sh install  #编译安装
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o hash.o hash.c  
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o chain.o chain.c  
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o shared_func.o shared_func.c  
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o ini_file_reader.o ini_file_reader.c  
     ...  ... 

一般没有报错,直接执行就好

  • 部署fastdfs-5.04

[root@lsigzmdun5 fastdfs_package]# unzip fastdfs-5.04.zip #解压
Archive:  fastdfs-5.04.zip
f19daf51eeb021f0fcaa8770d49f76551a436cb1
   creating: fastdfs-5.04/
  inflating: fastdfs-5.04/COPYING-3_0.txt  
  inflating: fastdfs-5.04/HISTORY    
  inflating: fastdfs-5.04/INSTALL    
  inflating: fastdfs-5.04/README.md  
   creating: fastdfs-5.04/client/
  inflating: fastdfs-5.04/client/Makefile.in  
   ... ...
[root@lsigzmdun5 fastdfs_package]# cd fastdfs-5.04/    #进入目录
[root@lsigzmdun5 fastdfs-5.04]# ls
client  conf             fastdfs.spec  init.d   make.sh     README.md   stop.sh  test
common  COPYING-3_0.txt  HISTORY       INSTALL  php_client  restart.sh  storage  tracker
[root@lsigzmdun5 fastdfs-5.04]# ./make.sh  && ./make.sh install #编译安装
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global.o ../common/fdfs_global.c  -I../common -I/usr/include/fastcommon
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o tracker_proto.o tracker_proto.c  -I../common -I/usr/include/fastcommon
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o 
  ...  ...

一般没有报错,直接执行

  • 创建存储文件目录

[root@lsigzmdun5 opt]# mkdir fastdfs   #/opt/fastdfs 本次项目的总存储路径
[root@lsigzmdun5 opt]# mkdir -p  /opt/fastdfs/client #client 端日志目录
[root@lsigzmdun5 opt]# mkdir -p  /opt/fastdfs/storage/base /opt/fastdfs/storage/store  #存储文件的路径 
[root@lsigzmdun5 opt]# mkdir -p /opt/fastdfs/tracker/data /opt/fastdfs/tracker/log   #跟踪器的文件路径
[root@lsigzmdun5 opt]# mkdir -p /opt/fastdfs/storage/base/data #存储文件的路径 
[root@lsigzmdun5 opt]# mkdir -p /opt/fastdfs/storage/base/logs #存储文件的日志路径 
[root@lsigzmdun5 opt]# mkdir -p /opt/fastdfs/nginx_mod #nginx模块路径
  • 拷贝配置文件

[root@lsigzmdun5 opt]# cd /etc/fdfs 
[root@lsigzmdun5 fdfs]# ls
client.conf.sample  storage.conf.sample  tracker.conf.sample
[root@lsigzmdun5 fdfs]# cp tracker.conf.sample tracker.conf
[root@lsigzmdun5 fdfs]# cp storage.conf.sample storage.conf
[root@lsigzmdun5 fdfs]# cp client.conf.sample client.conf
[root@lsigzmdun5 fdfs]# ls
client.conf   client.conf.sample  storage.conf  storage.conf.sample  tracker.conf  tracker.conf.sample
  • 修改配置文件

对于tracker.conf文件,只需要修改以下几项

base_path=/opt/fastdfs/tracker #修改文件存储路径

详细配置文件与说明如下:

[root@lsigzmdun5 fdfs]# cat tracker.conf|egrep -v "^$|^#"

disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/opt/fastdfs/tracker
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
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

对于storage.conf文件,只需要修改以下几项

base_path=/opt/fastdfs/storage/base
store_path0=/opt/fastdfs/storage/store
tracker_server=106.12.115.19:22122

详细配置文件与说明如下:

[root@lsigzmdun5 fdfs]# cat storage.conf|egrep -v "^$|^#"
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/opt/fastdfs/storage/base
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=/opt/fastdfs/storage/store
subdir_count_per_path=256
tracker_server=106.12.115.19:22122
log_level=info
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 = false
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=8888

对于client.conf文件,只需要修改以下几项

base_path=/opt/fastdfs/client/
tracker_server=106.12.115.19:22122

详细配置文件与说明如下:

[root@lsigzmdun5 fdfs]# cat client.conf|egrep -v "^$|^#"
connect_timeout=30
network_timeout=60
base_path=/opt/fastdfs/client/
tracker_server=106.12.115.19:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80
  • 启动

[root@lsigzmdun5 fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
[root@lsigzmdun5 fdfs]# ps -ef |grep fdfs
root     22737     1  0 23:48 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
[root@lsigzmdun5 fdfs]#  /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
[root@lsigzmdun5 fdfs]# ps -ef |grep fdfs
root     22737     1  0 23:48 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
root     25546     1  0 23:50 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf 
  • 检验上传

[root@lsigzmdun5 ~]# /opt/fastdfs_package/fastdfs-5.04/client/fdfs_test  /etc/fdfs/client.conf upload /root/lyy.png #先要有/root/lyy.png,你要先上传对应目录
This is FastDFS client test program v5.04

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.

[2022-12-10 00:03:45] DEBUG - base_path=/opt/fastdfs/client, 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=106.12.115.19, port=23000

group_name=group1, ip_addr=106.12.115.19, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672.png
source ip address: 192.168.0.4
file timestamp=2022-12-10 00:03:45
file size=160225
file crc32=3697121847
example file url: http://106.12.115.19/group1/M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672.png
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672_big.png
source ip address: 192.168.0.4
file timestamp=2022-12-10 00:03:46
file size=160225
file crc32=3697121847
example file url: http://106.12.115.19/group1/M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672_big.png
[root@lsigzmdun5 ~]# ll /opt/fastdfs/storage/store/data/00/00/  #文件存储位置
总用量 328
-rw-r--r-- 1 root root 160225 1210 00:03 wKgABGOTXGGAfL1OAAJx4dxdmjc672_big.png
-rw-r--r-- 1 root root     49 1210 00:03 wKgABGOTXGGAfL1OAAJx4dxdmjc672_big.png-m
-rw-r--r-- 1 root root 160225 1210 00:03 wKgABGOTXGGAfL1OAAJx4dxdmjc672.png
-rw-r--r-- 1 root root     49 1210 00:03 wKgABGOTXGGAfL1OAAJx4dxdmjc672.png-m

三、添加nginx显示

  • 配置fastdfs-nginx-module

[root@lsigzmdun5 ~]# cd /opt/fastdfs_package/
[root@lsigzmdun5 fastdfs_package]# ls
fastdfs-5.04      fastdfs-nginx-module-1.20.zip  libfastcommon-1.0.43.zip
fastdfs-5.04.zip  libfastcommon-1.0.43           nginx-1.20.2.tar.gz
[root@lsigzmdun5 fastdfs_package]# unzip fastdfs-nginx-module-1.20.zip 
Archive:  fastdfs-nginx-module-1.20.zip
396ffefbbb3a8c737226e9fdeb219e930c1e4372
   creating: fastdfs-nginx-module-1.20/
  inflating: fastdfs-nginx-module-1.20/HISTORY  
  inflating: fastdfs-nginx-module-1.20/INSTALL  
   creating: fastdfs-nginx-module-1.20/src/
  inflating: fastdfs-nginx-module-1.20/src/common.c  
  inflating: fastdfs-nginx-module-1.20/src/common.h  
  inflating: fastdfs-nginx-module-1.20/src/config  
  inflating: fastdfs-nginx-module-1.20/src/mod_fastdfs.conf  
  inflating: fastdfs-nginx-module-1.20/src/ngx_http_fastdfs_module.c  
[root@lsigzmdun5 fastdfs_package]# cd fastdfs-nginx-module-1.20
[root@lsigzmdun5 fastdfs-nginx-module-1.20]# cp src/mod_fastdfs.conf /etc/fdfs/
[root@lsigzmdun5 fastdfs-nginx-module-1.20]# cd /etc/fdfs/
[root@lsigzmdun5 fdfs]# ls
client.conf  client.conf.sample  mod_fastdfs.conf  storage.conf  storage.conf.sample  tracker.conf  tracker.conf.sample

对于client.conf文件,只需要修改以下几项

base_path=/opt/fastdfs/nginx_mod
tracker_server=106.12.115.19:22122
url_have_group_name = true
store_path0=/ytxt/fastdfs/storage/store/

详细配置文件与说明如下:

[root@lsigzmdun5 fastdfs_package]# cat mod_fastdfs.conf|egrep -v "^$|^#"
connect_timeout=2
network_timeout=30
base_path=/opt/fastdfs/nginx_mod
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=106.12.115.19:22122
torage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/ytxt/fastdfs/storage/store/
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
  • 安装nginx

[root@lsigzmdun5 fastdfs_package]# tar -xf  nginx-1.20.2.tar.gz 
[root@lsigzmdun5 fastdfs_package]# ls
fastdfs-5.04      fastdfs-nginx-module-1.20      libfastcommon-1.0.43      nginx-1.20.2
fastdfs-5.04.zip  fastdfs-nginx-module-1.20.zip  libfastcommon-1.0.43.zip  nginx-1.20.2.tar.gz
[root@lsigzmdun5 fastdfs_package]# ./configure --prefix=/opt/fastdfs_package/nginx-1.20.2 --add-module=/opt/fastdfs_package/fastdfs-nginx-module-1.20/src #配置

报错一

[root@lsigzmdun5 nginx-1.20.2]# make && make install  #编译安装
make -f objs/Makefile
make[1]: 进入目录“/opt/fastdfs_package/nginx-1.20.2”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused
    ...  ...
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /usr/local/include \
        -o objs/addon/src/ngx_http_fastdfs_module.o \
        /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/ngx_http_fastdfs_module.c
In file included from /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/common.c:26:0,
                 from /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/ngx_http_fastdfs_module.c:6:
/usr/include/fastdfs/fdfs_define.h:15:27: 致命错误:common_define.h:没有那个文件或目录
 #include "common_define.h"
                           ^
编译中断。
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 错误 1
make[1]: 离开目录“/opt/fastdfs_package/nginx-1.20.2”
make: *** [build] 错误 2

解决一:
修改配置文件/opt/fastdfs_package/fastdfs-nginx-module-1.20/src/config中的

ngx_module_incs="/usr/local/include "
CORE_INCS="$CORE_INCS /usr/local/include "

ngx_module_incs="/usr/local/include /usr/include/fastcommon/ "
CORE_INCS="$CORE_INCS /usr/local/include /usr/include/fastcommon/ "

文件前后文如下:

[root@lsigzmdun5 nginx-1.20.2]# cat  /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/config
       ... ...
ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    **ngx_module_incs="/usr/local/include  /usr/include/fastcommon/ "**
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    **CORE_INCS="$CORE_INCS /usr/local/include /usr/include/fastcommon/ "**
    CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi

重新编译安装

[root@lsigzmdun5 fastdfs_package]# ./configure --prefix=/opt/fastdfs_package/nginx-1.20.2 --add-module=/opt/fastdfs_package/fastdfs-nginx-module-1.20/src

报错二:

[root@lsigzmdun5 nginx-1.20.2]# make && make install
make -f objs/Makefile
make[1]: 进入目录“/opt/fastdfs_package/nginx-1.20.2”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused
    ...  ...
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /usr/local/include -I /usr/include/fastcommon/ \
        -o objs/addon/src/ngx_http_fastdfs_module.o \
        /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/ngx_http_fastdfs_module.c
In file included from /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/ngx_http_fastdfs_module.c:6:0:
/opt/fastdfs_package/fastdfs-nginx-module-1.20/src/common.c: 在函数‘fdfs_http_request_handler’中:
/opt/fastdfs_package/fastdfs-nginx-module-1.20/src/common.c:1245:61: 错误:‘FDFSHTTPParams’没有名为‘support_multi_range’的成员
                 (pContext->range_count > 1 && !g_http_params.support_multi_range))
                                                             ^
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 错误 1
make[1]: 离开目录“/opt/fastdfs_package/nginx-1.20.2”
make: *** [build] 错误 2

解决二:
/opt/fastdfs_package/fastdfs-nginx-module-1.20/src/common.c文件中第1245行的&& !g_http_params.support_multi_range删除。
原本文件相关上下文:

    if (fdfs_check_and_format_range(pContext, file_size) != 0 ||
          (pContext->range_count > 1  && !g_http_params.support_multi_range ))
          {
                    if (fd >= 0)
                    {
                           close(fd);
                  }

改为:

    if (fdfs_check_and_format_range(pContext, file_size) != 0 ||
          (pContext->range_count > 1 ))
          {
                    if (fd >= 0)
                    {
                           close(fd);
                  }

重新编译安装

[root@lsigzmdun5 fastdfs_package]# ./configure --prefix=/opt/fastdfs_package/nginx-1.20.2 --add-module=/opt/fastdfs_package/fastdfs-nginx-module-1.20/src

报错三:
安装文件与解压文件一致问题。


[root@lsigzmdun5 nginx-1.20.2]# make && make install
make -f objs/Makefile
make[1]: 进入目录“/opt/fastdfs_package/nginx-1.20.2”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused
    ...  ... 
make[1]: 离开目录“/opt/fastdfs_package/nginx-1.20.2”
make -f objs/Makefile install
make[1]: 进入目录“/opt/fastdfs_package/nginx-1.20.2”
test -d '/opt/fastdfs_package/nginx-1.20.2' || mkdir -p '/opt/fastdfs_package/nginx-1.20.2'
test -d '/opt/fastdfs_package/nginx-1.20.2/sbin' \
        || mkdir -p '/opt/fastdfs_package/nginx-1.20.2/sbin'
test ! -f '/opt/fastdfs_package/nginx-1.20.2/sbin/nginx' \
        || mv '/opt/fastdfs_package/nginx-1.20.2/sbin/nginx' \
                '/opt/fastdfs_package/nginx-1.20.2/sbin/nginx.old'
cp objs/nginx '/opt/fastdfs_package/nginx-1.20.2/sbin/nginx'
test -d '/opt/fastdfs_package/nginx-1.20.2/conf' \
        || mkdir -p '/opt/fastdfs_package/nginx-1.20.2/conf'
cp conf/koi-win '/opt/fastdfs_package/nginx-1.20.2/conf'
cp: "conf/koi-win""/opt/fastdfs_package/nginx-1.20.2/conf/koi-win" 为同一文件
make[1]: *** [install] 错误 1
make[1]: 离开目录“/opt/fastdfs_package/nginx-1.20.2”
make: *** [install] 错误 2

解决三:

[root@lsigzmdun5 fastdfs_package]# ./configure --prefix=/opt/fastdfs_package/nginx --add-module=/opt/fastdfs_package/fastdfs-nginx-module-1.20/src
[root@lsigzmdun5 nginx-1.20.2]# make && make install
make -f objs/Makefile
make[1]: 进入目录“/opt/fastdfs_package/nginx-1.20.2”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused
 ...  ...
cp conf/scgi_params \
        '/opt/fastdfs_package/nginx/conf/scgi_params.default'
test -f '/opt/fastdfs_package/nginx/conf/nginx.conf' \
        || cp conf/nginx.conf '/opt/fastdfs_package/nginx/conf/nginx.conf'
cp conf/nginx.conf '/opt/fastdfs_package/nginx/conf/nginx.conf.default'
test -d '/opt/fastdfs_package/nginx/logs' \
        || mkdir -p '/opt/fastdfs_package/nginx/logs'
test -d '/opt/fastdfs_package/nginx/logs' \
        || mkdir -p '/opt/fastdfs_package/nginx/logs'
test -d '/opt/fastdfs_package/nginx/html' \
        || cp -R html '/opt/fastdfs_package/nginx'
test -d '/opt/fastdfs_package/nginx/logs' \
        || mkdir -p '/opt/fastdfs_package/nginx/logs'
make[1]: 离开目录“/opt/fastdfs_package/nginx-1.20.2”

成功安装。

  • 修改nginx配置文件

做软链接

[root@lsigzmdun5 nginx-1.20.2]# cd ../
[root@lsigzmdun5 fastdfs_package]# mkdir 
[root@lsigzmdun5 fastdfs_package]# ls 
fastdfs-5.04      fastdfs-nginx-module-1.20      libfastcommon-1.0.43      nginx         nginx-1.20.2.tar.gz
fastdfs-5.04.zip  fastdfs-nginx-module-1.20.zip  libfastcommon-1.0.43.zip  nginx-1.20.2
[root@lsigzmdun5 fastdfs_package]# mkdir /opt/fastdfs/storage/store/data/M00ab/
[root@lsigzmdun5 fastdfs_package]# ln -s  /opt/fastdfs/storage/store/data/ /opt/fastdfs/storage/store/data/M00ab/ 

修改nginx.config文件
主要是在http.server下,将

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

替换为我们的

location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}

详细配置文件如下:

[root@lsigzmdun5 fastdfs_package]# vim nginx/conf/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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

       # location / {
        #    root   html;
         #   index  index.html index.htm;
        #}
           location ~/group([0-9])/M00 {
              ngx_fastdfs_module;
         }
        #error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

	    
}
  • 启动nginx

[root@lsigzmdun5 fastdfs_package]# /opt/fastdfs_package/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=8102
  • 网页检验

访问http://106.12.115.19/group1/M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672.png

报错四:

[root@lsigzmdun5 fastdfs_package]# tail -f nginx/logs/error.log 

ngx_http_fastdfs_process_init pid=8104
[2022-12-10 00:51:31] ERROR - file: ini_file_reader.c, line: 1029, include file "http.conf" not exists, line: "#include http.conf"
[2022-12-10 00:51:31] ERROR - file: /opt/fastdfs_package/fastdfs-nginx-module-1.20/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2022/12/10 00:51:31 [alert] 8103#0: worker process 8104 exited with fatal code 2 and cannot be respawned

解决四:

[root@lsigzmdun5 fastdfs_package]# cp fastdfs-5.04/conf/http.conf  fastdfs-5.04/conf/mime.types  /etc/fdfs
[root@lsigzmdun5 fastdfs_package]# /opt/fastdfs_package/nginx/sbin/nginx  -s reload
ngx_http_fastdfs_set pid=18978

再次访问http://106.12.115.19/group1/M00/00/00/wKgABGOTXGGAfL1OAAJx4dxdmjc672.png

在这里插入图片描述
完成

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。