CentOS Installation Fastdfs+nginx+fastdfs-nginx-module Installation configuration

Source: Internet
Author: User
Tags file upload install openssl openssl centos port number

Objective:

Previous projects uploaded files are saved locally or under a shared folder on the local area network. Due to the amount of data, the server load balance (the extension of some images can not be accessed by the problem processing), and other factors, the idea of using Fastdfs to file management, spent a few days to bite the bullet to learn how to install the configuration, Because of the Linux Foundation is not good, installation configuration up feel a little laborious, have to go to find some information at any time, fortunately after these days of efforts to install configuration Fastdfs finally finished, the final pay is not in vain, the following is a personal opinion, if there is error, please guidance. Do not know Fastdfs's children's shoes can first go to understand,

First, Introduction

Fastdfs is an open source lightweight Distributed File system that manages files, including file storage, file synchronization, file access (file uploads, file downloads), and so on, which solves the problem of large capacity storage and load balancing. Especially suitable for the document as the carrier of online services, such as photo albums, video sites and so on

The 1.FASTDFS architecture is illustrated as follows:

The FASTDFS server has three roles: a Tracking Service (tracker server), storage servers (storage server), and clients (client).

Tracker server: Tracking servers, mainly to do scheduling work, the role of load balancing. The state information of all storage groups and storage servers in the cluster is recorded in memory, which is the hub of interaction between client and data server. More streamlined than the master in GFs, which does not record file index information and consumes very little memory.
Storage server: Storage server (also known as storage node or data server), file and file attributes (meta data) are saved to the storage server. Storage server directly utilizes the OS's file system call to manage files.
Client: Clients, as initiators of a business request, use the TCP/IP protocol to interact with the tracker server or storage node through proprietary interfaces.
Second, file upload and download the interactive process

Client asks the tracker server to upload the storage server

1.client->tracker server (returns an available storage server with the data returned as the IP address and port of the storage server)

2.client directly with 1 returned Storage server to establish a connection-> file upload successful->storage server will return the newly generated file id-> end

The steps for the file download process are as follows:

1. Client asks tracker server can download the storage server for the specified file, with a parameter of file ID (including group name and filename);

2. Tracker server returns an available storage server;

3. Client directly and the storage server to establish a connection to complete the file download.

System Environment CENTOR7 64 bits, this article installs only one tracker and storage on the same server

Preparing the package for installation

First download the following installation package (download the address, please see the last Download Address section of this article):

Third, the installation process

Since fastdfs5.0.5 relies on libevent, we first install libevent, where openssl,pcre,zlib is nginx dependent, and because of the need to install the software using the Apt-get command, there are situations where resources are unavailable or invalid directives , so having to manually install these dependencies is a real hassle, as we'll say here, explaining the document above to prevent some children's shoes from being misled.

The installation steps are as follows:

Log on to the Linux system and switch users to the root user

1. Install Libevent

Cd/root (directory for storing libevent compressed files)

TAR-ZXVF libevent-2.0.22-stable.tar.gz

CD libevent-2.0.22-stable

Make clean
./configure
Make

Make install

Finally, if it is

32-bit Linux:

ln–s/usr/local/libevent/libevent-2.0.so.5/usr/lib/
64-bit Linux:

Ln-s/usr/local/libevent/libevent-2.0.so.5/usr/lib64/
2.FastDFS Installation

TAR-ZXVF fastdfs_v4.06.tar.gz

CD fastdfs_v4.06

./make.sh

./make.sh Install

If there is no error to indicate that the installation was successful, creating the above soft link installation is basically no problem

2.1: After the installation is successful, the/etc/fdfs directory will have the relevant configuration file:

Client.conf

Http.conf

Mime.types

Storage.conf

Tracker.conf

To modify a configuration file:

Configure Tracker

Gedit tracker.conf

2.2: Modify these items of the configuration file (modified according to the data):

Disabled=false #启用配置文件
port=22122 #设置tracker的端口号
Base_path=/data/fastdfs/trackerd #设置tracker的数据文件和日志目录 (need to be created in advance)
http.server_port=18080 #设置http端口号
Start the Trackerd service
/usr/local/bin/fdfs_trackerd/etc/fdfs/tracker.conf
If you need to turn on the boot automatically:
# echo '/usr/local/bin/fdfs_trackerd/etc/fdfs/tracker.conf restart ' >>/etc/rc.d/rc.local
See if the Trackerd service starts by using the following command:

NETSTAT-TUPLN | grep trackerd

You can also check the log file to see if there is an error (/data/fastdfs/tracker/logs is the path of the previous configuration), if there is no error, should be Trackerd service started.

Configure storage.conf

Gedit storage.conf

Disabled=false #启用配置文件
Group_name=group1 #组名, modified according to the actual situation
port=23000 #设置storage的端口号
Base_path=/data/fastdfs/storage #设置storage的日志目录 (need to be created in advance)
Store_path_count=1 #存储路径个数, need to match the number of Store_path
Store_path0=/data/fastdfs/storage #存储路径
tracker_server=192.168.188:22122 #tracker服务器的IP地址和端口号
Http.server_port=80 #设置http端口号
Start the Trackerd service
/usr/local/bin/fdfs_storage/etc/fdfs/storage.conf
Setting up Boot
# echo '/usr/local/bin/fdfs_storaged/etc/fdfs/storage.conf restart ' >>/etc/rc.d/rc.local
See if the Storaged service starts by using the following command:

