Linux System: Building Nginx and FastDFS File Management Middleware under centos7

This article source code: GitHub. Click here || GitEE. Click here

Introduction to FastDFS

1. Basic concepts

FastDFS is an open source lightweight distributed file system. It manages files. Its functions include file storage, file synchronization, file upload, file download and so on. It solves the problems of large capacity storage and load balancing.

2. Overview of the Environment

1. Gcc compilation environment exists by default, Centos7 Virtual Machine
 2. Installing the LibFastCommon environment
 3. FastDFS Middleware Installation
 4. Installation of Nginx proxy server

Installation of LibFastCommon

Core process

Download - > Unzip - > Compile - > Install

## download
[root@localhost mysoft]# wget
https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
## decompression
[root@localhost mysoft]# tar -zxvf V1.0.38.tar.gz
[root@localhost mysoft]# cd libfastcommon-1.0.38/
## Compile
[root@localhost libfastcommon-1.0.38]# ./make.sh
## install
[root@localhost libfastcommon-1.0.38]# ./make.sh install

Installation of FastDFS

Process: Download - > Decompress - > Compile - > Install - > Create Related Paths - > Configuration Tracker - > Install Configuration Data Storage - > Configuration Client - > Nginx Environment Configuration

1. Basic Installation Steps

## download
[root@localhost mysoft]# wget
https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
## decompression
[root@localhost mysoft]# tar -zxvf V5.11.tar.gz 
## Compile
[root@localhost mysoft]# cd fastdfs-5.11/
[root@localhost fastdfs-5.11]# ./make.sh 
## install
[root@localhost fastdfs-5.11]# ./make.sh install

2. Create a Relevant Path

Use follow-up instructions.

[root@localhost data]# mkdir -p /data/fastdfs/log
[root@localhost data]# mkdir -p /data/fastdfs/data
[root@localhost data]# mkdir -p /data/fastdfs/tracker
[root@localhost data]# mkdir -p /data/fastdfs/client

3. Configuration tracker

Tracker - > Tracker

1) View configuration files

Note the conversion of the directory here, here is the sample, the specific configuration also needs to do it yourself.

[root@localhost fastdfs-5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
total 24
client.conf.sample
storage.conf.sample
storage_ids.conf.sample
tracker.conf.sample

2) Configure tracker.conf file

[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# vim tracker.conf
## Focus on the following configurations
## Basic paths to store data and log files
base_path=/data/fastdfs/tracker
## Http Service Port
http.server_port=80
## Default Provide Service Port
port=22122

3) Start tracker

## start-up
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
## View state
[root@localhost fdfs]# netstat -apn|grep fdfs

4. Configuring data storage

1) View configuration files

[root@localhost fastdfs-5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
storage.conf.sample

2) Configure storage.conf file

[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# vim storage.conf
## Focus on the following configurations
## storage Storage storage data and log Tracking Path
base_path=/data/fastdfs/data
## Default group name
group_name=group1
## Default port. storage port number of the same group must be the same
port=23000
## Configure a storage path
store_path_count=1
store_path0=/data/fastdfs/data
## Configure tracker IP and port
tracker_server=192.168.72.130:22122

3) Start storage services

## start-up
[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
## View process
[root@localhost fdfs]# netstat -apn|grep fdfs
tcp 0:22122  LISTEN      4845/fdfs_trackerd  
tcp 0:45422  SYN_SENT    5410/fdfs_storaged
## View the startup log
[root@localhost fdfs]# tail -f /data/fastdfs/data/logs/storaged.log
## Log Show: Single FastDFS Installation Successful
set tracker leader: 192.168.72.130:22122
## Check if Storage and Tracker are communicating
[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
Storage 1:
	id = 192.168.72.130
	ip_addr = 192.168.72.130 (localhost.localdomain)  ACTIVE

5. Configuring client test

1) View configuration files

[root@localhost /]# cd /etc/fdfs
[root@localhost fdfs]# ll
total 40
client.conf.sample

2) Configure client.conf file

