System Environment
# VM virtualBox
# sentos 7_64X mini Install
# 为了快速上手,这里关闭了防火墙。实际生产中,则是开放指定的端口。
# 成功后会上传单机版环境,根据自己的虚拟机配置环境修改一下网卡,主机名,DNS 等信息即可。
Data preparation
Recommended to download directly from the official address
1.libfastcommon
* extracted from FastDFS and FastDHT the public C library, the basic environment
* before installing FastDFS need to install this
* Download site: https: //github.com/happyfish100/libfastcommon / Releases
2.FastDFS
* FastDFS installation package
* Download: HTTPS: //github.com/happyfish100/fastdfs/releases
3.fastdfs-nginx-Module
* to achieve via HTTP service to access and download files in the server FastDFS
* can be repeated directional link to the source file server to take your files from the same set of Storage server sync delay causes the file access error
* Download: HTTPS: //github.com/happyfish100/fastdfs-nginx-module/releases
* Note: the latest version is V1 .20, but because there is some question when configuring, where it is used instead V1.16 version
4.Nginx
* implement HTTP access, load balancing and caching functions
* Download: http: //nginx.org/en/download .html
the installation package using the following version
* libfastcommon: 1.0.38
* FastDFS: 5.11
* fastdfs-ninx-module :1.16
* Nginx : 1.15.1
The above installation package CentOS7 copied to the /root 目录
next
Installation configuration
# 关闭防火墙
# 查看防火墙状态
systemctl status firewalld.service
# 关闭防火墙
systemctl stop firewalld.service
# 禁用防火墙
systemctl disable firewalld.service
#以下的安装都要依赖gcc、perl
yum install make cmake gcc gcc-c++
yum -y install perl*
1. Install libfastcommon
cd /root
# 解压 libfastcommon 压缩包
tar -zxvf libfastcommon-1.0.39.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.39
# 编译并安装
./make.sh && ./make.sh install
# 由于 libfastcommon 安装的路径在 /usr/lib64/
# 但是 FastDFS 主程序设置的 lib 目录是在 /usr/local/lib,所以需要创建软链接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
2. Install fastdfs
cd /root/
# 解压缩
tar -zxvf fastdfs-5.12.tar.gz -C /usr/local/
cd /usr/local/fastdfs-5.12/
# 编译并安装
./make.sh && ./make.sh install
Configuration Tracker
# 创建 Tracker 的存储日志和数据的根目录
mkdir -p /fastdfs/tracker
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
# 配置 tracker.conf
vi tracker.conf
tracker.conf (just modify the path Tracker log and store data)
# 启用配置文件(默认为 false,表示启用配置文件)
disabled=false
# Tracker 服务端口(默认为 22122)
port=22122
# 存储日志和数据的根目录
base_path=/fastdfs/tracker
Storage Configuration
# 创建 Storage 的存储日志和数据的根目录
mkdir -p /fastdfs/storager
cd /etc/fdfs
cp storage.conf.sample storage.conf
# 配置 storage.conf
vi storage.conf
storage.conf just modify the path to store logs and storage data
# 启用配置文件(默认为 false,表示启用配置文件)
disabled=false
# Storage 服务端口(默认为 23000)
port=23000
# 数据和日志文件存储根目录
base_path=/fastdfs/storager
# 存储路径,访问时路径为 M00
# store_path1 则为 M01,以此递增到 M99(如果配置了多个存储目录的话,这里只指定 1 个)
store_path0=/fastdfs/storager
# Tracker 服务器 IP 地址和端口,单机搭建时也不要写 127.0.0.1
# tracker_server 可以多次出现,如果有多个,则配置多个
tracker_server=192.168.1.105:22122
# 设置 HTTP 访问文件的端口。这个配置已经不用配置了,配置了也没什么用
# 这也是为何 Storage 服务器需要 Nginx 来提供 HTTP 访问的原因
http.server_port=8888
Start Tracker and Storage Services
# 启动 Tracker 服务
# 其它操作则把 start 改为 stop、restart、reload、status 即可。Storage 服务相同
/etc/init.d/fdfs_trackerd start
# 启动 Storage 服务
/etc/init.d/fdfs_storaged start
# 可以通过 fdfs_monitor 查看集群的情况
# 查看 Storage 是否已经注册到 Tracker 服务器中
# 当查看到 ip_addr = 192.168.1.105 (localhost.localdomain) ACTIVE
# ACTIVE 表示成功
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
Appears in the following figure: that storage starts successfully
# 查看是否启动成功
ps -ef | grep fdfs
Test file upload
# 修改 Tracker 服务器客户端配置文件
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf
client.conf modify base_path and Tracker server's IP address and port number can be
# 存储日志文件的基本路径
base_path=/home/fastdfs/tracker
# Tracker 服务器 IP 地址与端口号
tracker_server=192.168.1.105:22122
# 将root目录下的一张图片存储到 FastDFS 服务器中
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/test.jpg
Success logo: return to the file id
3. Installation and Configuration Nginx
First, referring to the next:
Storage install Nginx, in order to provide http access and download services, while addressing the problem of group delay in synchronization Storage Server
Tracker install Nginx, is intended to provide reverse proxy http access, load balancing and caching services
Nginx rely environment GCC (this when installing libfastcommon on the installation), PCRE, zlib and openssl.
# 安装 GCC
yum install -y gcc-c++
# 安装 PCRE
yum install -y pcre pcre-devel
# 安装 zlib
yum install -y zlib zlib-devel
# 安装 openssl
yum install -y openssl openssl-devel
# 以上命令也可以使用一条命令来安装
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
Fastdfs-nginx-module configuration
所有 storage 节点都要安装 fastdfs-nginx-module 模块
cd /root
# 解压 fastdfs-nginx-module 模块
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/
cd /usr/local/fastdfs-nginx-module/
# 修改 fastdfs-nginx-module 的 config 配置文件
vi src/config
The CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
in local 去掉
revised toCORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
Compile and install nginx
cd /root
tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/
cd /usr/local/nginx-1.16.1/
# 给 Nginx 添加 fastdfs-nginx-module 模块
./configure --add-module=/usr/local/fastdfs-nginx-module/src
make && make install
: If there are mistakes
usr / local / fastdfs-nginx- module / src / common.c: 22: 20: fatal error: logger.h: No such file or directory # include "logger.h"
is executed:
ln -s /usr/include/fast* /usr/local/include/
fastdfs-nginx-module configuration file and modify FastDFS
# 复制 FastDFS 的部分配置文件到 /etc/fdfs
cd /usr/local/fastdfs-5.12/conf/
cp http.conf mime.types /etc/fdfs/
# 复制 fastdfs-nginx-module 源码中的配置文件到 /etc/fdfs 中
cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
mod_fastdfs.conf configured as follows
# Tracker 服务器IP和端口修改
tracker_server=192.168.1.105:22122
# url 中是否包含 group 名称,改为 true,包含 group
url_have_group_name = true
# 配置 Storage 信息,修改 store_path0 的信息
store_path0=/fastdfs/storager
# 其它的一般默认即可,例如
base_path=/tmp
group_name=group1
storage_server_port=23000
store_path_count=1
Nginx configuration
we /usr/local/nginx/conf/nginx.conf
Add the following code in the server
# 配置为支持 group0-group9,以及 M00-M99,以便于以后扩容
# 本单机环境下其实配置为 ~/group1/M00 就可以了
location ~/group([0-9])/M([0-9])([0-9]) {
ngx_fastdfs_module;
}
Start Nginx
# 启动 Nginx
/usr/local/nginx/sbin/nginx
# 重启 Nginx
/usr/local/nginx/sbin/nginx -s reload
# 停止 Nginx
/usr/local/nginx/sbin/nginx -s stop
# 查看是否启动成功
ps -ef|grep nginx
Access files via HTTP
This address can access by modifying the file uploaded to the above
http://192.168.1.105/group1/M00/00/00/wKgBaV4usqKALVXJAAFZ77FUVlQ276.jpg
See the uploaded images will be successful.
Every time you start
# 每次开机时,手动打开 Tracker 服务
/etc/init.d/fdfs_trackerd start
# 打开 Storage 服务
/etc/init.d/fdfs_storaged start
# 启动 Nginx
/usr/local/nginx/sbin/nginx
to sum up
Stand-alone end, so have time to build a good standalone version will be uploaded here.