NETSTAT-TUPLN | grep storaged

You can also check the log file to see if there is an error (/data/fastdfs/storage/logs is the path previously configured), if there is no error, should be storaged service started

Configuration http.conf have anti-theft chain, can be configured according to need,:

Http.anti_steal.check_token=true
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=fastdfssecretkey001
Http.anti_steal.token_check_fail=/data/fastdfs/img/anti-steal.jpg
Http.anti_steal.check_token: Whether to open the Anti-Theft chain, the default is False
Http.anti_steal.token_ttl: The effective time length of the token of the anti-theft chain
Http.anti_steal.secret_key: Generate token key
Http.anti_steal.token_check_fail: If is anti-theft chain, need to show the picture path

Configure the client and test the upload

Gedit client.conf

Modify these items of the configuration file (modified according to the data):
Base_path=/data/fastdfs/client
tracker_server=192.168.1.188:22122

Then we can do a simple file upload test.

Cd/usr/local/bin

The image above is client.conf, and successful execution returns the relative path of the corresponding group +m00+ picture (also known as the path to the storage configuration above).

If you need to use the browser to access the picture, you need to nginx to do the reverse proxy, direct access is not possible.

Then you need to install and configure Nginx, the beginning of the article said, Openssl,pcre,zlib is nginx dependence, if you can not use the command to install automatic installation, you need to manually install

Install Nginx dependencies (the version used below is for personal use.) have no special meaning)

1. Install Pcre

Get the Pcre compile installation package to get the current latest version on http://www.pcre.org/

Unzip the pcre-8.31.tar.gz package.

Enter the extract directory and execute./configure.

Execute make and make install commands sequentially

2. Install OpenSSL

Gets the OpenSSL compile installation package, on http://www.openssl.org/source/, to get the current latest version.

Unzip the openssl-1.0.2h.tar.gz package.

Enter the extract directory and execute./config.

Execute make and make install commands sequentially

3. Install Zlib

Gets the zlib compile installation package, on http://www.zlib.net/, to get the current latest version.

Unzip the zlib-1.2.5.tar.gz package.

Enter the extract directory and execute./configure.

Execute make and make install commands sequentially

4. So far: Nginx's dependent modules have been installed and can then be installed Nginx

TAR-ZXVF nginx-1.10.1.tar.gz

CD nginx-1.10.1

./configure--prefix=/usr/local/nginx (--prefix is installed to that directory)

Make

Make install

5. Nginx configuration after installation of Nginx

Cd/usr/local/nginx/conf

Gedit nginx.conf

Add the following configuration to the server node

location/group1/m00{
Root/fastdfs/storage/data;
Ngx_fastdfs_module;
}

This time you listen to the port after the default is 80, before I configure the storage file Http.server_port useful to 80, if you need to change other ports, can be modified according to the circumstances

Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/share/nginx/html;
}

6. Start Nginx

/usr/local/nginx/sbin/nginx

Use the following command to see if Nginx is started:

NETSTAT-TUPLN | grep nginx

If you succeed, you will see Nginx monitoring information.

7. Install and configure the Nginx plugin Fastdfs-nginx-module

TAR-ZXVF fastdfs-nginx-module_v1.16.tar.gz

CD fastdfs-nginx-module/src/
Gedit Config (This step is very important, very important, very important (important things say three times) I was some articles dizzy a few days, resulting in the launch of the Nginx module when there are errors, if the above start Nginx error, do not worry, then install Nginx plug-ins, Here is configured to recompile again, and then reboot nginx OK)

core_incs= "$CORE _incs/usr/local/include/fastdfs/usr/local/include/fastcommon/"
core_libs= "$CORE _libs-l/usr/lib-lfastcommon-lfdfsclient"
Then you need to add the plug-in to the Nginx
Cd/root/nginx-1.10.1/
./configure--add-module=/root/fastdfs-nginx-module/src/
Make
Make install

5. Copy and modify the Fastdfs-nginx-module configuration file
Cp/root/fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs
Vim Modify/etc/fdfs/mod_fastdfs.conf Save exit
Modify the following:

tracker_server=192.168.1.188:22122
Store_path0=/data/fastdfs/storage
Base_path=/data/fastdfs/storage/data
Url_have_group_name = True (this should be set to true when multiple tracker are configured)

Establish a soft connection (the path where data is storage in the configuration file)

Ln-s/data/fastdfs/storage/data/data/fastdfs/storage/data/m00

Copy 2 files under the fastdfs_v4.06 configuration directory to the/etc/fdfs directory:

Cp/usr/local/fastdfs-5.05/conf/http.conf.
Cp/usr/local/fastdfs-5.05/conf/mime.types.

Finally, I will upload the file test again:

Cd/usr/local/bin

uploaded a picture of the test

Then the browser to enter their own ip+ port number + file path (IP swap binding corresponding domain name also line)

Related Article

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.