Nginx+FastDFS to build an image server

Nginx+FastDFS to build an image server

Installation Environment

Centos

Environment Dependency:

yum -y install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
# If you don't have make, you need to install make
yum install -y make

Installation and configuration process

1. Create a fastdfs directory:

mkdir -p /fastdfs/tracker
mkdir -p /fastdfs/storage
mkdir -p /fastdfs/logs

1. Download and install libfastcomman (basic environment)

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh && ./make.sh install
# Copy the file to solve the problem of lib configuration file path in FastDFS.
cp /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
cp /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

2. Download and install FastDFS. After the installation is complete, the default configuration file directory is: /etc/fdfs/ , the default command is placed in /usr/bin/ , and starts with fdfs_ .

wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
tar -zxvf V5.05.tar.gz
cd fastdfs-5.05/
./make.sh && ./make.sh install

3. Configure tracker

# Copy the configuration file to the /etc/fdfs directory cd .../fastdfs-5.05/conf
cp * /etc/fdfs/
sudo vim tracker.conf

Modify bath_path and configure it as follows:

base_path=/fastdfs/tracker

Start the tracker:

fdfs_trackerd /etc/fdfs/tracker.conf start

4. Configure storage

vim storage.conf

Modify the configuration items and configure them as follows:

#Log directory base_path=/fastdfs/storage  
#Storage directory store_path0=/fastdfs/storage   
#tracker node tracker_server=192.168.1.4:22122

Start storage:

fdfs_storaged /etc/fdfs/storage.conf start

5. Configure the client

vim-client.conf

The configuration items are as follows:

#tracker node tracker_server=192.168.1.4:22122
#Log path base_path=/fastdfs/logs

6. Install nginx and fastdfs-nginx-module. It is not recommended to use yum or apt to install nginx directly, because when installing the fastdfs-nginx-module module, it needs to be compiled again, which is very troublesome.

# Download the fastdfs-nginx-module module cd /fastdfs
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1 fastdfs-nginx-module
# Download nginx
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
# Install nginx and fsatdfs-nginx-module
cd nginx-1.12.1
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/fastdfs/fastdfs-nginx-module/src
make
make install

7. Configure mod_fastdfs.conf file

cd /fastdfs/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf

The configuration items are as follows:

connect_timeout=10 # Client access file connection timeout (unit: seconds)
base_path=/fastdfs/tmp # Storage log path tracker_server=192.168.1.4:22122 # Tracker service IP and port url_have_group_name=true # Access link prefix plus group name group_name=group1 # One-to-one correspondence with storage groupname store_path0=/fastdfs/storage # File storage path

8. Configure nginx

cd /opt/nginx/conf/
vim nginx.conf

The configuration items are as follows, that is, when accessing resources starting with group1, they are handed over to fastdfs-nginx-module for processing:

# Listen for domains with group0 to group9, and hand them over to the fastdfs-nginx-module module for processing location ~/group([0-9])/ {
ngx_fastdfs_module;
}

test

1. Upload pictures

fdfs_upload_file /etc/fdfs/client.conf ~/Desktop/test.png

At this point a string will be returned to us.

2. Access the test, enter in the browser:

192.168.1.4/group1/M00/00/00/wKgBBF6Cu4GATwTvABy5G9p0iEE119.jpg

Access successful!

This is the end of this article about how to build an image server with Nginx+FastDFS. For more information about building an image server with Nginx+FastDFS, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Centos7 configuration fastdfs and nginx distributed file storage system implementation process analysis
  • Example of using Nginx reverse proxy to go-fastdfs
  • SpringBoot integrates FastDFS+Nginx to integrate Token-based anti-hotlinking method
  • How to install and configure FastDFS and integrate it with Nginx-1.13.3
  • Fastdfs and nginx compression image ratio
  • nginx FastDFS distributed storage module testing method
  • FastDFS and Nginx integration to achieve code analysis

<<:  Detailed explanation of using Vue custom tree control

>>:  Tutorial on installing mysql-8.0.18-winx64 under Windows (with pictures and text)

Recommend

How to implement digital paging effect code and steps in CSS

A considerable number of websites use digital pagi...

Vue3.0 project construction and usage process

Table of contents 1. Project construction 2: Dire...

Code analysis of user variables in mysql query statements

In the previous article, we introduced the MySQL ...

MySQL sql_mode analysis and setting explanation

When inserting a set of data into the MySQL datab...

How to build a virtual machine with vagrant+virtualBox

1. Introduction Vagrant is a tool for building an...

More elegant processing of dates in JavaScript based on Day.js

Table of contents Why use day.js Moment.js Day.js...

How to operate MySql database with gorm

1. Setting case sensitivity of fields in the tabl...

Building a Redis cluster on Docker

Table of contents 1. Pull the image 2. Create a R...

JavaScript to achieve mouse tailing effect

Mouse effects require the use of setTimeout to ge...

How to create a stored procedure in MySQL and add records in a loop

This article uses an example to describe how to c...

MySQL quickly inserts 100 million test data

Table of contents 1. Create a table 1.1 Create te...

Use docker to deploy tomcat and connect to skywalking

Table of contents 1. Overview 2. Use docker to de...

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version: Method 1: Use the SET PASSWORD...

W3C Tutorial (4): W3C XHTML Activities

HTML is a hybrid language used for publishing on ...