[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
## Focus on the following configurations
## client data and log directories
base_path=/data/fastdfs/client
## Configure tracker IP and port
tracker_server=192.168.72.130:22122

3) Client Testing

Call client file upload command

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf

Return the relative path and number of file upload

group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

[root@localhost fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /data/img/img1.jpg 
group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

So FastDFS single environment is installed, the steps are a bit complicated, but this is life.

The file was successfully uploaded to the storage server, but the download was not yet available. Nginx servers need to be installed to support Http access to files.

IV. Installation of Nginx

1. Download and decompress Nginx

## Download nginx
[root@localhost mysoft]# wget 
http://nginx.org/download/nginx-1.15.2.tar.gz
## Decompression nginx
[root@localhost mysoft]# tar -zxvf nginx-1.15.2.tar.gz

2. Download and decompress Fast-Nginx

## Download fastdfs-nginx
[root@localhost mysoft]#wget 
https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
## Decompressing fastdfs-nginx
[root@localhost mysoft]# mv 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip fast-nginx.zip
[root@localhost mysoft]# unzip fast-nginx.zip
[root@localhost mysoft]# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1/ 
fastdfs-nginx-module

3. Installation Must Depend on

## pcre-devel environment
[root@localhost nginx-1.15.2]# yum install -y pcre pcre-devel
## zlib-devel environment
[root@localhost nginx-1.15.2]# yum install -y zlib zlib-devel
## openssl-devel environment
[root@localhost nginx-1.15.2]# yum install -y openssl openssl-devel

4. Configuration and installation

[root@localhost nginx-1.15.2]# ./configure --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
[root@localhost nginx-1.15.2]# make && make install

5. Error Resolution

Version issues result in Fast-Nginx having to use this fix version.

https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/usr/local/mysoft/nginx-1.15.2'
make: *** [build] Error 2

6. View installation results

The following indicates that the installation was successful.

[root@localhost nginx-1.15.2]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src

V. Test picture access

1. Configuring Client

## Mobile Profile
[root@localhost src]# pwd
/usr/local/mysoft/fastdfs-nginx-module/src
[root@localhost src]# ll
total 76
Apr 14  2017 mod_fastdfs.conf
[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/
[root@localhost fdfs]# pwd
/etc/fdfs
[root@localhost fdfs]# vim mod_fastdfs.conf 
## Adjust the following configuration
## Link timeout
connect_timeout=20
## Configure tracker IP and port
tracker_server=192.168.72.130:22122
## Path contains group
url_have_group_name = true
# Must be the same as storage configuration
store_path0=/data/fastdfs/data

2. Improve FastDFS configuration

[root@localhost fdfs]# cd /usr/local/mysoft/fastdfs-5.11/conf/
[root@localhost conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/

3. Configure Nginx

Add the following configuration under Nginx's 80 service port. Note that the path here is the path automatically generated by the Nginx installation.

[root@localhost nginx]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
server {
    listen       80;
    
    location ~/group([0-9])/M00 {
        root /data/fastdfs/data;
        ngx_fastdfs_module;
    }
}

View configuration results

[root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src

So the configuration is successful.

4. The End of Witnesses

Start the Nginx service.

## start-up
/usr/local/nginx/sbin/nginx
## Stop it
/usr/local/nginx/sbin/nginx -s stop
## restart
/usr/local/nginx/sbin/nginx -s reload

5. Accessing Uploaded Pictures

Meow, actually succeeded, see next article.

http://192.168.72.130
/group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

6. Source code address

GitHub·address
https://github.com/cicadasmile/linux-system-base
GitEE·address
https://gitee.com/cicadasmile/linux-system-base

Tags: Programming Nginx github vim yum

Posted on Mon, 07 Oct 2019 03:06:37 -0700 by chanchelkumar