FastDFS安装与使用(单节点)

半兽人 发表于: 2016-02-21   最后更新时间: 2016-02-22  
  •   0 订阅,1997 游览

FastDFS 分布式文件系统的安装与使用(单节点)

本文tracker、storage都在一台机器上!本机tracker和storage是放在一起的。

下章介绍FastDFS + nginx的使用方法。

需要准备的包

FastDFS_v5.08.tar.gz
libfastcommon-master.zip  (是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库)

源码地址:https://github.com/happyfish100/ 
下载地址:http://sourceforge.net/projects/fastdfs/files/ 
官方论坛:http://bbs.chinaunix.net/forum-240-1.html

如果没有GCC编译器,先安装GCC

yum install make cmake gcc gcc-c++

1、解压 FastDFS_v5.08.tar.gz

tar -zxvf FastDFS_v5.08.tar.gz
cd FastDFS

2、编译、安装

./make.sh
./make.sh install
出现错误
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c  -I../common -I/usr/include/fastcommon
../common/fdfs_global.c:20:20: 错误:logger.h:没有那个文件或目录
在包含自 ../common/fdfs_global.c:21 的文件中:
../common/fdfs_global.h:14:27: 错误:common_define.h:没有那个文件或目录
../common/fdfs_global.h:16:29: 错误:connection_pool.h:没有那个文件或目录
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:26: 错误:‘MAX_PATH_SIZE’ 未声明 (不在函数内)
../common/fdfs_global.h:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.h:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.h:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c:23: 错误:‘DEFAULT_CONNECT_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:24: 错误:‘DEFAULT_NETWORK_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.c:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.c:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c: In function ‘fdfs_check_data_filename’:
../common/fdfs_global.c:39: 警告:隐式声明函数 ‘logError’
../common/fdfs_global.c:45: 警告:隐式声明函数 ‘IS_UPPER_HEX’
make: *** [../common/fdfs_global.o] 错误 1
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c  -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
../common/fdfs_global.c:20:20: 错误:logger.h:没有那个文件或目录
在包含自 ../common/fdfs_global.c:21 的文件中:
../common/fdfs_global.h:14:27: 错误:common_define.h:没有那个文件或目录
../common/fdfs_global.h:16:29: 错误:connection_pool.h:没有那个文件或目录
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:26: 错误:‘MAX_PATH_SIZE’ 未声明 (不在函数内)
../common/fdfs_global.h:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.h:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.h:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c:23: 错误:‘DEFAULT_CONNECT_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:24: 错误:‘DEFAULT_NETWORK_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.c:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.c:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c: In function ‘fdfs_check_data_filename’:
../common/fdfs_global.c:39: 警告:隐式声明函数 ‘logError’
../common/fdfs_global.c:45: 警告:隐式声明函数 ‘IS_UPPER_HEX’
make: *** [../common/fdfs_global.o] 错误 1
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c  -I../common -I../tracker -I/usr/include/fastcommon
../common/fdfs_global.c:20:20: 错误:logger.h:没有那个文件或目录
在包含自 ../common/fdfs_global.c:21 的文件中:
../common/fdfs_global.h:14:27: 错误:common_define.h:没有那个文件或目录
../common/fdfs_global.h:16:29: 错误:connection_pool.h:没有那个文件或目录
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:26: 错误:‘MAX_PATH_SIZE’ 未声明 (不在函数内)
../common/fdfs_global.h:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.h:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.h:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c:23: 错误:‘DEFAULT_CONNECT_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:24: 错误:‘DEFAULT_NETWORK_TIMEOUT’ 未声明 (不在函数内)
../common/fdfs_global.c:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’
../common/fdfs_global.c:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’
../common/fdfs_global.c:28: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’
../common/fdfs_global.c: In function ‘fdfs_check_data_filename’:
../common/fdfs_global.c:39: 警告:隐式声明函数 ‘logError’
../common/fdfs_global.c:45: 警告:隐式声明函数 ‘IS_UPPER_HEX’
是因为没有安装 libfastcommon 

安装libfastcommon

unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
libfastcommon 默认安装到了
/usr/lib64/libfastcommon.so
/usr/lib64/libfdfsclient.so

安装成功后,继续安装FastDFS

采用默认安装的方式安装,安装后的相应文件与目录: 

A、服务脚本在:
         /etc/init.d/fdfs_storaged
         /etc/init.d/fdfs_tracker
B、配置文件在(样例配置文件): 

         /etc/fdfs/client.conf.sample 

         /etc/fdfs/storage.conf.sample 

         /etc/fdfs/tracker.conf.sample
C、命令工具在/usr/bin/目录下的:
         fdfs_appender_test
         fdfs_appender_test1
         fdfs_append_file
         fdfs_crc32
         fdfs_delete_file
         fdfs_download_file
         fdfs_file_info
         fdfs_monitor
         fdfs_storaged
         fdfs_test
         fdfs_test1
         fdfs_trackerd
         fdfs_upload_appender
         fdfs_upload_file
         stop.sh
         restart.sh

进入 /etc/fdfs/

cd /etc/fdfs
复制3份配置文件

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

配置 tracker

1、查看tracker.conf

vi /etc/fdfs/tracker.conf
2、配置(保留默认即可)

disabled=false
port=22122
base_path=/home/yuqing/fastdfs
(其它参数保留默认配置,具体配置解释请参考官方文档说明: 

http://bbs.chinaunix.net/thread-1941456-1-1.html )

3、创建基础数据目录(参考基础目录 base_path 配置):

mkdir -p /home/yuqing/fastdfs
4、防火墙中打开跟踪器端口(默认为 22122)

vi /etc/sysconfig/iptables

添加如下端口行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
重启防火墙
service iptables restart
5、启动 Tracker:
/etc/init.d/fdfs_trackerd start

(初次成功启动,会在/fastdfs/tracker 目录下创建 data、logs 两个目录) 

查看 FastDFS Tracker 是否已成功启动:

ps -ef | grep fdfs
6、 关闭 Tracker:
# /etc/init.d/fdfs_trackerd stop
7、 设置 FastDFS 跟踪器开机启动:
vi /etc/rc.d/rc.local

添加以下内容:

## FastDFS Tracker 
/etc/init.d/fdfs_trackerd start

配置 FastDFS 存储

1、查看storage

vi /etc/fdfs/storage.conf
2、编辑

修改的内容如下:
disabled=false
port=23000
base_path=/home/yuqing/fastdfs
store_path0=/home/yuqing/fastdfs 

tracker_server=192.168.4.121:22122 

http.server_port=8888 

(其它参数保留默认配置,具体配置解释请参考官方文档说明: 

http://bbs.chinaunix.net/thread-1941456-1-1.html )
3、 创建基础数据目录(参考基础目录 base_path 配置)

/home/yuqing/fastdfs 
4、 防火墙中打开存储器端口(默认为 23000):
vi /etc/sysconfig/iptables
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT 
重启防火墙:
service iptables restart
5、 启动 Storage:
/etc/init.d/fdfs_storaged start


 (初次成功启动,会在/fastdfs/storage 目录下创建 data、logs 两个目录) 

查看 FastDFS Storage 是否已成功启动

ps -ef | grep fdfs
6、 关闭 Storage:
/etc/init.d/fdfs_storaged stop
7、 设置 FastDFS 存储器开机启动:
vi /etc/rc.d/rc.local
添加:
## FastDFS Storage
/etc/init.d/fdfs_storaged start

最后,文件上传测试

1、修改 Tracker 服务器中的客户端配置文件:

vi /etc/fdfs/client.conf
base_path=/fastdfs/tracker
tracker_server=192.168.4.121:22122
2、执行如下文件上传命令:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/FastDFS_v5.05.tar.gz
返回 ID 号:group1/M00/00/00/wKgEfVUYNYeAb7XFAAVFOL7FJU4.tar.gz
(能返回以上文件 ID,说明文件上传成功)








发表于: 1年前   最后更新时间: 1年前   游览量:1997
上一条: FastDFS介绍
下一条: FastDFS+Nginx安装与配置
评论…

  • 评论…
    • in this conversation
      提问