fastdfs简介
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。 Tracker Server:跟踪服务器,主要做调度工作,在访问上起到负载均衡的作用。在内存中记录集群中group和storage server的信息,是连接client和storage servery的枢纽。tracker性能是非常高的,二三台tracker就可以管理上百个group。 Storage Server:存储服务器,文件和文件属性都保存到存储服务器上。 所有的服务器是对等的,不存在mater-slave的关系,存储服务器采用分组的方式,同组之间文件完全相同,raid1。不同组storage server不会通信,是有storage server主动向tracker server报告状态,tracker server之间不会通信。 准备安装1、环境准备由于机器有限,我这使用二台服务器做实验,他们既做tracker,也做storage。 server01 IP:10.0.0.31 server02 IP:10.0.0.32 [root@nfs1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@nfs1 ~]# uname -r 3.10.0-327.el7.x86_64 [root@nfs1 ~]# getenforce Disabled [root@nfs1 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) #注意:磁盘空间留多一些,不然storage会报错。 2、安装fastdfs安装依赖 [root@nfs1 ~]# cd /usr/local/src/ [root@nfs1 ~]# git clone https://github.com/happyfish100/libfastcommon.git [root@nfs1 ~]# cd libfastcommon/ [root@nfs1 ~]# ./make.sh [root@nfs1 ~]# ./make.sh install #make报错需要安装yum install gcc gcc-c++ make -y 安装fastdfs,这次用的版本是5.0.4 [root@nfs1 ~]# cd /usr/local/src/ [root@nfs1 ~]# wget https://github.com/happyfish100/fastdfs/archive/V5.04.tar.gz [root@nfs1 ~]# tar xf V5.04.tar.gz [root@nfs1 ~]# cd fastdfs-5.04/ [root@nfs1 ~]# ./make.sh [root@nfs1 ~]# ./make.sh install 这个版本的坑(启动命令中路径不对): [root@nfs1 ~]# sed -i 's#/usr/local/bin#/usr/bin#g' /etc/init.d/fdfs_trackerd [root@nfs1 ~]# sed -i 's#/usr/local/bin#/usr/bin#g' /etc/init.d/fdfs_storaged #需要将/usr/local/bin修改为/usr/bin 3、配置环境tracker配置文件 [root@nfs1 ~]# cd /etc/fdfs/ [root@nfs1 ~]# cp tracker.conf.sample tracker.conf [root@nfs1 ~]# mkdir /data/fdfs/tracker -p [root@nfs1 ~]# vim tracker.conf ...... 22 base_path=/data/fdfs/tracker ...... [root@nfs1 fdfs]# /etc/init.d/fdfs_trackerd start storage配置文件 [root@nfs1 fdfs]# cd /etc/fdfs [root@nfs1 fdfs]# mkdir /data/fdfs/storage/base -p [root@nfs1 fdfs]# mkdir /data/fdfs/storage/store -p [root@nfs1 fdfs]# cp storage.conf.sample storage.conf [root@nfs1 fdfs]# vim storage.conf ... 37 base_path=/data/fdfs/storage/base 105 store_path0=/data/fdfs/storage/store ... 114 tracker_server=10.0.0.31:22122 115 tracker_server=10.0.0.32:22122 ... [root@nfs1 fdfs]# /etc/init.d/fdfs_storaged start client配置文件 [root@nfs1 fdfs]# mkdir /data/fdfs/client [root@nfs1 fdfs]# cp client.conf.sample client.conf [root@nfs1 fdfs]# vim client.conf ... 10 base_path=/data/fdfs/client 14 tracker_server=10.0.0.31:22122 15 tracker_server=10.0.0.32:22122 ... 好的,配置成功了,参数我在这里不解释了,可参看http://bbs./forum.php?mod=viewthread&tid=1941456&extra=page%3D1%26filter%3Ddigest%26digest%3D1 4、使用操作[root@nfs1 fdfs]# /etc/init.d/fdfs_trackerd status [root@nfs1 fdfs]# /etc/init.d/fdfs_storaged status #在操作前我们可以看看这两个服务是不是起来了,如果没有起来,查看日志 [root@nfs1 fdfs]# tailf /data/fdfs/tracker/logs/trackerd.log [root@nfs1 fdfs]# tailf /data/fdfs/storage/base/logs/storaged.log ##############我是分割线################### [root@nfs1 fdfs]# fdfs_monitor /etc/fdfs/client.conf server_count=2, server_index=1 tracker server is 10.0.0.32:22122 group count: 1 Group 1: group name = group1 disk total space = 28657 MB disk free space = 26333 MB trunk free space = 0 MB storage server count = 2 active server count = 2 storage server port = 23000 storage HTTP port = 8888 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0 Storage 1: id = 10.0.0.31 ip_addr = 10.0.0.31 (nfs1) ACTIVE ... Storage 2: id = 10.0.0.32 ip_addr = 10.0.0.32 ACTIVE 5、常用命令#可以查看命令帮助
fdfs_upload_file
#上传文件
fdfs_upload_file /etc/fdfs/client.conf file
#下载文件
fdfs_download_file
#查看信息
fdfs_file_info
#删除文件
fdfs_delete_file
#添加追加文件
fdfs_upload_appender /etc/fdfs/client.conf appent.txt
#追加内容
fdfs_append_file /etc/fdfs/client.conf file_id appent2.txt
#监控状态
fdfs_monitor /etc/fdfs/client.conf
#所有的命令都是需要接上配置文件的。
安装nginx模块 我们在使用FastDFS部署一个分布式文件系统的时候,通过FastDFS的客户端API来进行文件的上传、下载、删除等操作。同时通过FastDFS的HTTP服务器来提供HTTP服务。但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块),其使用非常简单。 #fastdfs-nginx-module下载地址:链接:https://pan.baidu.com/s/1fngCkQeWKW6HiCdDwyRK8Q 密码:v85v 将下好的fastdfs-nginx-module模块上传至服务器,解压,然后安装nginx 1、查看nginx和fastdfs模块 nginx的http_image_filter_module模块说明http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时缩放图片,旋转图片,验证图片有效性以及获取图片宽高以及图片类型信息。 http_image_filter_module模块的参数说明image_filter off; #关闭模块 image_filter test; #确保图片是jpeg gif png否则返415错误 image_filter size; #输出有关图像的json格式:例如以下显示{ "img" : { "width": 100, "height": 100, "type": "gif" } } 出错显示:{} image_filter rotate 90|180|270; #旋转指定度数的图像,參数能够包括变量,单独或一起与resize crop一起使用。 image_filter resize width height; #按比例降低图像到指定大小,公降低一个能够还有一个用"-"来表示,出错415,參数值可包括变量,能够与rotate一起使用,则两个一起生效。 image_filter crop width height; #按比例降低图像比較大的側面积和还有一側多余的载翦边缘,其他和rotate一样。没太理解 image_filter_buffer 10M; #设置读取图像缓冲的最大大小,超过则415错误。 image_filter_interlace on; #假设启用,终于的图像将被交错。对于JPEG,终于的图像将在“渐进式JPEG”格式。 image_filter_jpeg_quality 95; #设置变换的JPEG图像的期望质量。可接受的值是从1到100的范围内。较小的值通常意味着既降低图像质量,降低数据传输,推荐的最大值为95。參数值能够包括变量。 image_filter_sharpen 100; #添加了终于图像的清晰度。锐度百分比能够超过100。零值将禁用锐化。參数值能够包括变量。 image_filter_transparency on; #定义是否应该透明转换的GIF图像或PNG图像与调色板中指定的颜色时,能够保留。透明度的损失将导致更好的图像质量。在PNG的Alpha通道总是保留透明度。 再前面编译nginx已经制定了http_image_filter_module模块了,http_image_filter_module模块依赖gd-devel包所以需要安装gd-devel包(前面也已经安装了) nginx实现图片缩略图的配置如下:# cat /usr/local/nginx/conf/nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /usr/local/nginx/logs/error.log; pid /run/nginx.pid; /usr/share/nginx/README.dynamic. events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/nginx/logs/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /usr/local/nginx-1.13.7/conf/mime.types; default_type application/octet-stream; server { listen 80; server_name localhost; root /data/nginx/resource; location ~* \.(eot|ttf|woff|woff2|svg|otf)$ { root /data/nginx/resource/; add_header Access-Control-Allow-Origin *; } location static/* { root /data/nginx/resource/; } location ~ group1/M00/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) { #这段往下为生成缩略图的配置 alias /data0/fastdfs/storage/storage0/data; ngx_fastdfs_module; set $w $2; set $h $3; if ($w != "0") { rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break; } if ($h != "0") { rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break; } image_filter resize $w $h; image_filter_buffer 2M; try_files group1/M00$1.$4 $1.jpg; } location ~ group1/M00/(.+)\.?(.+){ alias /data0/fastdfs/storage/storage0/data; ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 配置后重启nginx!!! # /usr/local/nginx/sbin/nginx -s reload 往fastdfs中上传图片 # fdfs_upload_file /etc/fdfs/client.conf test.png group1/M00/00/00/wKgCEVvGzDSAJROvAAHgQeZ5IGY364.png 访问图片 1、访问原图:www.71net.com/group1/M00/00/00/wKgCEVvGzDSAJROvAAHgQeZ5IGY364.png 其中www.71net.com为你的域名或IP地址 2、访问缩略图
|
|