环境:Centos 7 or Ubuntu
版本:
Fastdfs 6.06
libfastcommon 1.0.4
Fastdht
berkeley 6.2.38
dependency
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
mkdir /home/fdfs/tracker
mkdir /home/fdfs/storage/datas
libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
tar -zxvf V1.0.43.tar.gz
cd libfastcommon-1.0.43/
./make.sh
./make.sh install
如果提示未安装gcc等,直接使用yum命令进行安装
yum install -y gcc gcc-c++
Fastdfs
wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
tar -zxvf V6.06.tar.gz
cd fastdfs-6.06
./make.sh
./make.sh install
查看
ls -la /usr/bin/fdfs*
tracker
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim tracker.conf
# tracker 默认就是22122,可修改
port = 22122
# tracker文件的目录存放log
base_path = /home/fdfs/tracker
store_group=group1
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
netstat -apn | grep fdfs*
storage
# /etc/fdfs
cp storage.conf.sample storage.conf
vim storage.conf
# storage组名,同一组名的storage中的文件会同步
group_name = group1
# storage使用的端口,默认23000
port = 23000
# storage文件的目录
base_path = /home/fdfs/storage
# storage具体保存文件的目录个数,默认值为1,可配置多个,与下面的store_path[N]对应
store_path_count = 1
# storage保存文件的目录,当store_path_count=1时,这里写store_path0
# 当store_path_count的值大于1时,这里的store_path[N]也要相应增加,
store_path0 = /home/fdfs/storage/datas
# 指定tracker服务器的IP和端口,根据自己的trackerIP进行修改
tracker_server = 62.234.8.154:22122
http.server_port=80
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
#查看
netstat -unltp | grep fdfs
查看日志
tail -n1000 -f tracker.log
tail -n1000 -f storage.log
上传
cd /etc/fdfs
cp client.conf.sample client.conf
vim client.conf
base_path = /home/fdfs/storage/datas
tracker_server = 62.234.8.154:22122
使用png上传
fdfs_upload_file /etc/fdfs/client.conf /home/shuaiqi.png
# 返回以下地址
# group1/M00/00/00/PuoImmDr4aOAaSBuAADa9TFjKso456.png
#查看上传
cd /home/fdfs/storage/datas/data/00/00
ls
PuoImmDr4aOAaSBuAADa9TFjKso456.png
以上情况说明正常
Fastdfs本身无法通过http传输文件,如果使用web进行通信需要结合nginx
Fastdht 指纹去重
berkeley db
#下载地址
#建议用6版本 官方的18版本有问题
https://www.oracle.com/cn/database/technologies/berkeleydb.html
tar -zvxf db-6.2.38.tar.gz -C /home/
cd /home/db-6.2.38/build_unix
../dist/configure --prefix=/usr/local/berkeley/
make && make install
fastdht
#下载fastdhf
https://github.com/happyfish100/fastdht
unzip fastdht-master.zip -d /home/
cd /home/fastdht-master
#编辑 vim make.sh 27行左右
CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/local/berkeley/include/ -L/usr/local/berkeley/lib/'
-I 跟的是Berkeley DB安装目录下的include
-L 跟的是Berkeley DB安装目录下的lib
./make.sh && ./make install
#安装完成过后,会在 /etc/fdht 下生成三个配置文件
配置
mkdir /home/fdht
cd /etc/fdht
vim fdhtd.conf
base_path=/home/fdht
#include /etc/fdhtd/fdht_servers.conf
vim fdht_servers.conf
group_count = 1
#内网
group0 = 172.21.0.7:11411
vim fdht_client.conf
base_path=/home/fdht
keep_alive=1
#include /etc/fdhtd/fdht_servers.conf
cd /etc/fdfs
vim storage.conf
check_file_duplicate = 1
keep_alive = 1
#include /etc/fdht/fdht_servers.conf
这里 #include 没改之前,前面是 ##
共享lib
FastDHT启动依赖Berkeley DB的共享lib,如果不共享,日志中会出现so的错误
这里需要将共享lib放到 FastDHT 能搜寻到的位置,或者直接配置到FastDHT的配置文件内,这里让 FastDHT自己查找
cp /usr/local/berkeley/lib/libdb-6.2.so /usr/lib/
ldconfig
#lib:在Berkeley DB的安装目录下
#ldconfig:主要是在默认搜寻目录/lib和/usr/lib以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态链接库(格式如lib.so),进而创建出动态装入程序(ld.so)所需的连接和缓存文件
测试
# 依次启动 tracker、storage 和 fdht
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
fdhtd /etc/fdht/fdhtd.conf start
# 多次上传同一张图片
fdfs_upload_file /etc/fdfs/client.conf /home/shuaiqi.png
cd /home/storage/datas/data/00/00
ll
这时可以看到,我们虽然同一张图片上传了多次,但是照片只有一个实体对象,其余的都是指向它的软连接,后续上传的照片将不再存储,节约了内存空间
注意点:
1.必须放开 22122、23000、11411三个端口
2.关闭防火墙
END