手机版
你好,游客 登录 注册
背景:
阅读新闻

FastDFS 应用安装测试

[日期:2017-03-25] 来源:Linux社区  作者:1992tao [字体: ]

配置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/1600x1200.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/1920x1200.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:

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

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款