FastDFS安装

一.安装libevent 我使用的是libevent-1.4.14b版本
公司的服务器由于安全原因不能连网,所以通过scp或其他工具上传该文件(能连网的可以通过wget命令直接下载),上传到/opt目录,安装步骤如下:

tar zvxf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure; make; make install

安装完成后, 为 libevent 创建软链接到/lib 库下,64 位系统对应/lib64

ln -s /usr/local/lib/libevent* /lib/
ln -s /usr/local/lib/libevent* /lib64/

二.安装FastDFS,我现在有两台服务器,地址分别为192.168.251.28(做tracker),192.168.251.29(做storage)
(1)上传文件,同样上传到/opt目录下,执行如下命令:
注意:如果 trackerd 需要使 用内置的 web server,需要修改 make.sh 文件,启用 WITH_HTTPD=1 再编译我的需要,所以我打开改选项。

tar zvxf FastDFS_v3.11.tar.gz
cd FastDFS ./make.sh ./make.sh install

安装完成后:终端中可以看到如下信息表示安装成功:

if [ 1 -eq 1 -a /usr/local/lib = "/usr/local/lib" ]; then sh ./fdfs_link_library.sh; fi

从打出的日志信息,可以看到:
FastDFS安装在/usr/local/bin中。
配置文件安装在/etc/fastdfs/中。

(2)创建存储目录,也算是fastdfs的工作目录

mkdir /home/fastdfs

(3)配置tracker_server:
vim /etc/fdfs/tracker.conf 设置base_path=/home/fastdfs;
需要注意tracker.conf文件最后一行为#include httpd.conf,也就是应该去掉一个#
启动:

/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

(4)通过去/home/fastdf查看日志看是否启动成功,或者可以输入netstat -lentup|grep 22122,查看端口的状态

(5)安装storage服务器,步骤也如上:
1.安装libevent
2.编译安装,同样,如果 storage需要使 用内置的 web server,需要修改 make.sh 文件,启用 WITH_HTTPD=1 再编译
3.创建存储目录,也算是fastdfs的工作目录

mkdir /home/fastdfs

4.配置storage_server

vim /etc/fdfs/storage.conf
设置base_path=/home/fastdfs;
store_path0=/home/fastdfs;
tracker_server=192.168.251.28:22122
#如果还有tracker_server,tracker_server=192.168.251.30:22122 (可以指定多个tracker_server,换行写即可)
需要注意tracker.conf文件最后一行为#include httpd.conf,也就是应该去掉一个#
启动:/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

5.通过去/home/fastdf查看日志看是否启动成功,或者可以输入netstat -lentup|grep 8888,查看端口的状态
三.测试上传和下载文件:
选择一条机器作为客服端,我是选择的tracker,在/etc/fdfs中在配置client.conf,修改base_path选项,还有tracker_server=192.168.251.28:22122。(base_path的作用是确定你下载时文件的下载位置。)
创建test.txt的测试文件,测试上传功能:

/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /opt/root/test.txt

看以看到如下信息:

This is FastDFS client test program v3.11

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2013-12-03 11:05:04] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0

tracker_query_storage_store_list_without_group:
	server 1. group_name=group1, ip_addr=192.168.251.29, port=23000

group_name=group1, ip_addr=192.168.251.29, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKj7HVKdSo6S4IWPAAAAH0JOY3A259.txt
source ip address: 192.168.251.29
file timestamp=2013-12-03 11:05:50
file size=31
file crc32=1112433520
file url: http://192.168.251.28:8080/group1/M00/00/00/wKj7HVKdSo6S4IWPAAAAH0JOY3A259.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKj7HVKdSo6S4IWPAAAAH0JOY3A259_big.txt
source ip address: 192.168.251.29
file timestamp=2013-12-03 11:05:50
file size=31
file crc32=1112433520
file url: http://192.168.251.28:8080/group1/M00/00/00/wKj7HVKdSo6S4IWPAAAAH0JOY3A259_big.txt

测试下载:看到最后的url,我们用这个路径:

/usr/local/bin/fdfs_test /etc/fdfs/client.conf download group1 M00/00/00/wKj7HVKdSo6S4IWPAAAAH0JOY3A259_big.txt

得到如下信息:

This is FastDFS client test program v3.11

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2013-12-03 11:06:06] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0

storage=192.168.251.29:23000
download file success, file size=31, file save to wKj7HVKdSo6S4IWPAAAAH0JOY3A259_big.txt

很明显成功了。。。over。
其他情况:
1).如果在编译过程中有任何错误,可使用

./make.sh clean

然后再重新编译
2)tracker_query_storage fail, error no: 2, error info: No such file or directory
tracker error.png
我出现该问题,是因为原有的storege服务器被换成新的,tracker里还有原来storage的缓存的原因,所以到tracker的工作的目录/home/fastdfs目录下,删除data文件夹。然后重启。问题解决。
3)重启命令

/usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf(重启tracker)
/usr/local/bin/restart.sh/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf(重启storage)

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部