1.测试

前面两篇博文已对FastDFS的安装和配置,做了比较详细的讲解。FastDFS的基础模块都搭好了,现在开始测试下载。

1.1 配置客户端

同样的,需要修改客户端的配置文件:

vim /etc/fdfs/client.conf
  • 1
  1. base_path=/usr/yong.cao/dev/fastdfs/fastdfs_tracker #tracker服务器文件路径
  2. tracker_server=192.168.128.131:22122 #tracker服务器IP地址和端口号
  3. http.tracker_server_port=6666 # tracker 服务器的 http端口号,必须和tracker的设置对应起来

通过ftp上传图片到CentOS:

在我的windows上,我随便拖了一张图片上去。

[root@localhost ~]# ll /usr/yong.cao/ftp/
total 19320
-rw-r--r-- 1 root root 88623 Jun 13 22:33 593d8f1eN5b3b8133.jpg
drwxr-xr-x 10 root root 258 Jun 14 01:26 fastdfs-5.11
-rw-r--r-- 1 root root 421773 Jun 17 09:34 fastdfs-5.11.zip
-rw-r--r-- 1 root root 75491 Jun 17 09:34 fastdfs-client-java-master.zip
-rw-r--r-- 1 root root 22192 Jun 17 09:34 fastdfs-nginx-module-master.zip
drwxr-xr-x 5 root root 135 Jun 8 21:51 libfastcommon-master
-rw-r--r-- 1 root root 478888 Jun 17 09:34 libfastcommon-master.zip
-rw-r--r-- 1 root root 980831 Jun 17 09:34 nginx-1.12.0.tar.gz
-rw-r--r--. 1 root root 150 Jun 4 12:19 record.txt
-rw-r--r--. 1 root root 17699306 Jun 4 13:32 zookeeper-3.4.6.tar.gz
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

1.2 模拟上传

确定图片位置后,我们输入上传图片命令:

/usr/bin/fdfs_upload_file  /etc/fdfs/client.conf  /usr/yong.cao/ftp/593d8f1eN5b3b8133.jpg  #这后面放的是图片的位置
  • 1

成功后会返回图片的路径:

[root@localhost ~]# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf  /usr/yong.cao/ftp/593d8f1eN5b3b8133.jpg
group1/M00/00/00/wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg
  • 1
  • 2

组名:group1 
磁盘:M00 
目录:00/00 
文件名称:wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg

我们上传的图片会被上传到我们创建的storage_data目录下,让我们去看看:

[root@localhost fastdfs_storage_data]# cd /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data
[root@localhost data]# ls
00 0D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9 B6 C3 D0 DD EA F7
01 0E 1B 28 35 42 4F 5C 69 76 83 90 9D AA B7 C4 D1 DE EB F8
02 0F 1C 29 36 43 50 5D 6A 77 84 91 9E AB B8 C5 D2 DF EC F9
03 10 1D 2A 37 44 51 5E 6B 78 85 92 9F AC B9 C6 D3 E0 ED FA
04 11 1E 2B 38 45 52 5F 6C 79 86 93 A0 AD BA C7 D4 E1 EE FB
05 12 1F 2C 39 46 53 60 6D 7A 87 94 A1 AE BB C8 D5 E2 EF FC
06 13 20 2D 3A 47 54 61 6E 7B 88 95 A2 AF BC C9 D6 E3 F0 FD
07 14 21 2E 3B 48 55 62 6F 7C 89 96 A3 B0 BD CA D7 E4 F1 FE
08 15 22 2F 3C 49 56 63 70 7D 8A 97 A4 B1 BE CB D8 E5 F2 FF
09 16 23 30 3D 4A 57 64 71 7E 8B 98 A5 B2 BF CC D9 E6 F3 M00
0A 17 24 31 3E 4B 58 65 72 7F 8C 99 A6 B3 C0 CD DA E7 F4
0B 18 25 32 3F 4C 59 66 73 80 8D 9A A7 B4 C1 CE DB E8 F5
0C 19 26 33 40 4D 5A 67 74 81 8E 9B A8 B5 C2 CF DC E9 F6
[root@localhost data]# cd 00
[root@localhost 00]# ls
00 0D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9 B6 C3 D0 DD EA F7
01 0E 1B 28 35 42 4F 5C 69 76 83 90 9D AA B7 C4 D1 DE EB F8
02 0F 1C 29 36 43 50 5D 6A 77 84 91 9E AB B8 C5 D2 DF EC F9
03 10 1D 2A 37 44 51 5E 6B 78 85 92 9F AC B9 C6 D3 E0 ED FA
04 11 1E 2B 38 45 52 5F 6C 79 86 93 A0 AD BA C7 D4 E1 EE FB
05 12 1F 2C 39 46 53 60 6D 7A 87 94 A1 AE BB C8 D5 E2 EF FC
06 13 20 2D 3A 47 54 61 6E 7B 88 95 A2 AF BC C9 D6 E3 F0 FD
07 14 21 2E 3B 48 55 62 6F 7C 89 96 A3 B0 BD CA D7 E4 F1 FE
08 15 22 2F 3C 49 56 63 70 7D 8A 97 A4 B1 BE CB D8 E5 F2 FF
09 16 23 30 3D 4A 57 64 71 7E 8B 98 A5 B2 BF CC D9 E6 F3
0A 17 24 31 3E 4B 58 65 72 7F 8C 99 A6 B3 C0 CD DA E7 F4
0B 18 25 32 3F 4C 59 66 73 80 8D 9A A7 B4 C1 CE DB E8 F5
0C 19 26 33 40 4D 5A 67 74 81 8E 9B A8 B5 C2 CF DC E9 F6
[root@localhost 00]# cd 00
[root@localhost 00]# ls
wKiAg1lE9WqAWu_ZAAFaL_xdW_s943.jpg
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

果然通过刚刚返回的路径,我们成功找到了图片。

我们仔细看一下,实际文件存储路径下有创建好的多级目录。data下有256个1级目录,每级目录下又有256个2级子目录,总共65536个文件,新写的文件会以hash的方式被路由到其中某个子目录下,然后将文件数据直接作为一个本地文件存储到该目录中。

1.3 HTTP访问文件

我们去浏览器用http请求访问一下刚刚的图片: 

我们发现,http不能直接访问到图片。这是为什么呢。 
我去官网看了一原码,在HISTORY中发现,原来早在4.05的时候,就remove embed HTTP support

Version 4.05  2012-12-30
* client/fdfs_upload_file.c can specify storage ip port and store path index
* add connection pool
* client load storage ids config
* common/ini_file_reader.c does NOT call chdir
* keep the mtime of file same
* use g_current_time instead of call time function
* remove embed HTTP support
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

1.4 HTTP请求不能访问文件的原因

我们在使用FastDFS部署一个分布式文件系统的时候,通过FastDFS的客户端API来进行文件的上传、下载、删除等操作。同时通过FastDFS的HTTP服务器来提供HTTP服务。但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者——淘宝的架构师余庆同学,为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块)。 
FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组之间的服务器需要复制文件,有延迟的问题.假设Tracker服务器将文件上传到了192.168.128.131,文件ID已经返回客户端,这时,后台会将这个文件复制到192.168.128.131,如果复制没有完成,客户端就用这个ID在192.168.128.131取文件,肯定会出现错误。这个fastdfs-nginx-module可以重定向连接到源服务器取文件,避免客户端由于复制延迟的问题,出现错误。 
正是这样,FastDFS需要结合nginx,所以取消原来对HTTP的直接支持。

2. FastDFS的nginx模块安装

2.1安装nginx准备

安装需要的工具,之前就已经放到了ftp:

