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

来源:互联网 发布:天下3鬼墨女捏脸数据 编辑:程序博客网 时间:2024/05/16 03:28

介绍

作者余庆在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/fastdfscd /root/fastdfswget -O fastlibcommon-master.zip https://github.com/happyfish100/libfastcommon/archive/master.zip /*编译安装*/unzip fastlibcommon-master.zipcd fastlibcommon-master./make.sh./make.sh install
  • 安装FastDFS
/*下载FastDFS*/cd /root/fastdfswget -O fastdfs-master.zip https://github.com/happyfish100/fastdfs/archive/master.zip /*编译安装*/unzip fastdfs-master.zipcd 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.confvi /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.1http.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.confvi /etc/fdfs/client.conf/*修改内容*/base_path=/home/fastdfs_data/trackertracker_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/fastdfswget -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/configCORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"修改为:CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
  • 安装 Nginx
/*下载*/cd /root/fastdfswget http://nginx.org/download/nginx-1.10.0.tar.gztar -zxvf nginx-1.10.0.tar.gzcd 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_tmpvi /etc/fdfs/mod_fastdfs.conf/*修改内容*/###connect_timeout=10base_path=/home/hhd/nginx-module_tmptracker_server=192.168.146.136:33133storage_server_port=33000group_name=group1url_have_group_name = truestore_path0=/root/fastdfs_data/storage###cd /root/fastdfs/fastdfs-master/confcp 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
  • 开启防盗链
vi /etc/fdfs/http.confhttp.anti_steal.check_token=true #开启http.anti_steal.secret_key=123456 #密钥
  • 防火墙
    不管是firewalld 还是iptables 只要开启需要的端口就行了,策略自己配.
原创粉丝点击