Fastdfs (1): Centos7 installation Fastdfs+nginx Module

Source: Internet
Author: User
Tags crc32

1, about Fastdfs

Excerpt from: Http://www.oschina.net/p/fastdfs
Fastdfs is an open source Distributed File System, she manages the file, features include: file storage, file synchronization, file access (file upload, file download), etc., to solve the problem of large-capacity storage and load balancing. Especially suitable for file-based online services, such as photo album sites, video sites and so on.

The FASTDFS server has two roles: Tracker (tracker) and storage node (storage). The tracker mainly does the dispatching work, and the function of load balancing on the access.

The storage node stores files and completes all the functions of file management: storing, synchronizing, and providing access interfaces, Fastdfs also manages meta data for the file. The so-called meta data of a file is the relevant attribute of the file, denoted by a key value pair (key value pair), such as: width=1024, where the key is width,value to 1024. File meta data is a list of file attributes that can contain multiple key-value pairs.

Github:https://github.com/happyfish100/fastdfs
A well-written blog: http://tech.uc.cn/?p=221

2, install Fastdfs

Reference Documentation:
Https://github.com/happyfish100/fastdfs/blob/master/INSTALL

2.1, install the Build tool
-y‘Development Tools‘-y
2.2, install the Libfastcommon class library

Must first follow this, otherwise error:

Cc-wall -d_file_offset_bits= - -d_gnu_source - G - o -ddebug_flag -dos_linux -dioevent_use_epoll - C - o ../common/fdfs_global.O../common/fdfs_global.C- I.../common- I./usr/include/fastcommon../common/fdfs_global.C: -: -: Fatal Error:logger.H:no such fileorDirectory#include "Logger.h"^compilation terminated.........

Download the installation directly:

wget https://github.com/happyfish100/libfastcommon/archive/master.zipunzip master.zipcd libfastcommon-master./make.sh./make.sh install
2.3, install Fastdfs
wget  https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gztar -zxvf V5.05.tar.gz cd fastdfs-5.05/./make.sh./make.sh install
2.4, Start Fastdfs

After installing the configuration file in directory/etc/fdfs.

mv storage.conf.sample  storage.confmv tracker.conf.sample tracker.conf

First modify the configuration file:
/etc/fdfs/tracker.conf, modify the path to the/data/fdfs directory.

basetoand log filesbase_path=/data/fdfs

Start:
/usr/bin/fdfs_trackerd/etc/fdfs/tracker.conf start

To modify a configuration file:
/etc/fdfs/storage.conf, modify the path to the/data/fdfs directory, and configure the Tracker_server address.

# the base path to store data and log filesbase_path=/data/fdfs# tracker_server can ocur more than once, and tracker_server format is#  "host:port", host can be hostname or ip addresstracker_server=192.168.1.36:22122# store_path#, based 0, if store_path0 not exists, it‘s value is base_path# the paths must be existstore_path0=/data/fdfs#store_path1=/home/yuqing/fastdfs2

/usr/bin/fdfs_storaged/etc/fdfs/storage.conf start

When you start, look at the log without errors to indicate that the startup was successful.
To view the FDFS process:

#ps-ef | grep fdfsRoot19880     1  0  +: the?xx:xx:xx/usr/bin/fdfs_trackerd/etc/fdfs/tracker. confStartroot20050     1  0  A: ,?xx:xx:xx/usr/bin/fdfs_storaged/etc/fdfs/storage. confStartroot20060 19915  0  A: ,pts/1    xx:xx:xxgrep--color=auto Fdfs

2.5 Installing Nginx + LUA + Fastdfs module
Download Fastdfs-nginx-module Module
Https://github.com/happyfish100/fastdfs-nginx-module
Download Openresty nginx +lua Bag

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zipunzip fastdfs-nginx-module-master.zipwget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gztar -zxvf ngx_openresty-1.7.10.1.tar.gz

Compile and install: note here that additional parameters are required.
One is the stub_status statistic module and one is the Realip module.
Reference Address:
Http://blog.danielss.com/?p=80
Http://wiki.nginx.org/HttpRealipModuleChs

Yum- yInstall Pcre-develOpenSSL OpenSSL-develCD Ngx_openresty-1.7. Ten. 1./configure-- with-luajit -- with-http_stub_status_module -- with-http_ssl_module -- with-http_realip_module --Add-module=/root/fastdfs-nginx-module-master/SRC Gmakegmake Install

Nginx +lua Installation path:

 nginx path prefix:  "/usr/local/openresty/nginx"  nginx binary file :  "/usr/local/openresty/ Nginx/sbin/nginx " nginx configuration prefix: "/usr/local/openresty/nginx/conf "  nginx configuration file :  "/usr/local/ openresty/nginx/conf/nginx.conf " nginx pid file :  "/usr/local/openresty/nginx/logs/nginx.pid"  nginx Error log  file :  "/usr/local/openresty/nginx/logs/error.log"  nginx http  access log  file : "/usr/local/openresty/nginx/logs/access.log " 

