FastDFS+Nginx installation configuration

FastDFS + Nginx installation configuration

Directory

  • Download and upload the installation package to the server
    • project address:
  • FastDFS installation
    • 1. Install FastDFS dependent libraries
      • 1. Compilation environment
      • 2. Install libfastcommon and libserverframe libraries
    • 2. Install FastDFS and configure it
    • 3. Start (choose one of the following startup methods)
      • File mode startup
      • Configure systemd startup
        • 1. tracker
        • 2.storage
      • Check whether the storage has been registered under the tracker
      • Cluster mode detection
    • 4. Test
      • fdfs command format
  • nginx installation configuration
    • 1. Install dependencies
      • nginx dependency
      • fastdfs-nginx-module module
      • Configure mod_fastdfs.conf
    • 2. Install nginx
    • 3. Start nginx
    • 4. Test
      • NOTE: Possible errors

Version: Pay attention to version matching issues (can be viewed in the version notes

  • FastDFS: v6.09 or higher version
  • libfastcommon:1.0.60
  • libserverframe: 1.1.19
  • cd fastdfs-nginx-module:V1.23
  • nginx: nginx-1.16.1

Download and upload the installation package to the server

Project address:

https://github.com/happyfish100

FastDFS installation

1. Install FastDFS dependent libraries

1. Compilation environment

Install gcc, libevent, libevent-devel

yum install -y gcc gcc-c + + libevent libevent-devel make automake autoconf libtool

2. Install libfastcommon and libserverframe libraries

Address: github.com/happyfish10…

  1. Upload the downloaded package to /usr/local/src or
    cd /usr/local/src
    
    wget https://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.60.tar.gz
    wget https://github.com/happyfish100/libserverframe/archive/refs/tags/V1.1.19.tar.gz
    
    
  2. Unzip
    1. tar -zxvf libfastcommon-1.0.60.tar.gz
    2. tar -zxvf libserverframe-1.1.19.tar.gz
  3. Enter the installation directory, perform compilation and installation
    1. Install libfastcommon
      cd libfastcommon-1.0.60
      ./make.sh & amp; & amp; ./make.sh install
      
      
    2. Install libserverframe
       cd libserverframe-1.1.19
       ./make.sh & amp; & amp; ./make.sh install
      

2. Install FastDFS and configure it

  1. Transfer packet or
    cd /usr/local/src
    
    wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V6.09.tar.gz
    
  2. Unzip tar -zxvf fastdfs-6.09.tar.gz
  3. Enter the installation directory, compile and install
    cd fastdfs-6.09
    ./make.sh & amp; & amp; ./make.sh install
    
    
  4. Copy the configuration file (if not copied, an error will be reported when accessed with nginx)
    cp /usr/local/src/fastdfs-6.09/conf/http.conf /etc/fdfs/ #For nginx access
    cp /usr/local/src/fastdfs-6.09/conf/mime.types /etc/fdfs/ #For nginx access
    
  5. Check the editing and configuration files. The files compiled by FastDFS are stored in the /usr/bin directory, and all configuration files are stored in the /etc/fdfs directory
    ll/ usr/bin/fdfs*
    -rwxr-xr-x 1 root root 380264 Sep 24 00:11 /usr/bin/fdfs_appender_test
    -rwxr-xr-x 1 root root 380040 Sep 24 00:11 /usr/bin/fdfs_appender_test1
    -rwxr-xr-x 1 root root 367008 Sep 24 00:11 /usr/bin/fdfs_append_file
    -rwxr-xr-x 1 root root 365648 Sep 24 00:11 /usr/bin/fdfs_crc32
    -rwxr-xr-x 1 root root 367040 Sep 24 00:11 /usr/bin/fdfs_delete_file
    -rwxr-xr-x 1 root root 367768 Sep 24 00:11 /usr/bin/fdfs_download_file
    -rwxr-xr-x 1 root root 367712 Sep 24 00:11 /usr/bin/fdfs_file_info
    -rwxr-xr-x 1 root root 387328 Sep 24 00:11 /usr/bin/fdfs_monitor
    -rwxr-xr-x 1 root root 367280 Sep 24 00:11 /usr/bin/fdfs_regenerate_filename
    -rwxr-xr-x 1 root root 1297648 Sep 24 00:11 /usr/bin/fdfs_storaged
    -rwxr-xr-x 1 root root 390160 Sep 24 00:11 /usr/bin/fdfs_test
    -rwxr-xr-x 1 root root 389384 Sep 24 00:11 /usr/bin/fdfs_test1
    -rwxr-xr-x 1 root root 509800 Sep 24 00:11 /usr/bin/fdfs_trackerd
    -rwxr-xr-x 1 root root 367984 Sep 24 00:11 /usr/bin/fdfs_upload_appender
    -rwxr-xr-x 1 root root 368992 Sep 24 00:11 /usr/bin/fdfs_upload_file
    
     ll /etc/fdfs/
    total 32
    -rw-r--r-- 1 root root 1909 Sep 24 00:11 client.conf
    -rw-r--r-- 1 root root 10246 Sep 24 00:11 storage.conf
    -rw-r--r-- 1 root root 620 Sep 24 00:11 storage_ids.conf
    -rw-r--r-- 1 root root 9138 Sep 24 00:11 tracker.conf
    
    
    
  6. FastDFS stand-alone mode configuration
    1. tracker configuration

      vim /etc/fdfs/tracker.conf

      base_path=/home/fastdfs/tracker # Root directory for storing logs and data, needs to be created
      
    2. storage configuration

      vim /etc/fdfs/storage.conf

      base_path=/home/fastdfs/storage # Data and log file storage root directory, needs to be created
      store_path_count = 1 #Specify the number of directories where files are actually stored, the default is 1
      store_path0=/home/fastdfs/first # The first storage directory needs to be created. Multiple directories can be added to configure cluster mode.
      #store_path0=/home/fastdfs/second The second storage directory needs to be created
      tracker_server=60.204.207.52:22122 # tracker server IP and port There can be multiple servers
      #tracker_server=60.204.207.53:22122 # tracker server IP and port
      http.server_port=8888 # The port for http access files (default 8888, change according to the situation, consistent with nginx)
      
    3. client configuration

      vim /etc/fdfs/client.conf

      base_path=/home/fastdfs/client #Directory to store logs, needs to be created
      tracker_server=60.204.207.52:22122 # Server 1 registers the tracker address of the current storage node. The default port number is 22122.
      
  7. FastDFS cluster mode configuration
    1. tracker configuration

      vim /etc/fdfs/tracker.conf

      base_path=/home/fastdfs/tracker # Root directory for storing logs and data, needs to be created
      
    2. storage configuration

      vim /etc/fdfs/storage.conf

      #The content that needs to be modified is as follows
      port=23000 # storage service port (default 23000, generally not modified)
      base_path=/home/fastdfs/storage # Data and log file storage root directory
      store_path0=/home/fastdfs/first # The first storage directory
      tracker_server=60.204.207.52:22122 # Server 1
      tracker_server=60.204.207.53:22122 # Server 2
      tracker_server=60.204.207.54:22122 # Server 3
      http.server_port=8888 # The port for http access files (default 8888, change according to the situation, consistent with nginx)
      
      
    3. client configuration

      vim /etc/fdfs/client.conf

      #The content that needs to be modified is as follows
      base_path=/home/fastdfs/client
      tracker_server=60.204.207.52:22122 # Server 1
      tracker_server=60.204.207.53:22122 # Server 2
      tracker_server=60.204.207.54:22122 # Server 3
      
      

3. Start (choose one of the following startup methods

Start by file mode

1. Start the tracker service

fdfs_trackerd /etc/fdfs/tracker.conf

2. Start the storage service

fdfs_storaged /etc/fdfs/storage.conf

Configuring systemd startup

1. tracker

Modify the PIDFile in /usr/lib/systemd/system/fdfs_trackerd.service, the format is:
PIDFile=$base_path/data/fdfs_trackerd.pid

vim /usr/lib/systemd/system/fdfs_trackerd.service


PIDFile=/home/fastdfs/tracker/data/fdfs_trackerd.pid #Modify directory
systemctl start fdfs_trackerd #Start tracker service
systemctl restart fdfs_trackerd #Restart the tracker service
systemctl stop fdfs_trackerd #Stop tracker service
systemctl enable fdfs_trackerd #Start automatically at boot
2. storage

Modify the PIDFile in /usr/lib/systemd/system/fdfs_storaged.service, the format is:
PIDFile=$base_path/data/fdfs_storaged.pid

vim /usr/lib/systemd/system/fdfs_storaged.service

PIDFile=/home/fastdfs/storage/data/fdfs_storaged.pid #Modify directory

systemctl start fdfs_storaged #Start the storage service
systemctl restart fdfs_storaged #Restart the storage service
systemctl stop fdfs_storaged #Stop the storage service
systemctl enable fdfs_storaged #Start automatically at boot

Check whether the storage has been registered under the tracker

fdfs_monitor /etc/fdfs/storage.conf

fdfs_monitor /etc/fdfs/storage.conf
[2023-09-24 03:29:18] DEBUG - base_path=/home/fastdfs/storage, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=1, g_connection_pool_max_idle_time= 3600s, use_storage_id=0, storage server id count: 0

server_count=1, server_index=0

tracker server is 60.204.207.52:22122 ###Indicates successful registration

group count: 1

Group 1:
group name = group1
....

Cluster mode detection

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
# It will display how many servers there are. If there are 3 servers, the detailed information of Storage 1-Storage 3 will be displayed.

4. Test

fdfs command format

  • Upload file command: fdfs_test :
    • config_file: The location of the configuration file
    • operation: upload, download, getmeta, setmeta, delete and query_servers
    • local_filename: the name of the file to be uploaded
  • Download file command: fdfs_test download
    • group_name: the group name of the file to be downloaded
    • remote_filename: the file name to be downloaded (to specify the name stored in fastDFS)
  • Delete file command: fdfs_test delete
Another way:
Test, return ID to indicate success, such as: group1/M00/00/00/xx.tar.gz

#upload
fdfs_upload_file <config_file> <local_filename>
command configuration file local file

#Download Example:
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/PMzOQmUPWzSAX0DbABAvAG3SAAY569.jpg

#delete example
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/PMzOQmUPWzSAX0DbABAvAG3SAAY569.jpg



Execute upload command:

fdfs_upload_file /etc/fdfs/client.conf test.jpg

group1/M00/00/00/PMzOQmUPWzSAX0DbABAvAG3SAAY569.jpg #Here is the returned file saving path



nginx installation configuration

1. Install dependencies

nginx dependency

yum install -y pcre pcre-devel zlib zlib-devel openssl-devel

fastdfs-nginx-module module
cd /usr/local/src/

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/refs/tags/V1.23.tar.gz

tar -zxvf /usr/local/src/fastdfs-nginx-module-1.23.tar.gz

#Copy mod_fastdfs.conf to /etc/fdfs/
cp /usr/local/src/fastdfs-nginx-module-1.23/src/mod_fastdfs.conf /etc/fdfs/
Configure mod_fastdfs.conf

vim /etc/fdfs/mod_fastdfs.conf

base_path=/home/fastdfs/nginx_mod # Specify the log storage location, which needs to be created
tracker_server=60.204.207.52:22122 # Specify the tracker’s IP and port
group_name=group1 # Group name
url_have_group_name = false # true means that the requested path contains the group name. The default is false. When it is false, the group name defaults to the value specified by group_name above.
store_path0=/home/fastdfs/first # Specify the location where data is stored, the same as in /etc/fdfs/storage.conf


The following quotes do not need to be configured (specify the location of the header file: it can be successfully deployed without adding it this time)

Configuration/usr/local/src/fastdfs-nginx-module-1.23/src/config

View header file

ll -d /usr/local/include/fast*
ls: cannot access /usr/local/include/fast*: No such file or directory

ll -d /usr/include/fast*
drwxr-xr-x 2 root root 4096 Sep 23 23:50 /usr/include/fastcommon
drwxr-xr-x 2 root root 4096 Sep 24 00:11 /usr/include/fastdfs

vim /usr/local/src/fastdfs-nginx-module-1.23/src/config

ngx_module_incs=“/usr/local/include”
Change to
ngx_module_incs=“/usr/include”

2. Install nginx

  1. Download and unzip the installation package

    cd /usr/local/src
    wget http://nginx.org/download/nginx-1.16.1.tar.gz
    tar -zxvf nginx-1.16.1.tar.gz
    
  2. Compile and install

    Add fastdfs-nginx-module module

    cd /usr/local/src/nginx-1.16.1
    
    ./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.23/src/
    make & amp; & amp; make install #Compile and install
    
    
  3. Configure nginx access

    vim /etc/fdfs/mod_fastdfs.conf
    #The content that needs to be modified is as follows
    tracker_server=60.204.207.52:22122 #tracker server IP and port
    url_have_group_name=true
    store_path0=/home/fastdfs/first/ #Data storage directory
    #Configure nginx.config
    vim /usr/local/nginx/conf/nginx.conf
    #Add the following configuration
    server {<!-- -->
        listen 8888; ## This port is the same as http.server_port in storage.conf
        server_name localhost;
        location ~/group[0-9]/ M([0-9])([0-9]) {<!-- -->
            ngx_fastdfs_module;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {<!-- -->
        roothtml;
        }
    }
    #Test, use an external browser to access FastDFS, pass the jpg test, and quote the returned ID. Note: Be sure to add the port.
    http://60.204.207.52: 8888 /group1/M00/00/00/PMzOQmUPWzSAX0DbABAvAG3SAAY569.jpg
    #Return the content and the deployment is completed
    

3. Start nginx

/usr/local/nginx/sbin/nginx #Start nginx

/usr/local/nginx/sbin/nginx -s reload #Restart nginx
/usr/local/nginx/sbin/nginx -s stop #Stop nginx

4. Test

#Test, use an external browser to access the jpg passed by FastDFS and test the returned ID. Note: Be sure to add the port.
http://60.204.207.52: 8888 /group1/M00/00/00/PMzOQmUPWzSAX0DbABAvAG3SAAY569.jpg
#Return the content and the deployment is completed

Note: Possible errors

  1. The upload is successful, but nginx reports an error 404 or nginx cannot be accessed: Check whether the store_path0 in the mod_fastdfs.conf file is consistent and whether a port has been added to the access address.
  2. If it is not installed in the /usr/local/src folder, compilation errors may occur.
  3. If the unknown directive “ngx_fastdfs_module” in /usr/local/nginx/conf/nginx.conf:151, it may be that nginx has been started and nginx must be restarted. nginx -s reload is invalid.
  4. If the error.log of nginx prompts: ERROR – file: ini_file_reader.c, line: 1051, include file “http.conf” not exists, line: “#include http.conf”ERROR – file: /root/fastdfs-nginx -module/src/common.c, line: 163, load conf file “/etc/fdfs/mod_fastdfs.conf” fail, ret code: 2
    You need to cp http.conf and mime.types in the conf folder in the fastdfs source code to the etc/fdf folder.