FastDFS安装部署文档
一、 FastDFS安装部署(单台服务器版)
在安装前,请务必将当前服务器配置为可以上外网!
1. 准备环境
Ø 操作系统: CentOS 6.5[Server-1]
Ø 安装包:(可在linux服务器指定目录下,如/opt/tools/,通过wget下载)
1、FastDFS_v5.08.tar.gz 下载地址: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
2、libfastcommon-master.zip下载地址:
https://github.com/happyfish100/libfastcommon/archive/master.zip
3、nginx-1.8.1.tar.gz 下载地址:
http://nginx.org/download/nginx-1.8.1.tar.gz
4、fastdfs-nginx-module_v1.16.tar.gz
http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
2. 安装步骤
Ø 安装 gcc,通过yum方式
yuminstall make cmake gcc gcc-c++
Ø 安装libfastcommon,执行下列命令:[Server-1]
cd/opt/tools/
unzip master.zip
cd libfastcommon-master
./make.sh
./make.shinstall
Ø 安装FastDFS,执行下列命令:[Server-1]
cd/opt/tools/
tar-xzvf FastDFS_v5.08.tar.gz
cdFastDFS
./make.sh
./make.sh install
采用默认方式安装后的文件及目录:
[root@PicServer tools]# ll /etc/init.d/|grep fdfs
-rwxr-xr-x. 1 root root 918 Jul 25 17:35 fdfs_storaged
-rwxr-xr-x. 1 root root 920 Jul 25 17:35 fdfs_trackerd
Ø fdfs_trackerd服务配置[Server-1]
mkdir-p /data/fastdfs/tracker
cd/etc/fdfs/
cptracker.conf.sample tracker.conf
vi tracker.conf
将base_path=/home/yuqing/fastdfs改成base_path=/data/fastdfs/tracker
Ø fdfs_storaged服务配置[Server-2]
mkdir-p /data/fastdfs/storage
cd/etc/fdfs/
cpstorage.conf.sample storage.conf
vi storage.conf
将base_path=/home/yuqing/fastdfs改成base_path=/data/fastdfs/storage
将store_path0=/home/yuqing/fastdfs改成store_path0=/data/fastdfs/storage
将tracker_server=192.168.209.121:22122改成tracker_server=192.168.1.81:22122
http.server_port=8888(默认为8888,与nginx中配置的监听端口一致)
(192.168.1.81为当前服务器ip,请根据实际情况修改)
Ø client服务配置[Server-1]
cd/etc/fdfs/
cpclient.conf.sample client.conf
vi client.conf
将base_path=/home/yuqing/fastdfs改成
base_path=/data/fastdfs/tracker
将tracker_server=192.168.0.197:22122改成
tracker_server=192.168.1.81:22122
3. 启动和关闭服务
启动fdfs_trackerd服务:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动fdfs_storaged服务:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
注:先启动fdfs_trackerd服务再启动fdfs_storaged服务。
可以通过servicefdfs_trackerd(storaged) start/stop/restart/status
这种方式来管理服务了。如果不行就将安装包里面提供的/init.d
的fdfs_trackerd(storaged)拷贝到/etc/init.d里面再执行上面操作。
如:cp /opt/tools/FastDFS/init.d/fdfs_trackerd/etc/init.d/
chkconfig --add fdfs_trackerd
chkconfig fdfs_trackerd on (设置开机自启动)
4. 测试文件上传
手动上传文件szp.png到[Server-1]的/tmp目录下面;
fdfs_upload_file /etc/fdfs/client.conf /tmp/szp.png
上传成功后返回:group1/M00/00/00/wKgagFUWXQWAeygxAABWNEgjnSE328.png
可以到/data/fastdfs/storage/data/00/00/目录下面查看文件是否存在。
5. 测试文件删除
fdfs_delete_file/etc/fdfs/client.confgroup1/M00/00/00/
wKgagFUWXQWAeygxAABWNEgjnSE328.png
可以到/data/fastdfs/storage/data/00/00/目录下面查看文件是否存在。
6. 存储服务器(storage server)安装并配置nginx
Ø 下载并安装fastdfs-nginx-module模块
cd /opt/tools
tar xf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src/
vim config
编辑config文件,执行如下命令进行批量替换并保存退出
:%s+/usr/local/+/usr/+g
Ø 拷贝fastdfs-nginx-module模块中配置文件到/etc/fdfs目录中并编辑
cp /opt/tools/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
修改内容如下:
connect_timeout=10
base_path=/tmp(默认为/tmp)
tracker_server=192.168.1.81:22122
storage_server_port=23000(默认配置为23000)
url_have_group_name = true
store_path0=/data/fastdfs/storage
group_name=group1(默认配置为group1)
Ø 安装nginx依赖库
yum install -y pcre-devel zlib-devel
安装nginx:
cd /opt/tools/
tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/
make && make install
拷贝FastDFS中的部分配置文件到/etc/fdfs目录中:
cp /opt/tools/FastDFS/conf/http.conf /etc/fdfs/
cp /opt/tools/FastDFS/conf/mime.types /etc/fdfs/
配置nginx,如下所示:
vim /application/nginx/conf/nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
拷贝nginx服务到/etc/init.d/目录下并启动
cp /application/nginx/sbin/nginx /etc/init.d/
/etc/init.d/nginx
ss -lntup|grep 8888
通过浏览器访问之前已经上传的文件
浏览器可以成功访问到上传的图片,说明使用FastDFS搭建的图片服务器成功完成!
防火墙中打开端口设置:
vi /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport8888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport22122 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport23000 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport11411 -j ACCEPT
重新启动防火墙:
service iptables restart
配置FastDFS随系统启动:
cd /etc/rc.d
vim rc.local
添加
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/etc/init.d/nginx
重启linux系统,FastDFS服务正常,图片可以访问。