FastDFS + Nginx 安装说明(高可用)
实现统一的对外下载访问入口的高可用架构,其中所有的Nginx只做下载用途,上传通过tracker进行上传
一、环境准备
1.1 系统软件说明:
名称 | 说明 |
---|---|
CentOS | 7.x(操作系统) |
libfastcommon | FastDFS分离出的一些公用函数包 |
FastDFS | FastDFS本体 |
fastdfs-nginx-module | FastDFS和nginx的关联模块,解决组内同步延迟问题 |
nginx | nginx 1.12.2(CentOS 7 下YUM可以安装的最新版本) |
1.2 所需环境资源及用途:
名称 | IP地址 | 应用 |
---|---|---|
tracker01 | 192.168.0.102 | FastDFS、libfastcommon |
tracker02 | 192.168.0.103 | FastDFS、libfastcommon |
storage01 | 192.168.0.104 | FastDFS、libfastcommon、nginx、fastdfs-nginx-module |
storage02 | 192.168.0.105 | FastDFS、libfastcommon、nginx、fastdfs-nginx-module |
nginx01 | 192.168.0.100 | nginx、keepalived |
nginx02 | 192.168.0.101 | nginx、keepalived |
VIP | 192.168.0.200 |
1.3 指定阿里yum源
1.4 准备安装包
下载 libfastcommon
、fastdfs
、fastdfs-nginx-module
安装包 | 下载地址 |
---|---|
libfastcommon | https://github.com/happyfish100/libfastcommon/releases |
fastdfs | https://github.com/happyfish100/fastdfs/releases |
fastdfs-nginx-module | https://github.com/happyfish100/fastdfs-nginx-module/releases |
nginx-1.12.2 | http://nginx.org/download/nginx-1.12.2.tar.gz |
下载的包都存放在 /www/fastdfs
目录下
版本对照:
fastdfs | fastdfs-nginx-module | nginx |
---|---|---|
v5.11 | v1.20 | v1.12 |
二、服务安装:
2.1 安装依赖组件:
2.2 安装 libfastcommon
2.3 安装 FastDFS
2.3.1 Tracker Server 配置:
Tracker Server 随机启动:
脚本内容:
设置随机启动:
2.3.2 Storage Server 配置
Storage Server 随机启动:
脚本内容:
设置随机启动:
查看集群状态:
2.3.4 Client 配置
保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
配置过程中有几点要注意:
确保配置中用到的目录已经创建了。比如
~/fdfs/client
、~/fdfs/data
、~/fdfs/logs
确保各种配置文件之间引用的端口一直。比如:
mod_fastdfs.conf
文件中tracker_server
的端口应该跟tracker.conf
中port
一致;mod_fastdfs.conf
文件中storage_server_port
的端口应该跟跟storage.conf
中port
一致;其他配置或文件虽然不用修改,但是fastdfs-nginx-module模块会用到:
anti-steal.jpg
http.conf
mime.types
2.3.5 安装 nginx 和 fastdfs-nginx-module
解压并配置 fastdfs-nginx-module
安装 Nginx
执行完成后会输出信息,通过这些信息可以知道编译出来的nginx会装到哪里,配置文件会放在哪里,错误日志会放在哪里:
继续执行 make
和 make install
:
配置 nginx.config
说明:
(1)”user root”是解决下载操作时报404的问题
(2)8888端口号与/etc/fdfs/storage.conf中的http.server_port=8888相对应
(3)storage对应有多个group的情况下,访问路径带group名称,例如:/group1/M00/00/00/**,对应nginx配置:
配置nginx开机启动
文件内容如下:
退出并保存文件,执行systemctl enable nginx.service使nginx开机启动
验证是否安装成功
输入http://服务器IP/ 如果能看到nginx的界面,就表示安装成功了
如果不能访问,关闭防火墙:
上传图片到fastdfs:
浏览器访问:http://192.168.2.200:8888/group1/M00/00/00/wKgCyF0bWrOAMmJDAAD4TDHQw7Y274.png
2.3.6 在nginx的构建中会遇到不少的报错,具体如下:
- ./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library.
解决方法如下:
- /configure: error: the HTTP rewrite module requires the PCRE library.
解决方法如下:
- ./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using –without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using –with-http_ssl_module –with-openssl= options.
解决方法如下:
- ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib= option.
解决方法如下:
- ./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.
解决方法如下:
- ./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
解决方法如下:
- ./configure: error: perl module ExtUtils::Embed is required
解决方法如下:
- ./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.
解决方法如下:
- 在make过程中会出现一个报错:/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory
解决方法如下:
2.3.7 配置文件访问的负载均衡和高可用
在192.168.0.100和101上安装nginx、keepalived
nginx的配置文件如下:
keepalived配置文件如下:
check_nginx.sh
2.3.7 FastDFS 文件防盗
FastDFS 配置 Nginx 负载后,默认情况只要知道访问地址就能获取文件,这种情况是极其不安全的,需要开启FastDFS自带的token安全机制,来实现文件防盗功能。
下面配置主要需要配置 check_token=true
来开启token验证, 指定Token超时时间token_ttl=900
, 设置安全密钥secret_key=6fGkkBwRnaDjfXdh
,指定异常情况返回结果token_check_fail=提示图片
参考文档:
https://segmentfault.com/a/1190000018251300?utm_source=tag-newest
https://www.cnblogs.com/sunnydou/p/49b92d511047f4f9da6cd727cfd415d5.html
https://github.com/happyfish100/fastdfs/wiki
https://www.cnblogs.com/youzhibing/p/9187765.html
最后编辑:Jeebiz 更新时间:2025-05-08 13:39