● CentOS7安装FastDFS

Boutique: CentOS7 and FastDFS build image server

brief introduction

FastDFS is an open source high-performance Distributed File System. It manages files. Its main functions include: file storage, file synchronization, file access (file upload, file download), etc. It mainly solves the problem of massive data storage, especially for small and medium-sized files (recommended range: 4KB < file)_ Size < 500MB).

FastDFS system has three roles: tracker server, storage server and client.

  • Client: the client, as the initiator of the service request, uses TCP/IP protocol to interact with the tracker server or storage node through a proprietary interface.
  • Tracker Server: coordinator of FastDFS, which plays a balanced role; it is responsible for managing all storage servers and groups. After each storage is started, it will connect tracker to inform itself of its group information and maintain periodic heartbeat. Tracker will establish a mapping table of group = = > [storage serverlist] according to the heartbeat information of storage.
  • Storage Server: Storage Server, which mainly provides capacity and backup services. It is organized by group (volume, group or volume). A group contains multiple storage machines, and the data is backed up for each other. The storage space is subject to the storage with the smallest capacity in the group. Therefore, it is recommended that multiple storage in the group be configured as much as possible to avoid the waste of storage space.


  • CentOS7
  • libfastcommon 1.0.38
  • fastdfs 5.11
  • nginx-1.15.2

Note: the version of the software should be consistent, otherwise there may be version incompatibility

1. Download and install libfastcommon

  1. Download libfastcommon

    wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
  2. Unzip file

    tar -zxvf V1.0.38.tar.gz
    cd libfastcommon-1.0.38
  3. Compile and install

    ./make.sh install
  4. Create soft link, because the Lib directory set by FastDFS main program is / usr/local/lib, so we need to create soft link

    ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
    ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
    ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
    ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

## 2. Download and install FastDFS

1. Download FastDFS

    wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz

2. decompression

    tar -zxvf V5.11.tar.gz
    cd fastdfs-5.11

3. Compile and install

    ./make.sh install

4. Installation results

    - The default installation directory, execute the command cd /etc/init.d to see the following:

    - Configuration file: cd /etc/fdfs, file with four. sample suffixes (automatically generated fdfs template configuration file)


    - Execute the command:

    ls -la /usr/bin/fdfs *
    ll /usr/bin/fdfs *

    and view the command script:

5. Set script soft link
   The bin directory set by FastDFS service script is /usr/local/bin, but the actual command is installed under /usr/bin/. You can create a soft link from /usr/bin to / usr/local/bin

    ln -s /usr/bin/fdfs_trackerd   /usr/local/bin
    ln -s /usr/bin/fdfs_storaged   /usr/local/bin
    ln -s /usr/bin/stop.sh         /usr/local/bin
    ln -s /usr/bin/restart.sh      /usr/local/bin

## 3. Create the fastdfs file storage directory /home/hc/fastdfs/

Create the folder fastdfs in the /home/hc/ directory as the root directory of fastdfs data

## 4. Configure Tracker service

1. Enter the /etc/fdfs directory and copy through the cp command tracker.conf.sample , renamed as: tracker.con (delete the suffix. Sample) as an official document

    cd /etc/fdfs/
    cp tracker.conf.sample  tracker.conf
    vi tracker.conf

2. edit tracker.conf : vi tracker.conf , modify the relevant parameters (only need to modify: base)_ Path and http.server_port)

    # Port to provide service. Default: 22122
    # Tracker stores the root path of data and log. The root directory must exist and the subdirectory will be created automatically
    # http port, which needs to be the same as nginx

3. Start tracker (support start|stop|restart)

    # Method 1:
    /etc/init.d/fdfs_trackerd start
    # Method 2:
    service fdfs_trackerd start

    After successful startup, the_ Create data and logs under path.

4. To view the port status, command: netstat -apn|grep fdfs

    If port 22122 is listening, the Tracker service is installed successfully.
    Tracker close command:
    service fdfs_trackerd stop

5. Set Tracker startup

    chkconfig fdfs_trackerd on

## 5. Storage service configuration

1. Enter the /etc/fdfs directory and copy the cp command storage.conf.sample , rename to storage.conf (delete. Sample) suffix as official document

    cd /etc/fdfs/
    cp storage.conf.sample storage.conf
    vi storage.conf

