1、前言
配置环境以及依赖:
分项 | 具体要求 |
---|---|
系统要求 | centos7 |
软件版本 | fastdfs-5.12(软件主体),libfastcommon-1.0.40(依赖包) |
软件地址 | https://github.com/happyfish100/fastdfs/releases v5.12 |
软件地址 | https://github.com/happyfish100/libfastcommon/releases v1.0.40 |
软件地址 | https://github.com/happyfish100/fastdfs-nginx-module/releases v1.21 |
2、安装gcc–编译时需要
FastDFS是C语言开发,安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gc
使用一下命令查看宿主机是否已经安装gcc
gcc -v
如果未安装gcc,则使用一下命令安装gcc
yum install -y gcc gcc-c++ maven
3、安装libevent–运行时需要
若安装了桌面图形界面,就不需要安装;FastDFS依赖libevent库。
yum -y install libevent
4、安装perl
使用以下命令查看宿主机是否安装perl
perl -v
如果未安装,则使用下列命令安装
yum -y install perl
5、安装libfastcommon(版本1.0.40)
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。
可以使用wget从网上下载,这边是使用下载好传输到宿主机。
unzip libfastcommonV1.0.40.zip //解压
cd libfastcommonV1.0.40
./make.sh //编译
./make.sh install //安装
安装完之后的截图
安装好之后会在/usr/lib64目录下生成libfastcommon.so 库文件,由此验证是否安装成功。
6、安装fastdfs
上传fastdfs-5.12.tar.gz至宿主机,解压至/usr/local中
tar -zxvf fastdfs-5.12.tar.gz -C /usr/local
fastdfs源码编译,安装
cd /usr/local/fastdfs-5.12
./make.sh
./make.sh install
7、配置和启动tracker
将fastdfs配置文件目录复制到/etc/fdfs目录下
cp /usr/local/FastDFS/conf/* /etc/fdfs/ #复制配置文件
查看是否有tracker.conf文件是否存在,如果没有则复制一份
cp tracker.conf.sample tracker.conf
修改tracker.conf配置文件,主要修改
1)base_path,原先设置的路径为/home/yuqing/fastdfs修改为本地的路径,推荐/home/fastdfs
2)http.server_port,根据自定义的要求确定是否修改端口。
根据上步设置的路径,新建文件夹
mkdir /home/fastdfs
启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
8、配置和启动storage
由于上面已经安装过FastDFS,这里只需要配置storage就好了;
1)切换目录到:/etc/fdfs/ 目录下;
2)拷贝一份新的storage配置文件
cp storage.conf.sample storage.conf
3)修改storage.conf ; vim storage.conf
group_name=group1 #配置组名
base_path=/home/yuqing/fastdfs 改为: base_path=/home/fastdfs
#store存放文件的位置(store_path)
store_path0=/home/yuqing/fastdfs 改为: store_path0=/home/fastdfs_storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......
#配置tracker服务器:IP
tracker_server=172.17.0.231:22122
#如果有多个则配置多个tracker
#tracker_server=172.17.0.231:22122
#根据自定义要求确定是否修改配置http端口
http.server_port=88
4)创建 /home/fastdfs_storage 目录
mkdir /home/fastdfs_storage
5)启动storage, 运行命令如下:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
启动完成后进入 /home/fdfs_storage/data 目录下,显示目录如下:
7、测试-使用FastDFS自带工具测试
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/9448607_203308534000_2.jpg
返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。
用xftp可以看到,在磁盘的存放路径为:
错误处理
当发现无法处理的错误时,请参考base_path下的log日志:本文中的log日志在 /home/fastdfs下。
文章参考:
https://www.cnblogs.com/chiangchou/p/fastdfs.html