如何安装FastDFS
前言
本文基于CentOS6.5安装
FastDFS方案
主机IP | 名称 |
---|---|
192.168.1.1 | trackerd |
192.168.1.2 | storaged |
环境准备
下载软件:
libfastcommon-master.zip
FastDFS_v5.05.tar
fastdfs-nginx-module_v1.16.tar
fastdfs_client_v1.24.jar
安装gcc
命令:yum install make cmake gcc gcc-c++
解压libfastcommon
命令:unzip libfastcommon-master.zip -d /usr/local/fast/
关闭防火墙
在学习时可以不用考虑防火墙的问题
正文
安装libfastcommon
./make.sh ./make.sh install mkdir -p /usr/lib64 install -m 755 libfastcommon.so /usr/lib64 mkdir -p /usr/include/fastcommon
打印:
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_bits.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h /usr/include/fastcommon
注意安装的路径:libfastcommon默认安装到了/usr/lib64/这个位置。
进行软链接创建
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
安装FastDFS(同时进行)
解压
tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local/fast/
安装
cd /usr/local/fast/FastDFS ./make.sh ./make.sh install
打印:
mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_trackerd /usr/bin if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_storaged /usr/bin if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs mkdir -p /usr/lib64 cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender /usr/bin if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; fi if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; fi mkdir -p /usr/include/fastdfs cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi
服务脚本在:
ls /etc/init.d/ | grep fdfs fdfs_storaged fdfs_trackerd
配置文件在:
ls /etc/fdfs/ client.conf.sample storage.conf.sample tracker.conf.sample
命令行工具在/usr/bin/目录下
ls /usr/bin/ | grep fdfs fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_crc32 fdfs_delete_file fdfs_download_file fdfs_file_info fdfs_monitor fdfs_storaged fdfs_test fdfs_test1 fdfs_trackerd fdfs_upload_appender fdfs_upload_file
因为FastDFS服务脚本设置的bin目录为/usr/local/bin/下,但是实际我们安装在了/usr/bin/下面。所以我们需要修改FastDFS配置文件中的路径,也就是需要修改俩 个配置文件:
命令:vim /etc/init.d/fdfs_storaged
进行全局替换命令:%s+/usr/local/bin+/usr/bin
命令:vim /etc/init.d/fdfs_trackerd
进行全局替换命令:%s+/usr/local/bin+/usr/bin
配置跟踪器(trackerd)
修改配置文件
cd /etc/fdfs/ cp tracker.conf.sample tracker.conf vim /etc/fdfs/tracker.conf
修改
# the base path to store data and log files base_path=/fastdfs/tracker
mkdir -p /fastdfs/tracker
目录命令:cd /fastdfs/tracker/ && ll
启动tracker命令:/etc/init.d/fdfs_trackerd start
查看进程命令:ps -el | grep fdfs
停止tracker命令:/etc/init.d/fdfs_trackerd stop
查看是否启动成功
启动前:
cd /fastdfs/tracker/ && ll total 0
启动
/etc/init.d/fdfs_trackerd start
启动成功
cd /fastdfs/tracker/ && ll total 8 drwxr-xr-x. 2 root root 4096 Dec 14 20:48 data drwxr-xr-x. 2 root root 4096 Dec 14 20:48 logs
可以设置开机启动跟踪器:(一般生产环境需要开机启动一些服务,如keepalived、Nginx、tomcat等等)
命令:vim /etc/rc.d/rc.local
加入配置:/etc/init.d/fdfs_trackerd start
配置FastDFS存储(storaged)
修改配置文件storage.conf
进入文件目录:cd /etc/fdfs/,进行copy storage文件一份
命令:cd /etc/fdfs/
命令:cp storage.conf.sample storage.conf
命令:vim /etc/fdfs/storage.conf
修改内容:
base_path=/fastdfs/storage store_path0=/fastdfs/storage tracker_server=192.168.1.1:22122 http.server_port=80
创建存储目录:
mkdir -p /fastdfs/storage
启动存储(storage)
命令:/etc/init.d/fdfs_storaged start
查看是否启动成功
ps -ef | grep fdfs
可以设置开机启动跟踪器:(一般生产环境需要开机启动一些服务,如keepaliv ed、linux、tomcat等等)
命令:vim /etc/rc.d/rc.local
加入配置:/etc/init.d/fdfs_storaged start
测试
首先我们在跟踪器(tracker)里copy一份client.conf文件。
命令:cd /etc/fdfs/
命令:cp client.conf.sample client.conf
编辑client.conf文件
vim /etc/fdfs/client.conf
修改内容:
base_path=/fastdfs/tracker tracker_server=**192.168.1.1**:22122
测试上传
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/FastDFS/libfastcommon-master.zip
打印:
group1/M00/00/00/2-YyVlhRQlaAZLlgAAGP6hUWM6I411.zip
存储器查看文件
cd /fastdfs/storage/data/00/00/ && ll total 1 -rw-r--r--. 1 root root 102378 Dec 14 21:00 2-YyVlhRQlaAZLlgAAGP6hUWM6I411.zip
FastDFS与Nginx整合(Storage)
解压Nginx
tar -zxvf nginx-1.6.2.tar.gz
安装fastdfs-nginx-module_v1.16.tar.gz
tar -zxvf FastDFS/fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/ cd /usr/local/fast/fastdfs-nginx-module/src/
编辑配置文件config
vim /usr/local/fast/fastdfs-nginx-module/src/config
修改前: CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/" 修改后: CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
FastDFS与Nginx进行集成
cd nginx-1.6.2/
./configure –add-module=/usr/local/fast/fastdfs-nginx-module/src/
make && make install
如报错 自行安装pcre
复制、修改配置文件
cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10 tracker_server=192.168.1.1:22122 url_have_group_name = true store_path0=/fastdfs/storage
复制FastDFS里的2个文件
cd /usr/local/fast/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/
建立软连接
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
修改Nginx配置
vim nginx.conf
listen 80; server_name localhost; location ~/group([0-9])/M00 {ngx_fastdfs_module; }
启动Nginx
/usr/local/nginx/sbin/nginx
报错: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
32位系统 ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统ln -s /usr/local/lib/libpcre.so.1 /lib64
测试
访问 http://192.168.1.2/group1/M00/00/00/2-YyVlhRQlaAZLlgAAGP6hUWM6I411.zip
启动停止命令
启动命令: 启动tracker命令:/etc/init.d/fdfs_trackerd start
查看进程命令:ps -el | grep fdfs
启动storage命令:/etc/init.d/fdfs_storaged start
查看进程命令:ps -el | grep fdfs
启动nginx命令:/usr/local/nginx/sbin/nginx
停止命令: 停止tracker命令:/etc/init.d/fdfs_trackerd stop
关闭storage命令:/etc/init.d/fdfs_storaged stop
关闭nginx命令:/usr/local/nginx/sbin/nginx -s stop
使用Java客户端操作
classpath下建立文件fastdfs_client.conf
输入以下内容
tracker_server = 192.168.125.129:22122
package vip.xubin.utils;import org.apache.commons.lang3.StringUtils;import org.apache.log4j.Logger;import org.csource.common.NameValuePair;import org.csource.fastdfs.*;import java.io.*;/*** FastDFS 工具类*/public class FastDFSClientUtils {private static final String CONF_FILENAME = Thread.currentThread().getContextClassLoader().getResource("fastdfs_client.conf").getPath();private static Logger logger = Logger.getLogger(FastDFSClientUtils.class);private static TrackerClient trackerClient;//加载文件static {try {ClientGlobal.init(CONF_FILENAME);TrackerGroup trackerGroup = ClientGlobal.g_tracker_group;trackerClient = new TrackerClient(trackerGroup);} catch (Exception e) {logger.error(e);}}/*** 上传* @param file 文件* @param path 路径* @return* 上传成功返回id,失败返回null*/public static String upload(File file, String path) {TrackerServer trackerServer = null;StorageServer storageServer = null;StorageClient1 storageClient1 = null;FileInputStream fis = null;try {NameValuePair[] meta_list = null; // new NameValuePair[0];fis = new FileInputStream(file);byte[] file_buff = null;if (fis != null) {int len = fis.available();file_buff = new byte[len];fis.read(file_buff);}trackerServer = trackerClient.getConnection();if (trackerServer == null) {logger.error("getConnection return null");}storageServer = trackerClient.getStoreStorage(trackerServer);storageClient1 = new StorageClient1(trackerServer, storageServer);String fileid = storageClient1.upload_file1(file_buff, getFileExt(path), meta_list);return fileid;} catch (Exception ex) {logger.error(ex);return null;}finally{if (fis != null){try {fis.close();} catch (IOException e) {logger.error(e);}}if (storageServer != null){try {storageServer.close();} catch (IOException e) {e.printStackTrace();}}if (trackerServer != null){try {trackerServer.close();} catch (IOException e) {e.printStackTrace();}}storageClient1 = null;}}/*** 上传* @param data 数据* @param extName 路径* @return* 上传成功返回id,失败返回null*/public static String upload(byte[] data, String extName) {TrackerServer trackerServer = null;StorageServer storageServer = null;StorageClient1 storageClient1 = null;try {NameValuePair[] meta_list = null; // new NameValuePair[0];trackerServer = trackerClient.getConnection();if (trackerServer == null) {logger.error("getConnection return null");}storageServer = trackerClient.getStoreStorage(trackerServer);storageClient1 = new StorageClient1(trackerServer, storageServer);String fileid = storageClient1.upload_file1(data, extName, meta_list);return fileid;} catch (Exception ex) {logger.error(ex);return null;}finally{if (storageServer != null){try {storageServer.close();} catch (IOException e) {e.printStackTrace();}}if (trackerServer != null){try {trackerServer.close();} catch (IOException e) {e.printStackTrace();}}storageClient1 = null;}}/*** 下载* @param fileId 文件id* @return* 返回InputStream*/public static InputStream download(String groupName, String fileId) {TrackerServer trackerServer = null;StorageServer storageServer = null;StorageClient1 storageClient1 = null;try {trackerServer = trackerClient.getConnection();if (trackerServer == null) {logger.error("getConnection return null");}storageServer = trackerClient.getStoreStorage(trackerServer, groupName);storageClient1 = new StorageClient1(trackerServer, storageServer);byte[] bytes = storageClient1.download_file1(fileId);InputStream inputStream = new ByteArrayInputStream(bytes);return inputStream;} catch (Exception ex) {logger.error(ex);return null;} finally {if (storageServer != null){try {storageServer.close();} catch (IOException e) {e.printStackTrace();}}if (trackerServer != null){try {trackerServer.close();} catch (IOException e) {e.printStackTrace();}}storageClient1 = null;}}/*** 删除* @param fileId 文件id* @return* 删除成功返回0,非0则操作失败,返回错误代码*/public static int delete(String groupName, String fileId) {TrackerServer trackerServer = null;StorageServer storageServer = null;StorageClient1 storageClient1 = null;try {trackerServer = trackerClient.getConnection();if (trackerServer == null) {logger.error("getConnection return null");}storageServer = trackerClient.getStoreStorage(trackerServer, groupName);storageClient1 = new StorageClient1(trackerServer, storageServer);int result = storageClient1.delete_file1(fileId);return result;} catch (Exception ex) {logger.error(ex);return 0;} finally {if (storageServer != null){try {storageServer.close();} catch (IOException e) {e.printStackTrace();}}if (trackerServer != null){try {trackerServer.close();} catch (IOException e) {e.printStackTrace();}}storageClient1 = null;}}/*** 更新文件* @param oldFileId 旧文件id* @param file 新文件* @param path 新文件路径* @return* 上传成功返回id,失败返回null*/public static String modify(String oldGroupName, String oldFileId, File file, String path) {String fileid = null;try {// 先上传fileid = upload(file, path);if (fileid == null) {return null;}// 再删除int delResult = delete(oldGroupName, oldFileId);if (delResult != 0) {return null;}} catch (Exception ex) {logger.error(ex);return null;}return fileid;}/*** 获取文件后缀名* @param fileName* @return* 如:"jpg"、"txt"、"zip" 等*/private static String getFileExt(String fileName) {if (StringUtils.isBlank(fileName) || !fileName.contains(".")) {return "";} else {return fileName.substring(fileName.lastIndexOf(".") + 1);}}}
总结
FastDFS的安装算是比较麻烦的 不过按照本篇 一步一步来 是绝对可以安装成功的 集群的安装就更麻烦了 个人暂时用不到 就不安装了
参考
转载于:https://blog.51cto.com/4925054/2341886
如何安装FastDFS相关推荐
- CentOS 6.4 i386 版本安装 FastDFS、使用Nginx作为文件访问WEB服务器
安装环境: 1. CentOS-6.4-i386 2. FastDFS_v4.06 3. fastdfs-nginx-module_v1.15 4. Nginx-1.5.6(安装见此) 5. libe ...
- linux下载安装fastdfs和fastdfs与nginx整合、springboot访问fastdfs
文章目录 需求分析 分布式文件系统 1 FastDFS安装 FastDFS 和nginx整合 2.整合java访问fastdfs服务 文件上传查询下载测试 整合springboot 需求分析 搭建fa ...
- Ubuntu中安装FastDFS
1 安装fastdfs依赖包 解压缩libfastcommon-master.zip 进入到libfastcommon-master的目录中 执行 ./make.sh 执行 sudo ./make.s ...
- centos下安装fastdfs(笔记系列)
为什么80%的码农都做不了架构师?>>> 前言 本文只用于记录在centos下安装fastdfs的过程,仅用于笔记. 步骤 环境 笔者系统Cent OS6.8 x86_64,f ...
- FastDfs工作笔记001---Centos下安装FastDfs进行文件存储
JAVA技术交流QQ群:170933152 我按照下面这个就安装成功了,也没有碰到什么问题 参考文献:http://dorole.com/tag/fastdfs/ 安装编译环境 yum -y grou ...
- 使用docker安装fastDFS
1|01.安装fastdfs必要组件tracker不用改 docker run -d --network=host --name tracker -v /var/fdfs/tracker:/var/f ...
- php fastdfs扩展,php如何安装fastdfs扩展
php安装fastdfs扩展的方法:首先下载FastDFS源程序:然后将其放在"/usr/local/src"目录下:最后在"php.ini"配置文件中加载fa ...
- fastdfs暗转 linux_Linux下安装fastDFS
1.Linux下使用FastDFS 本教程所有操作均在CentOS 6.x环境下进行. 文件下载: 链接:https://pan.baidu.com/s/1vVEfCeOHnaftvV0DPtbgWg ...
- 在 OSX 10.9.4 上编译安装 FastDFS 及其 PHP 扩展
2019独角兽企业重金招聘Python工程师标准>>> 经我测试,在OSX 10.9.4上安装FastDFS V5.01的话会很悲剧,一开始就无法安装,会遇到这帖子中的问题:http ...
- 安装fastDFS的依赖包fdfs_client报错解决方法
安装fastDFS的依赖包fdfs_client报错解决方法 参考文章: (1)安装fastDFS的依赖包fdfs_client报错解决方法 (2)https://www.cnblogs.com/Se ...
最新文章
- 7-3 逆序的三位数 (Java)
- android studio中如何设置注释模板
- 请简单解释一下ARP协议和ARP攻击
- [2021.1.31多校省选模拟12]随机变换的子串(线段树维护分治/字符串/自动机思想)
- P5283-[十二省联考2019]异或粽子【可持久化Trie,堆】
- CVPR 2021 3D视觉相关最新进展分享
- 微信小程序制作-随笔4
- CRC源码生成工具,可生成Verilog和VHDL
- html背景透明图片不透明,html - css实现背景透明内容不透明。
- HQChart使用教程78-分时图集合竞价
- excel常用函数汇总 excel最常用的八个函数 excel自动求减
- python从0开始学编程第二天第19讲_少儿Python编程_第十九讲 数据分析网站
- 64位系统装32位计算机,64位电脑装32位系统,教您64位电脑怎么装32位系统
- 我是一名资深程序员,而今天我又多了一个创业者的身份(2)
- unity建立项目崩溃:failed to decompress
- 字节跳动智力题-分金块问题
- mysql数据库名称中包含短横线的对应方式
- k近邻法: k-nearest neighbor
- 版本回顾会_回顾Excel的早期版本
- html枪战游戏代码大全,3D枪战射击游戏cs简单版源代码