1. What is FastDFS

FastDFS is an open source distributed file system written in C language. FastDFS is tailor-made for the Internet. It takes into account redundant backup, load balancing, and linear expansion, and emphasizes high availability and performance. It is easy to set up a high-performance file server cluster to provide file uploading and downloading services. The FastDFS architecture includes Tracker Server and Storage Server. The client requests the Tracker Server to upload and download documents. The Storage Server finally uploads and downloads files through the Tracker Server. The Tracker server is used for load balancing and scheduling. During file uploading, you can find the Storage Server based on certain policies to provide file uploading service. You can call a tracker a tracing server or a scheduling server. The Storageserver is used to store files. The files uploaded by the client are finally stored on the Storageserver. The Storageserver does not implement its own file system but uses the file system of the operating system to manage files. A storage can be called a storage server.

The server has two roles: Tracker: Manages the cluster. Tracker can also implement the cluster. Each tracker node has equal status. Collect Storage cluster status. Storage: Actual file Storage is divided into multiple groups. The files saved in each group are different. Each group can have multiple members. The contents stored in the group members are the same, and the status of the group members is the same. There is no concept of master and slave.

2. File Uploading Process

ID
ID

File name format is as follows
group1/M00/00/00/rBAABVzRPC-AJVSQAAHqEHLGutU563.jpg
Copy the code
  • Group name: indicates the name of the storage group in which the file is uploaded. The storage server returns a message after the file is successfully uploaded and the client needs to save the file by itself.

  • Virtual disk path: virtual path configured for the storage, which corresponds to the disk option store_path*. If store_path0 is configured, it is M00, if store_path1 is configured, it is M01, and so on.

  • Data two-level directory :storage A two-level directory created by the storage server in each virtual disk path to store data files.

  • File name: Different from file upload. A file name is generated by a storage server based on specific information. The file name includes the IP address of the source storage server, time stamp of file creation, file size, random number, and file name extension.

3. File download process

4. Simple FastDFS architecture

5. FastDFS installation

  • The FastDFS and corresponding Nginx modules are available below

Download address extraction code: NW6T

5.1 Installing the FastDFS Dependency Package
  1. unziplibfastcommon-master.zip
  2. Into thelibfastcommon-masterA directory of
  3. perform./make.sh
  4. performsudo ./make.sh install
5.2 installation fastdfs
  1. unzipfastdfs-master.zip
  2. Into thefastdfs-masterIn the directory
  3. perform./make.sh
  4. performsudo ./make.sh install
5.3 Configuring the Tracker Server
  1. sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
  2. in/home/python/Create a directory in a directoryfastdfs/tracker
  3. The editor/etc/fdfs/tracker.confThe configuration filesudo vim /etc/fdfs/tracker.confModify thebase_path=/home/python/fastdfs/tracker
5.4 Configuring a Storage Server Storage
  1. sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
  2. in/home/python/fastdfs/Create a directory in a directorystorage
  3. The editor/etc/fdfs/storage.confThe configuration filesudo vim /etc/fdfs/storage.confModified contents:base_path=/home/python/fastdfs/storage store_path0=/home/python/fastdfs/storage Tracker_server = IP address of your Ubuntu VM :22122
5.5 Starting the Tracker and storage

sudo service fdfs_trackerd start

sudo service fdfs_storaged start

On the cloud server

sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

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

5.6 Checking whether the installation is successful
  1. sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
  2. The editor/etc/fdfs/client.confThe configuration filesudo vim /etc/fdfs/client.confModified contents:base_path=/home/python/fastdfs/tracker Tracker_server = IP address of your Ubuntu VM :22122
  3. Upload file test:fdfs_upload_file /etc/fdfs/client.confTo upload a picture file if returned similargroup1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpgThe fileidThe file is uploaded successfully
5.7 Installing the Nginx and Fastdfs-nginx-module Web Modules

Start by installing the nginx dependency libraries

  • Install GCC g++ dependent libraries
sudo apt-get install build-essential
sudo apt-get install libtool
Copy the code
  • Install the PCRE dependency library (www.pcre.org/)
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
Copy the code
  • Install zlib dependencies (www.zlib.net)
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
Copy the code
  • Install SSL dependency libraries (16.04 Default installed)
sudo apt-get install openssl
Copy the code
  1. unzipNginx, version 1.8.1 -. Tar. Gz
  2. unzipfastdfs-nginx-module-master.zip
  3. Enter theNginx, version 1.8.1 -In the directory
  4. perform/configure --prefix=/usr/local/nginx --add-module=/home/ubuntu/fastdfs-nginx-module-master Specifies the absolute path to the decompressed directory/SRC
  5. sudo make sudo make install
  6. Sudo cp fastdfs-nginx-module-master SRC mod_fastdfs.conf /etc/fdf/mod_fastdfs.conf in the decompressed directory
  7. sudo vim /etc/fdfs/mod_fastdfs.confModified contents:
Connect_timeout =10 Tracker_server = IP address of the Ubuntu VM :22122 url_have_group_name=true
store_path0=/home/python/fastdfs/storage
Copy the code
  1. Sudo cp HTTP. Conf /etc/fdf/http. conf in the conf directory of the fastdfs-master directory
  2. Mime.types /etc/fdfs.mime.types in conf directory of fastdfs-master directory decompressed by sudo cp
  3. sudo vim /usr/local/nginx/conf/nginx.conf

Add the following configuration information to the HTTP section:

server { listen 8888; server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}Copy the code

11. Start nginx

sudo /usr/local/nginx/sbin/nginx