Fastdfs安装教程
1、环境
操作系统 Centos 7.0 X64最小化安装
Track1 :192.168.121.131
Track2 :192.168.121.132
Storage1 :192.168.121.133
Storage1 :192.168.121.134
FastDFS 下载地址
https://sourceforge.net/projects/fastdfs/files/?source=navbar
2、在Track上安装fastdfs
首先,安装依赖包
yum install -y gcc-c++ wget unzip perl pcre-devel zlib-devel
192.168.121.131
下载代码包
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
解压后我们查看INSTALL文件,上面写了安装步骤
如图,要安装FastDFS我们要先安装libfastcommon
所以下载安装libfastcommon
wget https://codeload.github.com/happyfish100/libfastcommon/zip/master
unzip master && cd libfastcommon-maste
./make.sh && ./make.sh install
再回到FaastDFS安装包,执行安装
cd ../FastDFS/
./make.sh && ./make.sh install
安装完成
然后在192.168.121.132 133 134上面执行同样操作
3、配置Track
修改tracker.conf 文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
mkdir /data/fastdfs
#配置data和log的存放路径
vim /etc/fdfs/tracker.conf
修改 base_path=/home/yuqing/fastdfs为
base_path=/data/fastdfs
修改client.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
#设置参数
vim /etc/fdfs/client.conf
base_path=/data/fastdfs
tracker_server=192.168.121.130:22122
tracker_server=192.168.121.131:22122
http.tracker_server_port=80
启动服务
/etc/init.d/fdfs_trackerd start
打开防火墙
firewall-cmd --add-port=22122/tcp
查看状态
fdfs_monitor /etc/fdfs/client.conf
4、配置Storage
cp /root/FastDFS/conf/http.conf /etc/fdfs/
cp /root/FastDFS/conf/mime.types /etc/fdfs/
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
#修改base路径
base_path=/data/fastdfs
#修改存储路径
store_path0=/data/fastdfs
#设置track IP
tracker_server=192.168.121.132:22122
tracker_server=192.168.121.133:22122
#修改web端口
http.server_port=80
启动服务
/etc/init.d/fdfs_storaged start
添加防火墙
firewall-cmd --add-port=23000/tcp
配置nginx并安装模块
wget http://nginx.org/download/nginx-1.8.1.tar.gz
wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
拷贝配置文件
cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
编译安装nginx
./configure --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module/src/
这步会报错
解决办法是修改fastdfs模块引用fastdfs的路径
因为Fastdfs的prefix 是/usr
这里引用的是/usr/local
vim ../fastdfs-nginx-module/src/config
#去掉local
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
然后重新编译安装就能过了
make clean
./configure --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module/src/
Make && make install
修改模块配置文件
vim /etc/fdfs/mod_fastdfs.conf
#日志路径
base_path=/data/log
tracker_server=192.168.121.130:22122
tracker_server=192.168.121.131:22122
#存储路径
store_path0=/data/fastdfs
url_have_group_name = true
修改nginx配置
vim /usr/local/nginx/conf/nginx.conf
location /group1/M00 {
root /data/fastdfs/data;
ngx_fastdfs_module;
}
启动nginx
/usr/local/nginx/sbin/nginx -s
开防火墙
firewall-cmd --add-port=23000/tcp
查看fastdfs状态
fdfs_monitor /etc/fdfs/storage.conf
状态为ACTIVE是正常
启动成功
5、测试上传
用Track1和Track2来上传都是可以的
这里用Track1
fdfs_test /etc/fdfs/client.conf upload /tmp/30adcbef76094b360fade2f0a5cc7cd98d109df4.jpg
上传成功,获得一个图片地址
图片实际保存路径为
/data/fastdfs/data/00/00/wKh5hFblTomANCAAAADD0tsLWr8597.jpg
访问图片测试
正常访问
再访问另一台Storage
访问正常,实验完成
由于有两台Storage和Track,任何一台s挂掉都是有备份的
Track和stoage可以用keepalive来做高可用实现故障转移 这里就不多说了。