FastDFS website address: https://github.com/happyfish100/fastdfs/wiki

Download the software package to be used:

  • Libfastcommon download address: https://github.com/happyfish100/libfastcommon/releases

  • FastDFS download address: https://github.com/happyfish100/fastdfs/releases

  • Fastdfs nginx – module download address: https://github.com/happyfish100/fastdfs-nginx-module/releases

  • Nginx download address: https://nginx.org/en/download.html

Use centos 6.x and 7.x systems

Two servers are required to use FastDFS

The functions areTrackerServices andStorageservice

You need to install FastDFS on both servers, and then configure Tracker and storage separately


Installation steps

1. The first installationgcc c++

yum install -y gcc gcc-c++
Copy the code

2. Installlibevent

yum install -y libevent
Copy the code

3. The installationlibfastcommon

3.1. Decompress the libfastcommon package

The tar - ZXVF libfastcommon - 1.0.48. Tar. GzCopy the code

3.2. Go to the decompressed folder for installation

CD libfastcommon-1.0.48/ Compile:./make. Sh install:./makeCopy the code

4. Installfastdfs

4.1 unzip fastdfs

Tar - ZXVF fastdfs 6.07. Tar. GzCopy the code

4.2. Go to the decompressed folder for installation

CD fastdfs-6.07/ Compile:./make. Sh install:./makeCopy the code

4.3. Go to the configuration file directory and copy the configuration file

CD conf/ Copy all files in the directory to the /etc/fdfs directory cp * /etc/fdf/Copy the code

Fastdfs installation directory:

/usr/bin

/etc/fdfs

/usr/lib64

/usr/lib


5. Configure them separatelyTrackerServices andStorageservice

After the installation is complete on both servers, configure the corresponding configuration file

In /etc/fdfs/there are two configuration files storage.conf and tracker.

[root@localhost FDFS]# PWD /etc/fdfs [root@localhost FDFS]# ll total 124-rw-r --r--. 1 root root 23981 2月 18 10:22 Anti-steal.jpg -rw-r--r--. 1 root root 1909 feb 18 10:22 client-conf -rw-r--r--. 1 root root 1909 Feb 18 10:21 Sample -rw-r--r-- 1 root root 965 February 18 10:22 http.conf -rw-r--r-- 1 root root 31172 February 18 10:22 Mime.types -rw-r--r-- 1 root root 10246 2月 18 10:22 storage.conf -rw-r--r-- 1 root root 10246 2月 18 10:21 Storage.conf. sample -rw-r--r-- 1 root root 620 February 18 10:22 storage_ids.conf -rw-r--r-- 1 root root 620 February 18 10:21 Storage_ids.conf. sample-rw-r --r-- 1 root root 9189 February 18 10:29 tracker.conf -rw-r--r-- 1 root root 9138 February 18 10:21 tracker.conf.sampleCopy the code

If your current machine is used as a Storage service, modify the storage.conf file.

If your current machine is used for the Tracker service, modify the tracker.conf file.

Let’s start with the tracker.conf file. So far, only one place to change is base_path, the path where data files and log files are stored

base_path = /usr/local/fastdfs/tracker
Copy the code

Change it to your own path.

Start theTrackerServices:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
Copy the code

Check whether the startup is successful

ps -ef | grep tracker
Copy the code

Then switch to another server and modify the storage.conf file

# # modified group name group_name = group1 stored data file and log file path base_path = / usr/local/fastdfs/storage store_path0 = / usr/local/fastdfs/storage can have two tracker_server # below, comment out the first one, because we are now only a tracker service # modified one IP for the tracker server IP, The default port for tracker is 22122 tracker_Server = 192.168.10.235:22122Copy the code

Start theStorageServices:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
Copy the code

6. Test upload

On the Storage server, modify the client.conf file in the /etc/fdfs/directory

Base_path = / usr/local/fastdfs/client tracker_server = 192.168.10.235:22122Copy the code

Prepare an image and go to the /usr/bin/directory, which contains a fdfs_test file for testing

[root@localhost fdfs]# cd /usr/bin/
[root@localhost bin]# ls fdfs*
fdfs_appender_test   fdfs_append_file  fdfs_delete_file    fdfs_file_info  fdfs_regenerate_filename  fdfs_test   fdfs_trackerd         fdfs_upload_file
fdfs_appender_test1  fdfs_crc32        fdfs_download_file  fdfs_monitor    fdfs_storaged             fdfs_test1  fdfs_upload_appender
[root@localhost bin]# 
Copy the code

Run the following command to test the upload

./fdfs_test /etc/fdfs/client.conf upload /home/test.png
Copy the code

Remote_filename, the file storage path

Example file URL, the file access path, has not been configured, so cannot access

Take a look at the uploaded file

[root @ localhost storage] # CD/usr/local/fastdfs/storage/data / 00/00 / / root @ localhost 00 # ll total amount - r - 1000 - rw - r. 1 root Root 504372 February 18 11:11 wKgK6mAt2vqAdn7SAAeyNMzENJ4999_big. PNG - rw - r - r -. 1 root root 49 February 18 11:11 WKgK6mAt2vqAdn7SAAeyNMzENJ4999_big. PNG - m - rw - r - r -. 1 root root 504372 February 18 11:11 wKgK6mAt2vqAdn7SAAeyNMzENJ4999. PNG Rw - r - r -. 1 root root 49 February 18 11:11 wKgK6mAt2vqAdn7SAAeyNMzENJ4999. PNG -m root @ localhost 00 #Copy the code

