Linux下搭建单机版FastDFS

准备

安装gcc

yum install make cmake gcc gcc-c++

安装libfastcommon

下载

https://github.com/happyfish100/libfastcommon/releases
or
https://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/lib64
mkdir -p /usr/lib
install -m 755 libfastcommon.so /usr/lib64
install -m 755 libfastcommon.so /usr/lib
mkdir -p /usr/include/fastcommon
install -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/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
if [ ! -f /etc/fdfs/storage_ids.conf.sample ]; then cp -f ../conf/storage_ids.conf /etc/fdfs/storage_ids.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
mkdir -p /usr/lib
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; cp -f libfdfsclient.a /usr/lib/;fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib/;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
配置
  • 服务脚本
/etc/init.d/fdfs_trackerd
/etc/init.d/fdfs_storaged

ll /etc/init.d/ | grep fdfs
  • 配置文件
/etc/fdfs/tracker.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/client.conf.sample

cd /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/storage
store_path0=/fastdfs/storage
tracker_server=192.168.1.100:22122
http.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/tracker
tracker_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-module
https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/


cd /usr/local/soft

tar -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.conf

connect_timeout=10
tracker_server=192.168.1.100:22122
url_have_group_name = true
store_path0=/fastdfs/storage
保存


复制FastDFS里的2个文件,到/etc/fdfs目录中
cd /usr/local/fast/fastdfs-5.11/conf
cp http.conf mime.types /etc/fdfs/

cd /etc/fdfs/ && ll 


创建一个软连接,在/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录
命令: ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00


配置nginx.conf
cd /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
参考资料

http://blog.csdn.net/wlwlwlwl015/article/details/52619851 http://blog.csdn.net/xyang81/article/details/52837974

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值