# fastdfs **Repository Path**: WendleXu/fastdfs ## Basic Information - **Project Name**: fastdfs - **Description**: fastdfs - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # fastdfs ## 1.1安装基础软件包 ``` yum -y install epel-release git yum install -y gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel readline-devel ncurses-devel libtermcap-devel ncurses-devel libevent-devel ``` ## 1.2 安装FastDFS ```shell cd /usr/local/src/fastdfs wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz tar -zxvf V5.11.tar.gz cd fastdfs-5.11 ./make.sh && ./make.sh install #配置文件准备 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf cp /usr/local/src/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs cp /usr/local/src/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs ``` 修改tracker配置 ```shell vim /etc/fdfs/tracker.conf #需要修改的内容如下 port=22122 base_path=/home/fastdfs ``` 修改storage配置 ```shell vim /etc/fdfs/storage.conf #需要修改的内容如下 port=23000 base_path=/home/fastdfs # 数据和日志文件存储根目录 store_path0=/home/fastdfs # 第一个存储目录 tracker_server=47.96.102.130:22122 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致) http.server_port=8888 ``` 启动tracker和storage ```shell mkdir /home/fastdfs -p /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart ``` 测试上传功能 ``` vim /etc/fdfs/client.conf #需要修改的内容如下 base_path=/home/fastdfs #tracker服务器IP和端口 tracker_server=47.96.102.130:22122 #保存后测试,返回ID表示成功 如:group1/M00/00/00/xxx.png /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/fastdfs/timg.jpg group1/M00/00/00/rBDFx18F37WAFRcQAACC3jMCN7Q589.jpg ``` ## **1.3下载lua、GraphicsMagick相关软件** ```shell cd /usr/local/src wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz wget https://ftp.pcre.org/pub/pcre/pcre-8.35.tar.gz wget http://www.lua.org/ftp/lua-5.3.1.tar.gz wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.18.tar.gz wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz git clone https://github.com/simpl/ngx_devel_kit.git git clone https://github.com/openresty/lua-nginx-module.git ``` ## 1.4 编译安装Lua、GraphicsMagick ```shell tar -zxvf LuaJIT-2.0.4.tar.gz tar -zxvf zlib-1.2.8.tar.gz cd LuaJIT-2.0.4 make && make install export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0 ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2 cd .. tar -zxvpf lua-5.3.1.tar.gz cd lua-5.3.1 make linux && make install cd .. tar -zxvpf GraphicsMagick-1.3.18.tar.gz cd GraphicsMagick-1.3.18 ./configure --prefix=/usr/local/GraphicsMagick --enable-shared make && make install ``` ## 1.5 Nginx动态添加模块 ```shell #先停止nginx ps -ef|grep nginx kill pid #进入nginx的源码目录下执行以下命令 ./configure --prefix=/usr/local/nginx \ --add-module=/usr/local/src/echo-nginx-module \ --add-module=/usr/local/src/lua-nginx-module-0.10.9rc7 \ --add-module=/usr/local/src/ngx_devel_kit \ --add-module=/usr/local/src/fastdfs/fastdfs-nginx-module-1.20/src #编译安装 make #查看模块是否安装上 /usr/local/nginx/sbin/nginx -V ``` ## 1.6 Lua+GraphicsMagick动态生成缩略图 lua脚本地址:链接: https://pan.baidu.com/s/1bRSK240OAIM5WbC0VZ6e7Q 密码: mm6f 将此文件下载后解压会有生成缩略图的lua脚本 将脚本上传到服务器上,我上传到了/usr/local/nginx/conf/lua/cropSize.lua 然后修改此文件的配置 ```lua vim /usr/local/nginx/conf/lua/cropSize.lua #52行 GraphicsMagick路径修改成前面安装GraphicsMagick编译后的路径 local gm_path = '/usr/local/GraphicsMagick/bin/gm' ``` 修改nginx配置 ```shell vim /usr/local/nginx/conf/nginx.conf server { listen 8888; server_name localhost; set $img_thumbnail_root /home/fastdfs/thumb; #缩略图保存的根目录 set $img_file $img_thumbnail_root$uri; #缩略图路径 # 缩略图访问:/group1/M00/xx/xx/xx.jpg_200x100.jpg location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png))$ { root $img_thumbnail_root; set $fdfs_group_root /home/fastdfs/data; if (!-f $img_file) { set $request_filepath $fdfs_group_root$4; # real file path set $img_width $6; # img width set $img_height $7; # img height set $img_ext $5; # file ext content_by_lua_file /usr/local/src/lua/cropSize.lua; } } location ~/group[0-9]/ { ngx_fastdfs_module; } } #重启nginx /usr/local/nginx/sbin/nginx -s reload ```