Start, restart Nginx

#启动/usr/local/openresty/nginx/sbin/nginx#重启 /usr/local/openresty/nginx/sbin/nginx -s restart
3, Test Fastdfs

Configure the service:

cd /etc/fdfsmv client.conf.sample client.conf

To modify the configuration:

# the base path to store log filesbase_path=/data/fdfs# tracker_server can ocur more than once, and tracker_server format is#  "host:port", host can be hostname or ip addresstracker_server=192.168.1.36:22122

Configure Nginx:

cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/mkdir /data/ngx

Modify the mod_fastdfs.conf configuration file: Modify the Tracker port or the Nginx will not start. The path must also be modified, otherwise the file cannot be found.

# the base path to store log filesbase_path=/data/ngx# FastDFS tracker_server can ocur more than once, and tracker_server format is#  "host:port", host can be hostname or ip address# valid only when load_fdfs_parameters_from_tracker is truetracker_server=192.168.1.36:22122# store_path#, based 0, if store_path0 not exists, it‘s value is base_path# the paths must be exist# must same as storage.confstore_path0=/data/fdfs

Copy the configuration file, otherwise nginx can not start, error:

[ --Geneva- -  One: -: -] ERROR-file: Ini_file_reader.c, line:315, includefile "http.conf"  notexists, line:"#include http.conf"[ --Geneva- -  One: -: -] ERROR-file:/root/fastdfs-nginx-module-master/src/common.c, line:155, Load conffile "/etc/fdfs/mod_fastdfs.conf"Fail, RET code:2 -/Geneva/ -  One: -: -[Alert]19969#0: WorkerProcess 2753Exited withFatal code2  andCannot be respawned

Workaround:

cp /root/fastdfs-master/conf/http.conf /root/fastdfs-master/conf/mime.types  /etc/fdfs

Nginx Configuration Modification vi/usr/local/openresty/nginx/conf/nginx.conf

    server {        listen       80;        server_name  localhost;        charset utf8;        location /M00 {                alias /data/fdfs/data;                ngx_fastdfs_module;        }   ......

Create a connection

ln -s /data/fdfs/data /data/fdfs/data/M00

Restart Nginx.
Test command:

"test fastdfs" > test.html /usr/bin/fdfs_test /etc/fdfs/client.conf upload test.html

Upload successful, execution result:

This was FASTDFS client test program v5. inCopyright (C) -, Happy Fish/yuqingfastdfs May is copied only under the terms of the GNU generalpublic License V3, which could be foundinchThe FastdfsSourceKit. Please visit the Fastdfs Home Page http://www.csource.org/ forMore detail. [ --Geneva- -  -: .: the] Debug-base_path=/data/fdfs, connect_timeout= -, network_timeout= -, tracker_server_count=1, anti_steal_token=0, Anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600S, use_storage_id=0, Storage server ID count:0Tracker_query_storage_store_list_without_group:server1.Group_name=, ip_addr=192.168. 1., port=23000Group_name=group1, ip_addr=192.168. 1., port=23000Storage_upload_by_filenamegroup_name=group1, Remote_filename=m00/xx/xx/wkgc1fu7zxgaf19vaaaadcvbslg01.htmlSourceIP Address:192.168. 1.filetimestamp= --Geneva- -  -: .: thefile size= -fileCrc32=3418468952ExamplefileUrl:http://192.168.1.36/group1/m00/00/00/wkgc1fu7zxgaf19vaaaadcvbslg01.htmlStorage_upload_slave_by_filenamegroup_name=group1, Remote_filename=m00/xx/xx/wkgc1fu7zxgaf19vaaaadcvbslg01_big.htmlSourceIP Address:192.168. 1.filetimestamp= --Geneva- -  -: .: thefile size= -fileCrc32=3418468952ExamplefileUrl:http://192.168.1.36/group1/m00/00/00/wkgc1fu7zxgaf19vaaaadcvbslg01_big.html

Test access:

curl http://192.168.1.36/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html

If the "Test Fastdfs" description is returned, the configuration is successful. Each of the above steps should be correct.

To view the Nginx error log:
Tail-f/usr/local/openresty/nginx/logs/error.log

4, summary

Fastdfs is a very good distributed file system. Simple configuration, multiple machines can be deployed, and the official to a nginx module, can be directly accessed with Nginx, very convenient. This reduces the middle of the Tomcat layer and is highly efficient.
The next step is to study the image compression of Lua. Image compression is done directly in the Nginx layer. More efficient, while the picture reads Fastdfs files.

Fastdfs (1): Centos7 installation Fastdfs+nginx Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.