您的位置:首页 > 运维架构 > Nginx

记录FastDFS+Nginx 安装与配置过程

2017-11-05 19:06 811 查看

介绍

作者余庆在GitHub的说明: FastDFS is an open source high performance distributed file system (DFS). It’s major functions include: file storing, file syncing and file accessing, and design for high capacity and load balance.

本文是记录FastDFS+Nginx的安装和配置过程,实现文件的上传以及从浏览器访问上传的文件.不部署集群,只部署一个 tracker 和 一个 storage.系统是CentOS7.

注意:

1.这里是直接下载GitHub源码进行编译安装的,生产环境需要下载稳定版本.

2.遇到问题,首先查看日志文件.

过程

安装fastlibcommon

/*安装依赖*/
yum install gcc gcc-c++ make automake autoconf libtool   pcre*  zlib zlib-devel  openssl openssl-devel
/*下载libfastcommon*/
mkdir /root/fastdfs
cd /root/fastdfs
wget -O fastlibcommon-master.zip https://github.com/happyfish100/libfastcommon/archive/master.zip /*编译安装*/
unzip fastlibcommon-master.zip
cd fastlibcommon-master
./make.sh
./make.sh install


安装FastDFS

/*下载FastDFS*/
cd /root/fastdfs
wget -O fastdfs-master.zip https://github.com/happyfish100/fastdfs/archive/master.zip /*编译安装*/
unzip fastdfs-master.zip
cd fastdfs-master
./make.sh
./make.sh install


配置tracker服务

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vi /etc/fdfs/tracker.conf
/*修改的内容*/
###
disabled=false              # 启用配置文件
port=33133                  # tracker服务器端口(默认22122)
base_path=/home/fastdfs_data/tracker  # 存储日志和数据的根目录
###
/*创建相应目录*/
mkdir -p /home/fastdfs_data/tracker
/*启动tracker服务
第一次启动会在base_path下生成 logs 和 data 俩个目录
*/
/etc/init.d/fdfs_trackerd start
/*查看是否启动成功*/
ps -ef|grep fdfs_trackerd




配置storage服务

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vi /etc/fdfs/storage.conf
/*修改的内容*/
###
disabled=false                      # 启用配置文件
port=33000                          # storage服务端口base_path=/home/fastdfs_data/storage  # 数据和日志文件存储根目录
store_path0=/home/fastdfs_data/storage  # 第一个存储目录
tracker_server=192.168.146.136:33133  # tracker服务器IP和端口,不能使用127.0.0.1
http.server_port=70               # http访问文件的端口
###
/*创建相应目录*/
mkdir -p /home/fastdfs_data/storage
/*启动storage服务*/
/etc/init.d/fdfs_storaged start
/*查看是否启动成功*/
ps -ef|grep fdfs_storaged




配置client

/*修改Tracker服务器客户端配置文件*/
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf
/*修改内容*/
base_path=/home/fastdfs_data/tracker
tracker_server=192.168.146.136:33133
/*查看是否一切正常*/
fdfs_monitor /etc/fdfs/client.conf


上传文件

fdfs_upload_file /etc/fdfs/client.conf  /home/fengw/test.gif




在storage节点安装fastdfs-nginx-module

/*下载fastdfs-nginx-module*/
cd /root/fastdfs
wget -O fastdfs-nginx-module-master.zip https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip unzip fastdfs-master.zip
/*修改配置文件*/
vi fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
修改为:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"


安装 Nginx

/*下载*/
cd /root/fastdfs
wget http://nginx.org/download/nginx-1.10.0.tar.gz tar -zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0
/*指定fastdfs-nginx-module路径*/
./configure --add-module=/root/fastdfs/fastdfs-nginx-module/src
/*编译安装*/
make && make install
/*查看是否安装成功*/
/usr/local/nginx/sbin/nginx -t




配置fastdfs-nginx-module

cp /root/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
mkdir -p /home/nginx-module_tmp
vi /etc/fdfs/mod_fastdfs.conf
/*修改内容*/
###
connect_timeout=10
base_path=/home/hhd/nginx-module_tmp
tracker_server=192.168.146.136:33133
storage_server_port=33000
group_name=group1
url_have_group_name = true
store_path0=/root/fastdfs_data/storage
###
cd /root/fastdfs/fastdfs-master/conf
cp http.conf mime.types /etc/fdfs/


配置Nginx

vi /usr/local/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 70;
server_name localhost;
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
###
/*启动Nginx*/
/usr/local/nginx/sbin/nginx #启动
/usr/local/nginx/sbin/nginx -s reload #重启
/*通过浏览器访问上传的图片(关闭防盗链才能访问)*/ http://192.168.146.136:70/group1/M00/00/00/wKiSiFn-sn-ANDfOAAF9cj1XR7g793.gif[/code] 
开启防盗链

vi /etc/fdfs/http.conf
http.anti_steal.check_token=true #开启
http.anti_steal.secret_key=123456 #密钥


防火墙

不管是firewalld 还是iptables 只要开启需要的端口就行了,策略自己配.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: