阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

FastDFS 应用安装测试

159次阅读
没有评论

共计 4400 个字符,预计需要花费 11 分钟才能阅读完成。

配置 Nginx 为 storage server 提供 http 访问接口:

背景:
在大多数业务场景中,往往需要为 FastDFS 存储的文件提供 http 下载服务,而尽管 FastDFS 在其 storage 及 tracker 都内置了 http 服务,但性能表现却不尽如人意;

作者余庆在后来的版本中增加了基于当前主流 web 服务器的扩展模块 (包括 nginx/apache),其用意在于利用 web 服务器直接对本机 storage 数据文件提供 http 服务,以提高文件下载的性能。

描述:
nginx 配置在 storage 节点上(本例以 storage 节点的 node2 为例);

因为 Nginx 要想连接 fastdfs 就必须要有相应的模块,所以要编译安装 nginx 把 fastdfs-nginx-module 模块编译进去

步骤如下:

1. 首先下载 fastdfs-nginx-module 和 编译安装 nginx 的源码包
# 从官方站点上克隆 fastdfs-nginx-module 模块
[root@CentOS7 ~]# git clone https://github.com/happyfish100/fastdfs-nginx-module.git
Cloning into ‘fastdfs-nginx-module’…
remote: Counting objects: 57, done.
remote: Total 57 (delta 0), reused 0 (delta 0), pack-reused 57
Unpacking objects: 100% (57/57), done.
 
# 准备好的 nginx 源码包如下
[root@centos7 fastdfs]# ls
fastdfs-nginx-module  nginx-1.10.0.tar.gz 
 
[root@centos7 fastdfs]# tar xf nginx-1.10.0.tar.gz 
[root@centos7 fastdfs]# ls
fastdfs-nginx-module  nginx-1.10.0  nginx-1.10.0.tar.gz

2. 准备编译安装的环境
yum groupinstall “Development Tools” “Server Platfrom Development” -y
yum install pcre-devel openssl-devel zlib-devel -y

3. 创建 nginx 用户编译安装 nginx,指明 fastdfs-nginx-module 模块的位置
[root@centos7 nginx-1.10.0]# useradd -r nginx
[root@centos7 nginx-1.10.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
 
[root@centos7 nginx-1.10.0]# ./configure –prefix=/usr/local/nginx –conf-path=/etc/nginx/nginx.conf 
–error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log 
–pid-path=/var/run/nginx/nginx.pid –lock-path=/var/lock/nginx.lock –user=nginx –group=nginx 
–with-http_ssl_module –with-http_stub_status_module –with-pcre –add-module=/root/fastdfs/fastdfs-nginx-module/src
 
[root@centos7 nginx-1.10.0]# make && make install

3、复制配置文件
# cp fastdfs-nginx/module/src/mod_fastdfs.conf  /etc/fdfs/
# cp fastdfs-5.0.8/conf/{httpd.conf,mime.types}  /etc/fdfs/
  注意:fastdfs-5.0.8 为 fastdfs 源码目录;

4、配置 /etc/fdfs/mod_fastdfs.conf 配置文件,部分指令类似如下所示;
  base_path=/data/fdfs/storage
  tracker_server=192.168.1.112:22122
  storage_server_port=23000
  group_name=group1
  url_have_group_name = true
  store_path_count=1
  store_path0=/data/fdfs/storage/0
 
  [group1] 
  group_name=group1
  storage_server_port=23000
  store_path_count=1
  store_path0=/data/fdfs/storage/0

5、配置 nginx,编辑 nginx.conf,在 server 中添加类似如下内容:
  location ~ /group[0-9]+/M00/ {
      root /data/fdfs/storage/0/data/;
      ngx_fastdfs_module;
  }

6、为存储文件路径创建链接至 M00,此示例中使用的 storage_path0 为 /data/fdfs/storage/0;
# ln -sv /data/fdfs/storage/0  /data/fdfs/storage/0/M00
 
[root@centos7 ~]# ll /data/fdfs/storage/0/
total 12
drwxr-xr-x 258 root root 8192 Mar 24 11:50 data
lrwxrwxrwx  1 root root  20 Mar 24 11:23 M00 -> /data/fdfs/storage/0

7、启动 nginx 服务即可;
[root@centos7 sbin]# pwd
/usr/local/nginx/sbin
 
[root@centos7 sbin]# ./nginx -t
ngx_http_fastdfs_set pid=27041
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
 
[root@centos7 sbin]# ./nginx
 
[root@centos7 sbin]# ps aux| grep ‘nginx’
root      27011  0.0  0.1  52880  1160 ?        Ss  11:25  0:00 nginx: master process ./nginx
nginx    27012  0.0  0.2  55524  2516 ?        S    11:25  0:00 nginx: worker process

8、上传文件,测试:
# node3 节点上传文件
[root@centos7 fdfs]# fdfs_upload_file /etc/fdfs/client.conf /usr/share/wallpapers/Autumn/contents/images/1600×1200.jpg
group1/M00/00/00/wKgBcVjUlzqAEyeUAAxFCUUQ0Sc981.jpg
 
[root@centos7 fdfs]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKgBcVjUlzqAEyeUAAxFCUUQ0Sc981.jpg
source storage id: 0
source ip address: 192.168.1.113
file create timestamp: 2017-03-24 11:49:14
file size: 804105
file crc32: 1158730023 (0x4510D127)
 
[root@centos7 fdfs]# fdfs_upload_file /etc/fdfs/client.conf /usr/share/wallpapers/Hanami/contents/images/1920×1200.jpg
group1/M00/00/00/wKgBcljUGkCAEkdsAAqAdF8ZgSw271.jpg
 
[root@centos7 fdfs]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKgBcljUGkCAEkdsAAqAdF8ZgSw271.jpg
source storage id: 0
source ip address: 192.168.1.114
file create timestamp: 2017-03-24 02:56:00
file size: 688244
file crc32: 1595506988 (0x5F19812C)

9. 在浏览器中访问路径的 URL 为 fid:

FastDFS 应用安装测试

CentOS 7 安装配置分布式文件系统 FastDFS 5.0.5  http://www.linuxidc.com/Linux/2016-09/135537.htm

CentOS6 环境单服务器 FastDFS+Nginx+fastdfs-nginx-module 安装配置 http://www.linuxidc.com/Linux/2015-01/111889.htm

Ubuntu 14.04 下部署 FastDFS 5.08+Nginx 1.9.14 http://www.linuxidc.com/Linux/2016-07/133485.htm

FastDFS 分布式文件系统集群安装与配置   http://www.linuxidc.com/Linux/2017-02/140420.htm

CentOS 7 安装配置分布式文件系统 FastDFS 5.0.5  http://www.linuxidc.com/Linux/2016-09/135537.htm

FastDFS 分布式存储服务器安装过程详解 http://www.linuxidc.com/Linux/2016-10/136544.htm

FastDFS 之文件服务器集群部署详解 http://www.linuxidc.com/Linux/2017-01/139891.htm

FastDFS 的详细介绍 :请点这里
FastDFS 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-03/142172.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计4400字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中