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

A graphic tutorial on how to install MySQL in Windows

Abstract: This article mainly explains how to ins...

Docker installation of Nginx problems and error analysis

question: The following error occurred when insta...

Web Design Tutorial (3): Design Steps and Thinking

<br />Previous tutorial: Web Design Tutorial...

How to solve the problem of case insensitivity in MySQL queries

question Recently, when I was completing a practi...

A brief discussion on group by in MySQL

Table of contents 1. Introduction 2. Prepare the ...

MySql 8.0.11 installation and configuration tutorial

Official website address: https://dev.mysql.com/d...

MySQL Server IO 100% Analysis and Optimization Solution

Preface During the stress test, if the most direc...

Vue3.0 handwriting magnifying glass effect

The effect to be achieved is: fixed zoom in twice...

A brief discussion on MySQL B-tree index and index optimization summary

MySQL's MyISAM and InnoDB engines both use B+...

Mysql backup multiple database code examples

This article mainly introduces the Mysql backup m...

Specific use of Linux dirname command

01. Command Overview dirname - strip non-director...

How to avoid data loop conflicts when MySQL is configured with dual masters

I wonder if you have ever thought about this ques...

Tutorial on installing VMWare15.5 under Linux

To install VMWare under Linux, you need to downlo...