[root@localhost dev]# cd /usr/yong.cao/ftp/
[root@localhost ftp]# ls
593d8f1eN5b3b8133.jpg libfastcommon-master
fastdfs-5.11 libfastcommon-master.zip
fastdfs-5.11.zip nginx-1.12.0.tar.gz
fastdfs-client-java-master.zip record.txt
fastdfs-nginx-module-master.zip zookeeper-3.4.6.tar.gz
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在安装nginx之前要安装nginx所需的依赖lib:

yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
  • 1
  • 2
  • 3

2.2 安装nginx并添加fastdfs-nginx-module

解压nginx,和fastdfs-nginx-module:

tar -zxvf nginx-1.12.0.tar.gz
unzip fastdfs-nginx-module-master.zip
  • 1
  • 2

解压后进入nginx目录编译安装nginx,并添加fastdfs-nginx-module:

./configure --prefix=/usr/local/nginx --add-module=/usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src    #解压后fastdfs-nginx-module所在的位置
  • 1

如果配置不报错的话,就开始编译:

make
make install
  • 1
  • 2

如果报错的话,很可能是版本的原因,在我的第二篇博文中提供了我测试成功不报错的版本下载。 
nginx的默认目录是/usr/local/nginx,安装成功后查看:

[root@localhost nginx-1.12.0]# cd /usr/local/nginx
[root@localhost nginx]# ll
total 0
drwx------ 2 nobody root 6 Jun 14 01:58 client_body_temp
drwxr-xr-x 2 root root 333 Jun 16 21:42 conf
drwx------ 2 nobody root 6 Jun 14 01:58 fastcgi_temp
drwxr-xr-x 2 root root 40 Jun 14 01:31 html
drwxr-xr-x 2 root root 58 Jun 15 22:21 logs
drwx------ 2 nobody root 6 Jun 14 01:58 proxy_temp
drwxr-xr-x 2 root root 19 Jun 14 01:31 sbin
drwx------ 2 nobody root 6 Jun 14 01:58 scgi_temp
drwx------ 2 nobody root 6 Jun 14 01:58 uwsgi_temp
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2.3 配置storage nginx

修改nginx.conf:

[root@localhost nginx]# cd conf/
[root@localhost conf]# ls
fastcgi.conf koi-win scgi_params
fastcgi.conf.default mime.types scgi_params.default
fastcgi_params mime.types.default uwsgi_params
fastcgi_params.default nginx.conf uwsgi_params.default
koi-utf nginx.conf.default win-utf
[root@localhost conf]# vim nginx.conf
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

修改监听端口 listen 9999, 新增location

