Fastdfs介绍

2017年12月15日12:34:52 发表评论 875 views

1.1 安装fastdfs

1.1.1 编译安装依赖包

[[email protected] ~]# cd /server/tools/
[[email protected] tools]# unzip libfastcommon-master.zip
[[email protected] tools]# cd libfastcommon-master/
[[email protected] libfastcommon-master]# ./make.sh
[[email protected] libfastcommon-master]# ./make.sh install

1.1.2 编译安装fastdfs

[[email protected] ~]# cd /server/tools/
[[email protected] tools]# unzip fastdfs-master.zip
[[email protected] tools]# cd fastdfs-master/
[[email protected] fastdfs-master]# ./make.sh
[[email protected] fastdfs-master]# ./make.sh install

1.2 配置fastdfs

1.2.1 创建相关目录

[[email protected] ~]# mkdir -p /data/fdfs_tracker
[[email protected] ~]# mkdir -p /data/fdfs_storage/{base,store}

1.2.2 备份配置文件

[[email protected] ~]# cp /etc/fdfs/storage.conf{.sample,}
[[email protected] ~]# cp /etc/fdfs/tracker.conf{.sample,}

1.2.3 编辑配置文件

1.2.3.1 编辑tracker配置文件

[[email protected] ~]# vim /etc/fdfs/tracker.conf
base_path=/data/fdfs_tracker
# 或
# [[email protected] ~]# sed -i 's#^base_path.*#base_path=/data/fdfs_tracker#g' /etc/fdfs/tracker.conf

1.2.3.2 编辑storage配置文件

[[email protected] ~]# vim /etc/fdfs/storage.conf
base_path=/data/fdfs_storage/base
store_path0=/data/fdfs_storage/store
tracker_server=10.0.0.211:22122
tracker_server=10.0.0.212:22122
# 或
# [[email protected] ~]# sed -i 's#^base_path.*#base_path=/data/fdfs_storage/base#;s#^store_path0.*#store_path0=/data/fdfs_storage/store#;[email protected][email protected]#[email protected];117a tracker_server=10.0.0.211:22122\ntracker_server=10.0.0.212:22122' /etc/fdfs/storage.conf

1.2.3.3 比较更改前后的配置文件

[[email protected] ~]# diff /etc/fdfs/tracker.conf{,.sample}
22c22
< base_path=/data/fdfs_tracker
---
> base_path=/home/yuqing/fastdfs
[[email protected] ~]# diff /etc/fdfs/storage.conf{,.sample}
41c41
< base_path=/data/fdfs_storage/base
---
> base_path=/home/yuqing/fastdfs
109c109
< store_path0=/data/fdfs_storage/store
---
> store_path0=/home/yuqing/fastdfs
118,119c118
< tracker_server=10.0.0.211:22122
< tracker_server=10.0.0.212:22122
---
> tracker_server=192.168.209.121:22122

1.3 启动服务并查看端口

1.3.1 启动服务

[[email protected] ~]# /etc/init.d/fdfs_trackerd start
[[email protected] ~]# /etc/init.d/fdfs_storaged start

1.3.2 查看开启的端口号

[[email protected] ~]# netstat -lntup | grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      2844/fdfs_trackerd 
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      2867/fdfs_storaged

1.4 配置客户端共享文件服务

1.4.1 备份客户端配置文件

[[email protected] ~]# cp /etc/fdfs/client.conf{.sample,}

1.4.2 编辑客户端配置文件

[[email protected] ~]# vim /etc/fdfs/client.conf
base_path=/tmp/
tracker_server=10.0.0.211:22122
tracker_server=10.0.0.212:22122
# 或
# [[email protected] ~]# sed -i 's#^base_path.*#base_path=/tmp/#;[email protected]^[email protected]#[email protected];13a tracker_server=10.0.0.211:22122\ntracker_server=10.0.0.212:22122' /etc/fdfs/client.conf

1.5 测试服务

1.5.1 查看集群服务详细信息

[[email protected] ~]# fdfs_monitor /etc/fdfs/client.conf
[2017-12-14 20:19:02] DEBUG - base_path=/tmp, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

server_count=2, server_index=0

tracker server is 10.0.0.211:22122

group count: 1

Group 1:

group name = group1
...省略部分输出内容...
    Storage 1:
        id = 10.0.0.211
        ip_addr = 10.0.0.211 (gluterfs01)  ACTIVE
...省略部分输出内容...
    Storage 2:
        id = 10.0.0.212
        ip_addr = 10.0.0.212 (gluterfs02)  ACTIVE
...省略部分输出内容...

1.5.2 上传文件测试

[[email protected] ~]# fdfs_upload_file /etc/fdfs/client.conf /var/log/messages
group1/M00/00/00/CgAA01oyaoKAF4RyAAALSBSzmYs3740004
[[email protected] ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/CgAA01oyaoKAF4RyAAALSBSzmYs3740004
source storage id: 0
source ip address: 10.0.0.211
file create timestamp: 2017-12-14 20:11:46
file size: 2888
file crc32: 347314571 (0x14B3998B)
[[email protected] ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/CgAA01oyaoKAF4RyAAALSBSzmYs3740004
[[email protected] ~]# md5sum /var/log/messages
f1a9e8a43529db1398384ea49812b409  /var/log/messages
[[email protected] ~]# md5sum CgAA01oyaoKAF4RyAAALSBSzmYs3740004
f1a9e8a43529db1398384ea49812b409  CgAA01oyaoKAF4RyAAALSBSzmYs3740004

1.5.3 测试追加文件

[[email protected] ~]# echo "hello" > a.txt
[[email protected] ~]# echo "world" > b.txt
[[email protected] ~]# fdfs_upload_appender /etc/fdfs/client.conf a.txt
group1/M00/00/00/CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt
[[email protected] ~]# fdfs_append_file /etc/fdfs/client.conf group1/M00/00/00/CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt b.txt
[[email protected] ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt
[[email protected] ~]# cat CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt
hello
world
[[email protected] ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt
source storage id: 0
source ip address: 10.0.0.212
file create timestamp: 2017-12-14 20:15:52
file size: 12
file crc32: 1998380320 (0x771CDD20)

1.5.4 删除共享文件

[[email protected] ~]# fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/CgAA1Foya1eEJDPkAAAAAHcc3SA118.txt

weinxin
我的微信
如果有技术上的问题可以扫一扫我的微信
版权声明
1. 本网站名称:Leon的博客
2. 本站永久网址:https://blog.leonshadow.cn
3. 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ632113590进行删除处理。
4. 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5. 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6. 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
liyang