项目中使用了FastDFS作为文件系统,这里记录一下它的安装和配置过程
项目场景
由于是测试环境,所以只提供了一台服务器,后续软件的安装和配置都在这台服务器上完成
准备工作
软件名称 | 下载地址 |
---|---|
FastDFS | fastdfs-5.10.tar.gz |
libfastcommon | libfastcommon-1.0.35.tar.gz |
nginx | nginx-1.9.9.tar.gz |
fastdfs-nginx-module | fastdfs-nginx-module_v1.16.tar.gz |
Tracker安装配置
1、安装fastdfs公共库libfastcommon,注意fastdfs和libfastcommon的安装目录,后面安装fastdfs-nginx-module时需要进行相关配置
cp /mnt/download/libfastcommon-1.0.35.tar.gz /usr/local/
cd /usr/local
tar -zxvf libfastcommon-1.0.35.tar.gz
cd libfastcommon-1.0.35
./make.sh
./make.sh install
2、安装fastdfs
cp /mnt/download/fastdfs-5.10.tar.gz /usr/local/
cd /usr/local
tar -zxvf fastdfs-5.10.tar.gz
cd fastdfs-5.10
./make.sh
./make.sh install
3、配置Tracker
vi /etc/fdfs/tracker.conf
# 是否禁用该配置文件
# false:开启
# true:禁用
disabled=false
# 绑定地址
# 空字符表示绑定所有地址
bind_addr=
# 端口设置
port=22122
# 连接超时设置
connect_timeout=30
# 网络超时设置
network_timeout=30
# 存储数据和日志的目录
base_path=/mnt/fastdfs
# 最大并发连接数
max_connections=256
# 接受请求的线程数
accept_threads=1
# 执行请求的线程数 <= max_connections
work_threads=4
# 如何选择上传文件的存储group
# 0: 轮询
# 1: 制定group名称
# 2: 负载均衡, 选择空闲空间最大的存储group
store_lookup=2
# 选择哪一个存储group,当store_lookup=1时,须指定存储group的名称
store_group=group1
# 如何选择上传文件的存储server
# 0: 轮询
# 1: 以ip地址排序的第一个地址
# 2: 以优先级排序
store_server=0
# 选择存储server的哪一个路径(磁盘或挂载点)上传文件
# 0: 轮询
# 2: 负载均衡, 选择空闲空间最大的路径来存储文件
store_path=0
# 选择哪一个存储server下载文件
# 0: 轮询
# 1: 选择该文件上传时的那个存储server
download_server=0
# 预留的存储空间 G(GB) M(MB) K(KB) 默认byte(B),% 表示比例,如下,预留的存储空间为10%,即只占用90%
reserved_storage_space = 10%
# log级别:alert error notice info debug
log_level=info
# 运行用户组,默认当前用户组
run_by_group=
# 运行用户,默认当前用户
run_by_user=
# 允许的host,例子如下
# "*" 表示所有
# 10.0.1.[1-15,20]
# host[01-08,20-25].domain.com:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
allow_hosts=*
# 同步内存日志到磁盘的间隔时间,默认10s
sync_log_buff_interval = 10
# 检查存储server存活的间隔时间,默认120s
check_active_interval = 120
# 线程栈大小 >= 64KB
thread_stack_size = 64KB
# 当存储server变化时,是否自动调整存储server的ip
storage_ip_changed_auto_adjust = true
# 存储server同步文件的最大延时,默认86400s(1天)
storage_sync_file_max_delay = 86400
# 存储server同步一个文件的最大时间
storage_sync_file_max_time = 300
# 是否用一个主文件存储多个小文件
use_trunk_file = false
# 最小的slot大小(多个小文件之间的空隙大小),小于4k
slot_min_size = 256
# 最大的slot大小(多个小文件之间的空隙大小) > slot_min_size
# 当上传的文件大小 < slot_max_size时,那么该文件将合并到一个主文件
slot_max_size = 16MB
# 主文件大小 >= 4MB
trunk_file_size = 64MB
# 是否提前创建trunk文件
trunk_create_file_advance = false
# 创建trunk文件的基准时间
trunk_create_file_time_base = 02:00
# 创建trunk文件的间隔时间,默认86400s(1天)
trunk_create_file_interval = 86400
# 创建trunk文件的阈值空间
trunk_create_file_space_threshold = 20G
# 当加载trunk空间空间时,是否检查trunk空间占用情况,设置为true,启动会变慢
trunk_init_check_occupying = false
# 是否忽略storage_trunk.dat
trunk_init_reload_from_binlog = false
# 压缩trunk binlog文件的间隔时间
# 0表示不压缩
trunk_compress_binlog_min_interval = 0
# 是否使用storage ID,而不是ip地址
use_storage_id = false
# 定义storage ids文件,相对或绝对路径
storage_ids_filename = storage_ids.conf
# 存储id类型,当use_storage_id=true时有效
## ip: 存储server的IP
## id: 存储server的ID
id_type_in_filename = ip
# 是否使用链接文件存储slave文件
store_slave_file_use_link = false
# 是否滚动错误日志文件
rotate_error_log = false
# 滚动错误日志文件的时间点
error_log_rotate_time=00:00
# 当错误日志文件超出该值时,滚动错误日志文件
rotate_error_log_size = 0
# 保存日志文件的天数
# 0表示不删除日志文件
log_file_keep_days = 0
# 是否使用连接池
use_connection_pool = false
# 连接最大空闲时间
connection_pool_max_idle_time = 3600
# tracker的http端口
http.server_port=8080
# 检查http server存活的时间间隔
http.check_alive_interval=30
# 检查http sever存活的类型
# tcp : 仅连接http端口,不发请求
# http: 发http请求,并需返回200
# default value is tcp
http.check_alive_type=tcp
# 检查http server的uri
http.check_alive_uri=/status.html
注意一下存放数据和日志的目录,启动后需要查看日志信息
4、启动Tracker
fdfs_trackerd /etc/fdfs/tracker.conf
5、查看日志
为了确保Tracker启动成功,我们可以在刚在配置的日志目录中查看日志信息
cd /mnt/fastdfs/logs
cat trackerd.log
[2017-09-14 15:42:11] INFO - FastDFS v5.10, base_path=/mnt/fastdfs, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=30s, port=22122, bind_addr=, max_connections=256, accept_threads=1, work_threads=4, min_buff_size=8192, max_buff_size=131072, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, use_storage_id=0, id_type_in_filename=ip, storage_id_count=0, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, log_file_keep_days=0, store_slave_file_use_link=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2017-09-14 15:42:39] INFO - file: tracker_relationship.c, line: 389, selecting leader...
[2017-09-14 15:42:39] INFO - file: tracker_relationship.c, line: 407, I am the new tracker leader 10.129.44.128:22122
出现上述信息表示Tracker已启动成功
6、遇到的问题
Tracker启动后,如果改了Tracker的配置文件想要重新启动,执行启动命令后发现日志中报错
[2017-09-14 15:29:19] INFO - FastDFS v5.10, base_path=/mnt/fastdfs, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=30s, port=22122, bind_addr=, max_connections=256, accept_threads=1, work_threads=4, min_buff_size=8192, max_buff_size=131072, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, use_storage_id=0, id_type_in_filename=ip, storage_id_count=0, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, log_file_keep_days=0, store_slave_file_use_link=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2017-09-14 15:29:19] ERROR - file: sockopt.c, line: 864, bind port 22122 failed, errno: 98, error info: Address already in use.
[2017-09-14 15:29:19] CRIT - exit abnormally!
这是因为此时Tracker已经启动了,再执行启动命令就会报错地址已被使用,此时可以执行restart命令进行重启
fdfs_trackerd /etc/fdfs/tracker.conf restart
或者
ps -ef | grep tracker
#杀死对应的进程号
kill -9 xxxx
fdfs_trackerd /etc/fdfs/tracker.conf
Storage安装配置
安装步骤在上面Tracker的安装中已经做好了,直接配置即可
1、配置Storage
vi /etc/fdfs/storage.conf
## 是否禁用该配置文件# false:开启
# true:禁用
disabled=false
# 组名称
group_name=group1
# 绑定地址
# 空字符表示绑定所有地址
bind_addr=
# 当连接其他存储server时,是否绑定地址
client_bind=true
# 存储server端口
port=23000
# 连接超时
connect_timeout=30
# 网络超时
network_timeout=60
# 心跳
heart_beat_interval=30
# 磁盘使用报道的时间间隔
stat_report_interval=60
# 数据和日志目录
base_path=/mnt/fastdfs
# 最大并发连接数
max_connections=256
# 接收和发送数据的缓冲区大小
buff_size = 256KB
# 接受请求的线程数
accept_threads=1
# 执行请求的线程数
work_threads=4
# 磁盘读写是否分开
disk_rw_separated = true
# 每个存储基路径的读线程数
disk_reader_threads = 1
# 每个存储基路径的写线程数
disk_writer_threads = 1
# 当没有进行同步时, 多少毫秒后读取binlog
sync_wait_msec=50
# 当同步完一个文件后, 暂停多少毫秒
# 0 表示不调用usleep
sync_interval=0
# 每天存储同步的开始时间
sync_start_time=00:00
# 每天存储同步的结束时间
sync_end_time=23:59
# 同步多少个文件后,写入mark文件
write_mark_file_freq=500
# 路径(磁盘或挂载点)数
store_path_count=1
# 存储路径
store_path0=/mnt/fastdfs
# 子目录数
subdir_count_per_path=256
# tracker地址,可以配置多个tracker_server
tracker_server=10.129.44.128:22122
# tracker_server=10.163.174.222:22122
# 日志级别:alert error notice info debug
log_level=debug
# 运行进程的用户组,默认当前用户组
run_by_group=
# 运行进程的用户,默认当前用户
run_by_user=
# 允许的host,例子如下# "*" 表示所有
# 10.0.1.[1-15,20]
# host[01-08,20-25].domain.com:
# allow_hosts=10.0.1.[1-15,20]
# allow_hosts=host[01-08,20-25].domain.com
allow_hosts=*
# 文件分布模式
# 0: 轮询
# 1: 随机
file_distribute_path_mode=0
# 写多少个文件后,轮到下一个路径
file_distribute_rotate_count=100
# 当写入多大文件时,调用fsync
# 0: 不调用
# other: 文件大小(byte)
fsync_after_written_bytes=0
# 同步内存日志到磁盘的间隔时间,默认10s
sync_log_buff_interval=10
# 同步binlog到磁盘的间隔时间,默认10s
sync_binlog_buff_interval=10
# 同步存储状态信息到磁盘的间隔时间,默认300s
sync_stat_file_interval=300
# 线程栈大小 >= 512KB
thread_stack_size=512KB
# 上传文件的优先级,tracker中使用
upload_priority=10
# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=
# 是否检查文件重复
check_file_duplicate=0
# 文件签名方法
## hash: hash
## md5: MD5
file_signature_method=hash
# 存储文件索引的命名空间,check_file_duplicate=true时
key_namespace=FastDFS
# 设置与FastDHT保持长连接的数目,0表示使用短连接
keep_alive=0
# FastDHT server列表,需要安装FastDHT
##include /home/yuqing/fastdht/conf/fdht_servers.conf
# 是否记录访问日志
use_access_log = true
# 是否每天滚动访问日志文件
rotate_access_log = true
# 访问日志滚动时间点
access_log_rotate_time=00:00
# 是否每天滚动错误日志文件
rotate_error_log = true
# 错误日志滚动时间点
error_log_rotate_time=00:00
# 访问日志滚动大小
rotate_access_log_size = 0
# 错误日志滚动大小
rotate_error_log_size = 0
# 日志保留天数
log_file_keep_days = 7
# 同步文件时是否跳过无效的文件
file_sync_skip_invalid_record=false
# 是否使用连接池
use_connection_pool = false
# 连接最大空间时间
connection_pool_max_idle_time = 3600
# 域名
http.domain_name=
# http端口
http.server_port=8888
注意tracker的地址配置是否正确,否则启动时会报错
2、启动Storage
fdfs_storaged /etc/fdfs/storage.conf
3、查看日志
cd /mnt/fastdfs/logs
cat storaged.log
[2017-09-14 15:18:19] INFO - FastDFS v5.10, base_path=/mnt/fastdfs, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, accept_threads=1, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=hash, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=, use_access_log=1, rotate_access_log=1, access_log_rotate_time=00:00, rotate_error_log=1, error_log_rotate_time=00:00, rotate_access_log_size=0, rotate_error_log_size=0, log_file_keep_days=7, file_sync_skip_invalid_record=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2017-09-14 15:18:19] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0
[2017-09-14 15:18:19] INFO - file: storage_func.c, line: 257, tracker_client_ip: 10.129.44.128, my_server_id_str: 10.129.44.128, g_server_id_in_filename: -2144567030
[2017-09-14 15:18:19] DEBUG - file: storage_ip_changed_dealer.c, line: 241, last my ip is 10.163.174.222, current my ip is 10.129.44.128
[2017-09-14 15:18:19] DEBUG - file: fast_task_queue.c, line: 227, max_connections: 256, init_connections: 256, alloc_task_once: 256, min_buff_size: 262144, max_buff_size: 262144, block_size: 263288, arg_size: 1008, max_data_size: 268435456, total_size: 67401728
[2017-09-14 15:18:19] DEBUG - file: fast_task_queue.c, line: 284, malloc task info as whole: 1, malloc loop count: 1
[2017-09-14 15:18:19] DEBUG - file: tracker_client_thread.c, line: 225, report thread to tracker server 10.129.44.128:22122 started
[2017-09-14 15:18:19] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 10.129.44.128:22122, as a tracker client, my ip is 10.129.44.128
[2017-09-14 15:18:50] INFO - file: tracker_client_thread.c, line: 1263, tracker server 10.129.44.128:22122, set tracker leader: 10.129.44.128:22122
出现上述信息表示Storage已启动成功
4、遇到的问题
Storage启动后,如果改了Storage的配置文件想要重新启动,执行启动命令后发现日志中报错
[2017-09-14 15:28:09] INFO - FastDFS v5.10, base_path=/mnt/fastdfs, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, accept_threads=1, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=hash, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=, use_access_log=1, rotate_access_log=1, access_log_rotate_time=00:00, rotate_error_log=1, error_log_rotate_time=00:00, rotate_access_log_size=0, rotate_error_log_size=0, log_file_keep_days=7, file_sync_skip_invalid_record=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2017-09-14 15:28:09] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0
[2017-09-14 15:28:09] INFO - file: storage_func.c, line: 257, tracker_client_ip: 10.129.44.128, my_server_id_str: 10.129.44.128, g_server_id_in_filename: -2144567030
[2017-09-14 15:28:09] DEBUG - file: storage_ip_changed_dealer.c, line: 241, last my ip is 10.129.44.128, current my ip is 10.129.44.128
[2017-09-14 15:28:09] ERROR - file: sockopt.c, line: 864, bind port 23000 failed, errno: 98, error info: Address already in use.
[2017-09-14 15:28:09] CRIT - exit abnormally!
这是因为此时Storage已经启动了,再执行启动命令就会报错地址已被使用,此时可以执行restart命令进行重启
fdfs_storaged /etc/fdfs/storage.conf restart
或者
ps -ef | grep storage
#杀死对应的进程号
kill -9 xxxx
fdfs_storaged /etc/fdfs/storage.conf
之前阿里云ESC实例迁移,导致服务器内网ip地址发生了改变,重启Storage时日志报错
[2017-09-14 15:04:54] ERROR - file: storage_ip_changed_dealer.c, line: 186, connect to tracker server 10.163.174.222:22122 fail, errno: 110, error info: Connection timed out
这是由于Storage配置文件中tracker_server的ip地址还是旧地址,所以会出现连接超时的问题,将配置文件中的地址改成新的地址重启Storage
Storage上fastdfs-nginx-module安装配置
1、配置fastdfs-nginx-module所需的配置文件,包括mod_fastdfs.conf,http.conf,mime.types
配置mod_fastdfs.conf
vi /etc/fdfs/mod_fastdfs.conf
connect_timeout=5
network_timeout=30
base_path=/mnt/fastdfs/logs
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=10.129.44.128:22122
storage_server_port=23000
#与Storage的配置一致
group_name=group1
url_have_group_name = false
#与Storage的配置一致
store_path_count=1
#与Storage的配置一致
store_path0=/mnt/fastdfs
log_level=debug
log_filename=/usr/local/nginx/logs/mod_fastdfs.log
response_mode=proxy
if_alias_prefix=
#include http.conf
flv_support = true
flv_extension = flv
group_count = 0
注意tracker_server地址,否则启动后会报错
cd /usr/local/nginx/logs
cat mod_fastdfs.log
[2017-09-12 10:47:39] ERROR - file: ../tracker/tracker_proto.c, line: 593, connect to tracker server 10.163.174.222:22122 fail, errno: 110, error info: Connection timed out
配置http.conf
vi /etc/fdfs/http.conf
http.default_content_type = application/octet-stream
http.mime_types_filename=mime.types
http.anti_steal.check_token=false
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=FastDFS1234567890
http.anti_steal.token_check_fail=/path/to/check_failed.jpg
配置mime.types
cp /usr/local/fastdfs-5.10/conf/mime.types /etc/fdfs/mime.types
2、安装配置
cp /mnt/download/fastdfs-nginx-module_v1.16.tar.gz /usr/local/
cd /usr/local
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src
vi config
ngx_addon_name=ngx_http_fastdfs_module
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/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
注意CORE_INCS和CFLAGS两项的配置
Storage上nginx安装配置
1、建立nginx用户
groupadd nginx
useradd -g nginx nginx --shell=/sbin/nologin
2、安装配置
cp /mnt/download/nginx-1.9.9.tar.gz /usr/local/
cd /usr/local
tar -zxvf nginx-1.9.9.tar.gz
cd nginx-1.9.9
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src --group=nginx --user=nginx
make && make install
3、更改nginx目录权限
chown -R nginx:nginx /usr/local/nginx
4、配置文件nginx.conf
提供一个最简单的配置方式供参考,由于项目中nginx还做了其他处理,配置文件比较复杂,这里就不贴出来了
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
# group1为Storage所在的group
location /group1/M00 {
# Storage的data目录
root /mnt/fastdfs/data;
# 由于fastdfs保存的文件名已经编码,源文件名将丢失,应用可通过在请求url后加oname参数指定源文件名
if ($arg_oname != ''){
add_header Content-Disposition "attachment;filename=$arg_oname";
}
# 调用nginx-fastdfs-module模块
ngx_fastdfs_module;
}
}
}
5、启动nginx
两种方式
cd /usr/local/nginx/sbin/
./nginx -s reload
或者
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
使用过程中有其他问题多查看日志报错情况,或者查阅Nginx 跳转fastdfs存储图片地址报错问题分析过程汇总,详细原理讲解和测试查阅下面的参考文档