2. Editor storage.conf , modify the relevant parameters (base_path,store_path0,tracker_server, http.server_port)

    # Whether the configuration file does not take effect. false means it takes effect
    # Specify the group (volume) this storage server is in
    # storage server service port, the default storage is 23000
    # Heartbeat interval time, unit: seconds (here refers to sending heartbeat to tracker server actively)
    # Number of storage paths, need and store_path number matching
    # The following path of storage data and log must be created in advance
    # If empty, base is used_ Path, set the same here
    #If this parameter is N only (for example: 256), then the storage server will run in store for the first time_ Automatically create N * N subdirectories to store files under path
    # Configure the ip and port of the tracker monitored by the storage
    #When there are multiple tracker servers, each tracker server writes one line
    # The period of time that the system is allowed to synchronize (the default is all day). It is generally used to avoid some problems in peak synchronization.
    #Access port

3. Start Storage

    # Method 1:
    /etc/init.d/fdfs_storaged start
    # Method 2:
    service fdfs_storaged start

4. Check the port status: netstat -apn|grep fdfs

    - Shut down Storage command:
    service fdfs_storaged stop
    - Restart Storage command:
    service fdfs_storaged restart

5. Use monitor to check whether the storage is successfully bound and whether the communication between storage and Tracker is successful

    /usr/bin/fdfs_monitor /etc/fdfs/storage.conf


6. Set the Storage boot

    chkconfig fdfs_storaged on

## 6. Configure client

Modify configuration clinet configuration

cd /etc/fdfs
cp client.conf.sample client.conf
vi client.conf

Modify the following configuration
# Client's data and log directory
# Tracker port

7. Install nginx

  1. Download the Nginx package:

    wget http://nginx.org/download/nginx-1.15.2.tar.gz
  2. Unzip nginx:

    tar -zxvf nginx-1.15.2.tar.gz
  3. Enter the nginx directory

    cd nginx-1.15.2
  4. Depending on the NX installation package, you need to:

    yum update
    yum install pcre-devel
    yum install zlib zlib-devel
    yum install openssl openssl-devel
    //The above three commands can be replaced by one of the following:
    yum install pcre-devel zlib zlib-devel openssl openssl-devel

8. Install fastdfs nginx module installation package

  1. Download fastdfs nginx module package

    wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
    # Unzip the installation package
    tar -zxvf V1.20.tar.gz
  2. Modify the fastdfs-nginx-module-1.20/src/config file

    ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
  3. Configure Nginx,

    get into nginx catalog
    cd nginx-1.15.2
    add module
    ./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src
  4. Recompile, install

    make && make install
  5. Check nginx version, command:

    /usr/local/nginx/sbin/nginx -V

9. Configure Nginx and fastdfs Nginx module modules

  1. Configure mod-fastdfs.conf And copy it to the / etc/fdfs file directory

    cd /usr/local/src/fastdfs-nginx-module-1.20/src/
    cp mod_fastdfs.conf /etc/fdfs/
  2. Modify mod-fastdfs.conf

    vi /etc/fdfs/mod_fastdfs.conf 
    Modify the following configuration:
    # Connection timeout
    # The address of the Tracker Server
    ## Whether the url contains the group name, set to true
    url_have_group_name = true
    # Storage configured store_path0 path, must and storage.conf Consistency in
  3. Copy the FastDFS unzip directory (anti-steal.jpg , http.conf , mime.types )Go to the / etc/fdfs directory

    cd /root/libfastcommon-1.0.38/fastdfs-5.11/conf
    cp anti-steal.jpg http.conf mime.types /etc/fdfs/
  4. Configure nginx, modify nginx.conf

    vi /usr/local/nginx/conf/nginx.conf
  5. Add the following:

    location ~/group([0-9])/M00 {

    Note: in order to avoid the problem that the http request cannot be accessed due to the permission problem of nginx:

    This step is very important. If you don't do this, the image will be uploaded successfully, but nginx in the browser cannot be accessed.

  6. Start nginx

  7. Check nginx installation path:

    whereis nginx

  8. Set boot up

vi /etc/rc.local
Add a line:
# Set execution permissions
chmod 755 rc.local
  1. Query nginx version
/usr/local/nginx/sbin/nginx -V

10. Testing

  1. Upload files

    fdfs_upload_file /etc/fdfs/client.conf /home/111.png

  2. View in nginx