1.FastDFS–tracker安装
1.1下载
tracker和storage使用相同的安装包,下载地址:http://sourceforge.net/projects/FastDFS/ 或https://github.com/happyfish100/FastDFS(推荐)
本教程下载:FastDFS_v5.05.tar.gz
1.2FastDFS安装环境
FastDFS是C语言开发,建议在linux上运行 安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++
1.3安装libevent
FastDFS依赖libevent库,需要安装:
yum -y install libevent
1.4安装libfastcommon
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。
将libfastcommonV1.0.7.tar.gz拷贝至/usr/local/下
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
**注意 **:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。
要拷贝的文件如下:
1.5tracker编译安装
将FastDFS_v5.05.tar.gz拷贝至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下。
安装成功后进入/etc/fdfs目录:
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改为:
base_path=/home/FastDFS
注意:FastDFS文件没有在启动时会失败 需要在/home/下创建FastDFS文件夹
1.7启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
设置开机自动启动
[root@tracker FastDFS]# vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
2.FastDFS–storage安装
2.1storage配置
进入/etc/fdfs目录:
修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改为:base_path=/home/FastDFS1
store_path0=/home/yuqing/FastDFS改为:store_path0=/home/FastDFS1/
tracker_server=127.0.0.1:22122
注意:FastDFS1没有需要先在/home/下创建FastDFS1
2.5启动
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
设置开机自动启动。
[root@storage1 FastDFS]# vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
测试端口:ps -ef | grep 23000
3.上传图片测试
3.1通过fdfs_test程序
FastDFS安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作。
修改/etc/fdfs/client.conf
base_path=/home/fastdfs
tracker_server=127.0.0.1:22122
注意:home下创建fastdfs文件夹
使用格式:
/usr/bin/fdfs_test 客户端配置文件地址 upload 上传文件
比如将/home下的图片上传到FastDFS中:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/tomcat.png
http://127.0.0.1/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png就是文件的下载路径。
对应storage服务器上的
/home/fastdfs/fdfs_storage/data/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png文件。
没有和nginx整合无法使用http下载 Nginx和FastDFS整合请看下一篇。