7. Configure Nginx to provide Web services

To install nginx on a Storage server, see the article Nginx Installation and Running

7.1. Decompress the downloaded fastdfs-nginx-module-1.22.tar.gz file

The tar - ZXVF fastdfs - nginx - module - 1.22. Tar. GzCopy the code

7.2. Go to the SRC folder in the decompressed folder

[root@localhost SRC]# PWD /home/software/fastdfs-nginx-module-1.22/ SRC [root@localhost SRC]# ll 84-rw-rw-r --. 1 Root root 43507 November 19 2019 common.c -rw-rw-r--. 1 root root 3995 November 19 2019 common.h -rw-rw-r--. 1 root root 848 November 19 19 2019 config-rw-rw-r -- 1 root root 3725 November 19 2019 mod_fastdfs.conf -rw-rw-r-- 1 root root 28668 November 19 2019 ngx_http_fastdfs_module.cCopy the code

7.3. Copy the mod_fastdfs.conf configuration file to the /etc/fdf/ directory

cp mod_fastdfs.conf /etc/fdfs/
Copy the code

7.4. Go to the /etc/fdfs/directory and modify the mod_fastdfs.conf configuration file that you just copied

/usr/local/ fastdfs.tmp/store_path0 =/usr/local/ fastdfs.tmp/store_path0 =/usr/local Store_path0 = / usr/local/fastdfs/storage # modify tracker_server = 192.168.10.235 tracker_server address for the tracker server address: 22122 # change Group_name group_name = group1 # url_have_group_name specifies whether the generated url must contain group name. You can change the url to trueCopy the code

7.5. Go back to the fastdfs-nginx-module-1.22/ SRC folder and modify the config file

[root@localhost FDFS]# CD /home/software/fastdfs-nginx-module-1.22/ SRC / [root@localhost SRC]# ll 84-rw-rw-r -- Root root 43507 November 19 2019 common.c -rw-rw-r--. 1 root root 3995 November 19 2019 common.h -rw-rw-r--. 1 root root 848 November 19 19 2019 config-rw-rw-r -- 1 root root 3725 November 19 2019 mod_fastdfs.conf -rw-rw-r-- 1 root root 28668 November 19 2019 ngx_http_fastdfs_module.cCopy the code
Change ngx_module_incs="/usr/local/include" to ngx_module_incs="/usr/include"; CORE_INCS="$CORE_INCS /usr/local/include" CORE_INCS="$CORE_INCS /usr/include"Copy the code

7.6. Nginx needs to be re-installed because the new nginx module is added

Go to the unzipped nginx directory,

[root @ localhost nginx - 1.18.0] # CD/home/software/nginx 1.18.0 /Copy the code

Run the following command:

./configure \--prefix=/usr/local/nginx \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/var/temp/nginx/client \--http-proxy-temp-path=/var/temp/nginx/proxy \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ - HTTP - scgi - temp - path = / var/temp/nginx/scgi \ - add - the module = / home/software/fastdfs - nginx - module - 1.22 / SRCCopy the code

Note: When copying, do not end the last line with a space or a newline, otherwise it may cause an error

It is best to copy this command, modify the path and then paste it to the command line.

— Add-module = fastdfs-nginx-module-1.22/ SRC; SRC = fastdfs-nginx-module-1.22/ SRC

And then install it

[root@localhost nginx-1.18.0]# make & make install
Copy the code

7.7. After the installation is complete, modify the nginx.conf configuration file

[root@localhost nginx]# CD /usr/local/nginx/conf/ [root@localhost conf]# CD /usr/local/nginx/conf/ [root@localhost conf]# Conf -rw-r--r-- 1 root root 1077 2月 18 13:10 fastcgi.conf. Default -rw-r--r-- 1 root root 1007 2月 4 17:54 Fastcgi_params-rw-r --r-- 1 root root 1007 2月 18 13:10 fastcgi_params.default-rw-r --r-- 1 root root 2837 2月 18 13:10 Types -rw-r--r-- koi-utf-rw-r --r-- 1 root root 2223 2月 18 13:10 Koi-win-rw-r --r-- 1 root root 5231 2月 4 17:54 mime. 1 root root 5231 2月 18 13:10 mime.types. Default-rw-r --r-- 1 root root 2672 2月 18 11:32 nginx.conf -rw-r--r-- 1 root Default -rw-r--r-- 1 root root 636 2月 4 17:54 scgi_params-rw-r --r-- 1 root root 636 2月 4 17:54 scgi_params-rw-r --r-- 1 root root 636 2月 18 13:10 scgi_params. default-rw-r --r-- 1 root root 664 2月 4 17:54 uwsgi_params-rw-r --r-- 1 root root 664 2月 18 13:10 scgi_params. default-rw-r --r-- 1 root root 664 2月 4 17:54 uwsgi_params-rw-r --r-- 1 root root 664 2月 18 13:10 uwsgi_params. default-rw-r --r--. 1 root root 3610 2月 18 13:10 win-utfCopy the code

Add the following configuration to nginx.conf

Server {## this port is the same listen 8888 as http.server_port in storage.conf; 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

Location corresponds to the group_name name set in the previous configuration file

For example, if group_name=test, location should be written

location /test/M00 {
	ngx_fastdfs_module;
}
Copy the code

Restart nginx to access the previously uploaded image

http://ip:8888/test/M00/00/00/wKgK6mAt2vqAdn7SAAeyNMzENJ4999.png

Image file is in/usr/local/fastdfs/storage/data / 00/00 / directory.