在上一篇文章中对 FastDFS 做了内容简介。接下来我在 Ubuntu 服务器上做演示安装 FastDFS 环境。
接下来的几篇文章中,介绍在两台机器上部署 tracker 和 storage,本来也想连同集群的文章一块儿写完的,无奈电脑配置多台虚拟机不太给力,放弃了,网上相关文章很多,自行查询即可。
Tracker / Client 服务器:
172.16.119.129Storage 服务器:
172.16.119.128
在配置完成 Tracker Server 和 Stroage Server 服务器之后,会演示如何使用自带的工具实现文件的上传、下载、监控、删除。
然后再介绍最后一步,如果使用 Java 来操作 FastDFS 实现文件的上传,下载。
一、安装 FastDFS
FastDFS的项目主页:https://github.com/happyfish100/fastdfs
1、安装 Git
fastdfs 依赖 libfastcommon,需要从 github 上 clone 到本地编译安装。因此首先需要安装 git。
apt install git
修改 Git 的传输字节限制,避免 error: RPC failed(git缓存区不足)问题
git config --global http.postBuffer 524288000
2、下载安装 libfastcommon 库
新版的 FastDFS 同以前版本相比,将公共的一些函数等单独封装成了 libfastcommon 包,所以在安装FastDFS之前我们还必须安装 libfastcommon。
项目地址:https://github.com/happyfish100/libfastcommon
# 克隆项目 git clone https://github.com/happyfish100/libfastcommon.git # 进入目录 cd libfastcommon/ # 编译 ./make.sh # 安装 sudo ./make.sh install
安装 libfastcommon 库
3、设置软链接
libfastcommon.so 默认安装到了 /usr/lib64/libfastcommon.so,但是 FastDFS 主程序设置的 lib 目录是 /usr/local/lib,所以此处需要重新设置软链接,实际上也相当于 windows 上的快捷方式。
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so 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
设置软连接
4、下载安装 FastDFS
下载地址为:https://github.com/happyfish100/fastdfs/releases ,我这里版本选择最新 V5.11
# 下载 wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz # 执行解压包命令: tar -zxvf V5.11.tar.gz # 进入目录 cd fastdfs-5.11/ # 编译 ./make.sh # 安装 sudo ./make.sh install
安装 fastDFS
至此,FasfDFS 就算安装完成了。
二、默认安装方式脚本文件说明
1、服务脚本
默认路径
/etc/init.d/fdfs_storaged /etc/init.d/fdfs_trackerd
查看服务脚本
cd /etc/init.d/ && ls |grep fdfs
(1)fdfs_trackerd 脚本内容
liurenkui@ubuntu:/etc/init.d$ cat fdfs_trackerd
#!/bin/bash
#
# fdfs_trackerd Starts fdfs_trackerd
#
#
# chkconfig: 2345 99 01
# description: FastDFS tracker server
### BEGIN INIT INFO
# Provides: $fdfs_trackerd
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
PRG=/usr/bin/fdfs_trackerd
CONF=/etc/fdfs/tracker.conf
if [ ! -f $PRG ]; then
echo "file $PRG does not exist!"
exit 2
fi
if [ ! -f $CONF ]; then
echo "file $CONF does not exist!"
exit 2
fi
CMD="$PRG $CONF"
RETVAL=0
start() {
echo -n $"Starting FastDFS tracker server: "
$CMD &
RETVAL=$?
echo
return $RETVAL
}
stop() {
$CMD stop
RETVAL=$?
return $RETVAL
}
rhstatus() {
status fdfs_trackerd
}
restart() {
$CMD restart &
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart|reload)
restart
;;
condrestart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $?(2)fdfs_storaged 脚本内容
liurenkui@ubuntu:/etc/init.d$ cat fdfs_storaged
#!/bin/bash
#
# fdfs_storaged Starts fdfs_storaged
#
#
# chkconfig: 2345 99 01
# description: FastDFS storage server
### BEGIN INIT INFO
# Provides: $fdfs_storaged
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
PRG=/usr/bin/fdfs_storaged
CONF=/etc/fdfs/storage.conf
if [ ! -f $PRG ]; then
echo "file $PRG does not exist!"
exit 2
fi
if [ ! -f $CONF ]; then
echo "file $CONF does not exist!"
exit 2
fi
CMD="$PRG $CONF"
RETVAL=0
start() {
echo -n "Starting FastDFS storage server: "
$CMD &
RETVAL=$?
echo
return $RETVAL
}
stop() {
$CMD stop
RETVAL=$?
return $RETVAL
}
rhstatus() {
status fdfs_storaged
}
restart() {
$CMD restart &
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart|reload)
restart
;;
condrestart)
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $?注意观察上面的脚本,有看到 CONF=/etc/fdfs/tracker.conf 和 CONF=/etc/fdfs/storage.conf 的代码段,而 tracker.conf 和 storage.conf 两个文件默认是不存在的,接下来查看 /etc/fdfs 配置文件目录。
2、配置脚本
安装的 log 中会提示 FastDFS 安装到了 /etc/fdfs 目录下。此目录包含 4 个配置文件:
liurenkui@ubuntu:~/下载/fastdfs-5.11$ tree /etc/fdfs/ /etc/fdfs/ ├── client.conf.sample ├── storage.conf.sample ├── storage_ids.conf.sample └── tracker.conf.sample 0 directories, 4 files
3、命令行工具
#路径 /usr/bin/ #查看相关命令 ls /usr/bin/ | grep fdfs
FastDFS命令行工具
可以手动的通过 tracker 命令来操作 storage。后面的文章中会讲到。
未经允许请勿转载:程序喵 » Ubuntu 安装 FastDFS 分布式文件系统(二)
程序喵