server {
listen 9999;
server_name localhost; location / {
root html;
index index.html index.htm;
} location ~/group1/M00 {
root /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data;
ngx_fastdfs_module;
} location = /50x.html {
root html;
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

然后进入FastDFS安装时的解压过的目录,将http.conf和mime.types拷贝到/etc/fdfs目录下:

[root@localhost fastdfs-5.11]# cd /usr/yong.cao/ftp/fastdfs-5.11/conf/
[root@localhost conf]# ls
anti-steal.jpg http.conf storage.conf tracker.conf
client.conf mime.types storage_ids.conf
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

另外还需要把fastdfs-nginx-module安装目录中src目录下的mod_fastdfs.conf也拷贝到/etc/fdfs目录下:

cp /usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
  • 1

对刚刚拷贝的mod_fastdfs.conf文件进行修改:

vim /etc/fdfs/mod_fastdfs.conf
  • 1
 base_path=/usr/yong.cao/dev/fastdfs/fastdfs_storage  #保存日志目录
tracker_server=192.168.128.131:22122 #tracker服务器的IP地址以及端口号
storage_server_port=23000 #storage服务器的端口号
url_have_group_name = true #文件 url 中是否有 group 名
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data #存储路径
group_count = 3 #设置组的个数,事实上这次只使用了group1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在文件的最后,设置group

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/yuqing/fastdfs
store_path1=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data # group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data [group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/usr/yong.cao/dev/fastdfs/fastdfs_storage_data
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

创建M00至storage存储目录的符号连接:

ln  -s  /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data/ /usr/yong.cao/dev/fastdfs/fastdfs_storage_data/data/M00
  • 1

启动nginx:

/usr/local/nginx/sbin/nginx
  • 1

成功启动:

[root@localhost conf]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=8142
  • 1
  • 2

恭喜你,storage的nginx已配置成功。接下来,我们还要继续配置tracker的nginx。

2.4 配置tracker nginx

再解压一个nginx: 
我在我自己的工作下再建了一个nginx2,把原来的nginx-1.12.0.tar.gz又解压了一份到里面

fastdfs  nginx  nginx2  zookeeper
[root@localhost dev]# cd /usr/yong.cao/dev
[root@localhost dev]# ls
fastdfs nginx nginx2 zookeeper
  • 1
  • 2
  • 3
  • 4

配置:

[root@localhost ftp]# cd /usr/yong.cao/dev/nginx2/nginx-1.12.0/
[root@localhost nginx-1.12.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
./configure --prefix=/usr/local/nginx2 --add-module=/usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src #解压后fastdfs-nginx-module所在的位置
  • 1
  • 2
  • 3
  • 4
  • 5

编译:

make
make install
  • 1
  • 2

接下来,一样的还是修改nginx.conf,端口号可以不改,用80的。需将upstream指向tracker的nginx地址。

vim /usr/local/nginx2/conf/nginx.conf

 upstream fdfs_group1 {
server 127.0.0.1:9999;
}
server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location /group1/M00 {
proxy_pass http://fdfs_group1;
}
#location / {
# root html;
# index index.html index.htm;
#} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

启动nginx:

/usr/local/nginx/sbin/nginx2
  • 1

可以成功访问。

2.5 防火墙端口设置

成功了,为什么还要讲这个呢。因为有些同学到这里,还是不到访问,很可能是防火墙没有开启相应的端口。防火墙这个东西我建议大家还是不要关闭,虽然麻烦了一点。

查看已开启的端口:

[root@localhost nginx-1.12.0]# firewall-cmd --zone=public --list-ports
20880/tcp 80/tcp 2181/tcp 23000/tcp 22122/tcp 9999/tcp
[root@localhost nginx-1.12.0]#
  • 1
  • 2
  • 3

在我的CentOS上这些端口都是开放的。 
storage:20880 
tracker:23000 
这两个端口要开启,到时候下一篇讲fastdfs-client-javas可能会造成无法连接。 
9999和80端口是提供给nginx访问的。 
开放端口号命令:–permanent表示永久生效,不加的话,重启后不生效

firewall-cmd --zone=public --add-port=23000/tcp --permanent #开户端口号
  • 1

CentOS7 防火墙相关命令:

systemctl enable firewalld.service    #开启防火墙
systemctl stop firewalld.service #关闭防火墙(开机会仍会启动)
systemctl disable firewalld.service #禁用防火墙(开机后不再启动)
  • 1
  • 2
  • 3

2.6 HTTP测试

现在我们再去访问一下,原来我们上传过的文件: 

这个时候已经能成功访问。感谢你能坚持到现在,FastDFS已部署完成。

fastdfs5.11+centos7.2 按照部署(三)【转载】的更多相关文章

  1. fastdfs5.11+centos7.2 按照部署(二)【转载】

    https://files.cnblogs.com/files/xiaojf/nginx-1.12.0.tar.gz https://files.cnblogs.com/files/xiaojf/li ...

  2. fastdfs5.11+centos7.2 按照部署(一)【转载】

    1.绪论 最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的过程中遇到过很多的问题,为了能帮忙到以后搭建FastDFS的同学,少走弯路,与大家分享一下.FastDFS的作者淘宝资深架 ...

  3. Hadoop生态圈-CentOs7.5单机部署ClickHouse

    Hadoop生态圈-CentOs7.5单机部署ClickHouse 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 到了新的公司,认识了新的同事,生产环境也得你去适应新的集群环境,我 ...

  4. Hadoop 完全分布式部署(三节点)

    用来测试,我在VMware下用Centos7搭起一个三节点的Hadoop完全分布式集群.其中NameNode和DataNode在同一台机器上,如果有条件建议大家把NameNode单独放在一台机器上,因 ...

  5. 在CentOS7 开发与部署 asp.net core app笔记

    原文:在CentOS7 开发与部署 asp.net core app笔记 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lihongzhai/art ...

  6. centos7 下zookeeper 部署 单机多实例模式

    centos7 下zookeeper 部署 本文参考https://www.linuxidc.com/Linux/2016-09/135052.htm 1.创建/usr/local/zookeeper ...

  7. centos7 下 安装部署nginx

    centos7 下 安装部署nginx 1.nginx安装依赖于三个包,注意安装顺序 a.SSL功能需要openssl库,直接通过yum安装: #yum install openssl b.gzip模 ...

  8. CentOS7.4安装部署openstack [Liberty版] (二)

    继上一篇博客CentOS7.4安装部署openstack [Liberty版] (一),本篇继续讲述后续部分的内容 一.添加块设备存储服务 1.服务简述: OpenStack块存储服务为实例提供块存储 ...

  9. CentOS7.4安装部署openstack [Liberty版] (一)

    一.OpenStack简介 OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. OpenStack是一个 ...

随机推荐

  1. 【bzoj3567】江南乐

    Portal -->bzoj3567 Solution ​  今天开始啃博弈论了qwq ​  先mark一篇很棒的博客Portal -->博弈论学习资料 ​​  稍微总结一下两个自己容易混 ...

  2. 学习笔记:使用opencv做双目测距(相机标定+立体匹配+测距).

    最近在做双目测距,觉得有必要记录点东西,所以我的第一篇博客就这么诞生啦~ 双目测距属于立体视觉这一块,我觉得应该有很多人踩过这个坑了,但网上的资料依旧是云里雾里的,要么是理论讲一大堆,最后发现还不知道 ...

  3. selenium - 查看selenium版本信息

    1. pip list 2. pip show selenium 3. cmd>>python >>> import selenium>>> help( ...

  4. git 列出两个 commit 之间变更的文件列表

    git diff <commit1> <commit2> --stat 如: git diff 74ecf17dc 1ee25ed3c --stat src/assets 上面 ...

  5. OA项目中的论坛模块设计与实现

    1.论坛是什么?论坛与贴吧有什么区别? 简单的说论坛和贴吧都是发表言论和讨论的一个平台. 贴吧是论坛的一个部分. 2.关于论坛模块的需求分析? 首先我们看看论坛的几个设计页面: 这个主要是论坛的版块设 ...

  6. array_unique后,数组本身的值并不会变

    <?php $arr = [ ' ]; print_r($arr); print_r(array_unique($arr)); print_r($arr); //array_unique后,数组 ...

  7. 赤池信息量准则 ( Akaike information criterion)

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  8. 线上Redis偶发性链接失败排查记

    问题过程 输入法业务于12月12日上线了词库接受业务,对部分用户根据用户uuid判断进行回传,在12月17日早上8点多开始出现大量的php报错(Redis went away),报错导致了大量的链接积 ...

  9. UVA 818 Cutting Chains

    https://vjudge.net/problem/UVA-818 题意: 有n个圆环,其中有一些已经扣在了一起.现在需要打开尽量少的圆环,使得所有圆环可以组成一条链 n<=15 因为n< ...

  10. 「LibreOJ β Round #4」子集

    https://loj.ac/problem/526 题目描述 qmqmqm有一个长为 n 的数列 a1,a2,……,an,你需要选择集合{1,2,……,n}的一个子集,使得这个子集中任意两个元素 i ...