博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下搭建单机版FastDFS
阅读量:6075 次
发布时间:2019-06-20

本文共 6892 字,大约阅读时间需要 22 分钟。

hot3.png

准备

安装gcc

yum install make cmake gcc gcc-c++

安装libfastcommon

下载

https://github.com/happyfish100/libfastcommon/releasesorhttps://sourceforge.net/projects/libfastcommon/files/?source=navbar

解压

unzip libfastcommon-*.zip -d /usr/local/fast/

安装

cd /usr/local/fast/libfastcommon-*

./make.sh

./make.sh install

执行结果:

mkdir -p /usr/lib64mkdir -p /usr/libinstall -m 755 libfastcommon.so /usr/lib64install -m 755 libfastcommon.so /usr/libmkdir -p /usr/include/fastcommoninstall -m 644 common_define.h ··· /usr/include/fastcommon

FastDFS

准备

下载

https://github.com/happyfish100/fastdfs/releases

解压

tar -zxvf fastdfs-5.11.tar.gz -C /usr/local/fast/

cd /usr/local/fast/fastdfs-5.11

安装

编译命令:

./make.sh

安装命令:

./make.sh install

执行结果:

mkdir -p /usr/binmkdir -p /etc/fdfscp -f fdfs_trackerd /usr/binif [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fiif [ ! -f /etc/fdfs/storage_ids.conf.sample ]; then cp -f ../conf/storage_ids.conf /etc/fdfs/storage_ids.conf.sample; fimkdir -p /usr/binmkdir -p /etc/fdfscp -f fdfs_storaged  /usr/binif [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fimkdir -p /usr/binmkdir -p /etc/fdfsmkdir -p /usr/lib64mkdir -p /usr/libcp -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/binif [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; cp -f libfdfsclient.a /usr/lib/;fiif [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib/;fimkdir -p /usr/include/fastdfscp -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/fastdfsif [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi

配置

  • 服务脚本
/etc/init.d/fdfs_trackerd/etc/init.d/fdfs_storagedll /etc/init.d/ | grep fdfs
  • 配置文件
/etc/fdfs/tracker.conf.sample/etc/fdfs/storage.conf.sample/etc/fdfs/client.conf.samplecd /etc/fdfs/ && ll
  • 命令行工具
usr/bin/目录下fdfs_*ll /usr/bin/ | grep fdfs-rwxr-xr-x    1 root root     255587 Feb 22 11:54 fdfs_appender_test-rwxr-xr-x    1 root root     255284 Feb 22 11:54 fdfs_appender_test1-rwxr-xr-x    1 root root     245716 Feb 22 11:54 fdfs_append_file-rwxr-xr-x    1 root root     245394 Feb 22 11:54 fdfs_crc32-rwxr-xr-x    1 root root     245807 Feb 22 11:54 fdfs_delete_file-rwxr-xr-x    1 root root     246606 Feb 22 11:54 fdfs_download_file-rwxr-xr-x    1 root root     246332 Feb 22 11:54 fdfs_file_info-rwxr-xr-x    1 root root     258972 Feb 22 11:54 fdfs_monitor-rwxr-xr-x    1 root root     872126 Feb 22 11:54 fdfs_storaged-rwxr-xr-x    1 root root     262027 Feb 22 11:54 fdfs_test-rwxr-xr-x    1 root root     261196 Feb 22 11:54 fdfs_test1-rwxr-xr-x    1 root root     368259 Feb 22 11:54 fdfs_trackerd-rwxr-xr-x    1 root root     246654 Feb 22 11:54 fdfs_upload_appender-rwxr-xr-x    1 root root     247784 Feb 22 11:54 fdfs_upload_file
配置跟踪器

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

vim /etc/fdfs/tracker.conf

修改为自己的路径地址: base_path=/fastdfs/tracker保存

mkdir -p /fastdfs/tracker

注意:对于tracker.conf配置文件参数解释可以找官方文档,地址为:http://bbs.chinaunix.net/thread-1941456-1-1.html

开放22122端口

vim /etc/sysconfig/iptables

添加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT重启: service iptables restart

启动跟踪器

启动tracker命令:

/etc/init.d/fdfs_trackerd start

查看进程命令:

ps -ef | grep fdfs

停止tracker命令:

/etc/init.d/fdfs_trackerd stop

可以设置开机启动跟踪器:(一般生产环境需要开机启动一些服务,如keepalived、 linux、 tomcat等等)命令: vim /etc/rc.d/rc.local加入配置: /etc/init.d/fdfs_trackerd start
配置存储器

cd /etc/fdfs/

cp storage.conf.sample storage.conf

vim /etc/fdfs/storage.conf

base_path=/fastdfs/storagestore_path0=/fastdfs/storagetracker_server=192.168.1.100:22122http.server_port=8888

mkdir /fastdfs/storage

开放23000端口

vim /etc/sysconfig/iptables

# 添加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

重启:

service iptables restart

启动:

/etc/init.d/fdfs_storaged start

关闭:

/etc/init.d/fdfs_storaged stop

查看FastDFS storage 是否启动成功命令:

ps -ef | grep fdfs

同理,也可以设置开机启动存储器:(一般生产环境需要开机启动一些服务,如keepalived、 linux、 tomcat等等)命令: vim /etc/rc.d/rc.local加入配置: /etc/init.d/fdfs_storaged start

测试

若跟踪器和存储器不在一个机器上,则需要注意,我们需要在跟踪器上进行测试

cd /etc/fdfs/

cp client.conf.sample client.conf

vim /etc/fdfs/client.conf

base_path=/fastdfs/trackertracker_server=192.168.1.100:22122

使用命令fdfs_upload_file进行上传操作

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/xxx.png

结果:

group1/M00/00/00/wKhkI1qOVqOAKL45AAMGL59aArk524.png到存储器下查看:cd /fastdfs/storage/data/00/00/ && ll-rw-r--r-- 1 root root 198191 Feb 22 13:35 wKhkI1qOVqOAKL45AAMGL59aArk524.png

FastDFS与Nginx整合

存储节点安装fastdfs-nginxmodule_v1.16.tar.gz包https://github.com/happyfish100/fastdfs-nginx-modulehttps://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/cd /usr/local/softtar -zxvf /usr/local/soft/fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/cd /usr/local/fast/fastdfs-nginx-module/src/vim config修改内容:去掉CORE_INCS中的local文件层次即CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"改为CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"若之前安装过nginx需要删除重新编译rm -rf nginx重新编译./configure 后面添加上--add-module=/usr/local/fast/fastdfs-nginx-module/src/如:./configure --sbin-path=/usr/local/nginx/nginx \--conf-path=/usr/local/nginx/nginx.conf \--pid-path=/usr/local/nginx/nginx.pid \--with-http_ssl_module \--with-pcre=/usr/local/src/pcre-8.41 \--with-zlib=/usr/local/src/zlib-1.2.11 \--with-openssl=/usr/local/src/openssl-1.0.2n \--add-module=/usr/local/fast/fastdfs-nginx-module/src/编译:make && make install复制fastdfs-ngin-module中的配置文件,到/etc/fdfs目录中cd /usr/local/fast/fastdfs-nginx-module/src/cp mod_fastdfs.conf /etc/fdfs/cd /etc/fdfs/vim mod_fastdfs.confconnect_timeout=10tracker_server=192.168.1.100:22122url_have_group_name = truestore_path0=/fastdfs/storage保存复制FastDFS里的2个文件,到/etc/fdfs目录中cd /usr/local/fast/fastdfs-5.11/confcp http.conf mime.types /etc/fdfs/cd /etc/fdfs/ && ll 创建一个软连接,在/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录命令: ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00配置nginx.confcd /usr/local/nginx/vim nginx.conf修改内容为:listen 8888;server_name localhost;location ~/group([0-9])/M00 {    #alias /fastdfs/storage/data;    ngx_fastdfs_module;}注意: nginx里的端口要和第五步配置FastDFS存储中的storage.conf文件配置一致,也就是(http.server_port=8888)启动nginx服务./nginx 打开浏览器访问http://192.168.100.35:8888/group1/M00/00/00/wKhkI1qOVqOAKL45AAMGL59aArk524.png注意:我们在使用FastDFS的时候,需要正常关机,不要使用kill -9强杀FastDFS进程,不然会在文件上传时出现丢数据的情况

java客户端 demo

参考资料

转载于:https://my.oschina.net/mengzhang6/blog/1622641

你可能感兴趣的文章
2017 Hackatari Codeathon B. 2Trees(深搜)(想法)
查看>>
单词统计
查看>>
输入一个数字计算圆的面积
查看>>
在Delphi中隐藏程序进程
查看>>
AngularJS PhoneCat代码分析
查看>>
maven错误解决:编码GBK的不可映射字符
查看>>
2016/4/19 反射
查看>>
SharePoint Wiki发布页面的“保存冲突”
查看>>
oracle 10g 数据库与客户端冲突导致实例创建无监听问题
查看>>
Delphi中读取文本文件的方法(实例一)
查看>>
Linux常用命令
查看>>
Android开源代码解读の使用TelephonyManager获取移动网络信息
查看>>
想说一点东西。。。。
查看>>
css知多少(8)——float上篇
查看>>
NLB网路负载均衡管理器详解
查看>>
水平添加滚动条
查看>>
PHP中”单例模式“实例讲解
查看>>
VS2008查看dll导出函数
查看>>
VM EBS R12迁移,启动APTier . AutoConfig错误
查看>>
atitit.细节决定成败的适合情形与缺点
查看>>