Installing and configuring FastDFS
1. Operating environment and related software
CentOS 7.4 64position
FastDFS_v5.08.tar.gz
nginx-1.8.1.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
libfastcommon
2. Server Planning
Server name | IP Address and Port | Remarks |
---|---|---|
fastdfs-tracker | 172.17.156.5:22122 | Tracking Server/Scheduling Server |
fastdfs-storage | 172.17.156.5:23000 | Storage Server |
3. Installation of FastDFS
3.1 First create the tool catalog (not required)
[root@fastdfs-storage ~]# mkdir -p /home/oldcat/tools
[root@fastdfs-storage ~]# cd /home/oldcat/tools/
3.2 Download and install FastDFS dependency package libfast common
[root@fastdfs-storage tools]# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master
[root@fastdfs-storage tools]# unzip master
[root@fastdfs-storage tools]# cd libfastcommon-master/
[root@fastdfs-storage libfastcommon-master]# ls
HISTORY INSTALL libfastcommon.spec make.sh php-fastcommon README src
[root@fastdfs-storage libfastcommon-master]# ./make.sh
[root@fastdfs-storage libfastcommon-master]# ./make.sh install
Tip: If the second sentence is executed and the following error is reported, no error is reported directly 3.3
-bash: unzip: command not found
The reason why the command was not found must be that unzip was not installed.
The installation command is:
yum install -y unzip zip
3.3 Download and install FastDFS
[root@fastdfs-tracker tools]# wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
[root@fastdfs-tracker tools]# tar xf FastDFS_v5.08.tar.gz
[root@fastdfs-tracker tools]# cd FastDFS
[root@fastdfs-tracker FastDFS]# ./make.sh && ./make.sh install
Files and directories installed by default:
- Service scripts:
[root@fastdfs-tracker ~]# ll /etc/init.d/ |grep fdfs
-rwxr-xr-x. 1 root root 918 4month 22 22:08 fdfs_storaged
-rwxr-xr-x. 1 root root 920 4month 22 22:08 fdfs_trackerd
- Sample configuration file
[root@fastdfs-tracker ~]# ll /etc/fdfs/
//Total consumption 20
-rw-r--r--. 1 root root 1461 4month 22 22:08 client.conf.sample
-rw-r--r--. 1 root root 7927 4month 22 22:08 storage.conf.sample
-rw-r--r--. 1 root root 7200 4month 22 22:08 tracker.conf.sample
- Command Line Tools
[root@fastdfs-tracker ~]# ll /usr/bin|grep fdfs
-rwxr-xr-x. 1 root root 252272 4month 22 22:08 fdfs_appender_test
-rwxr-xr-x. 1 root root 252225 4month 22 22:08 fdfs_appender_test1
-rwxr-xr-x. 1 root root 242449 4month 22 22:08 fdfs_append_file
-rwxr-xr-x. 1 root root 242013 4month 22 22:08 fdfs_crc32
-rwxr-xr-x. 1 root root 242508 4month 22 22:08 fdfs_delete_file
-rwxr-xr-x. 1 root root 243627 4month 22 22:08 fdfs_download_file
-rwxr-xr-x. 1 root root 243369 4month 22 22:08 fdfs_file_info
-rwxr-xr-x. 1 root root 255657 4month 22 22:08 fdfs_monitor
-rwxr-xr-x. 1 root root 863913 4month 22 22:08 fdfs_storaged
-rwxr-xr-x. 1 root root 258712 4month 22 22:08 fdfs_test
-rwxr-xr-x. 1 root root 257881 4month 22 22:08 fdfs_test1
-rwxr-xr-x. 1 root root 365232 4month 22 22:08 fdfs_trackerd
-rwxr-xr-x. 1 root root 243547 4month 22 22:08 fdfs_upload_appender
-rwxr-xr-x. 1 root root 244453 4month 22 22:08 fdfs_upload_file
Note: Although FastDFS differentiates tracker from storage server, the software and steps installed are the same, just different configuration files, so the above installation is suitable for tracker server and storage server.
4. Configuration of tracker server
4.1 Copy the tracker server and client-side sample configuration files and rename them
[root@fastdfs-tracker ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[root@fastdfs-storage ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
4.2 Edit the tracker server configuration file tracker.conf, which needs to be modified as follows:
disabled=false(Default isfalse,Indicates whether it is invalid or not)
port=22122(Default is22122)
base_path=/data/fastdfs/tracker
4.3 Edit the client-side configuration file client.conf, which needs to be modified as follows
base_path=/data/fastdfs/tracker
tracker_server=172.17.156.5:22122
IP fills in the private IP of its own server. If it is a virtual machine, use the following
Example: 192.168.25.133
4.4 Create tracker server data directory
[root@fastdfs-tracker ~]# mkdir -p /data/fastdfs/tracker
4.5 Test starts trackerserver, which automatically creates data and logs directories in the / data/fastdfs/tracker directory
[root@fastdfs-tracker ~]# cd /data/fastdfs/tracker/
[root@fastdfs-tracker tracker]# ls
[root@fastdfs-tracker tracker]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
[root@fastdfs-tracker tracker]# ss -lntup|grep 22122
tcp LISTEN 0 128 *:22122 *:* users:(("fdfs_trackerd",3785,5))
[root@fastdfs-tracker tracker]# ls
data logs
4.6 Close tracker server
[root@fastdfs-tracker tracker]# /etc/init.d/fdfs_trackerd stop
waiting for pid [3785] exit ...
pid [3785] exit.
5. Configuring storage server
5.1 Copy the storage server sample configuration file and rename it
[root@fastdfs-storage ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
5.2 Edit the storage server configuration file storage.conf, which needs to be modified as follows:
disabled=false(Default is false,Indicates whether it is invalid or not)
port=23000(The default is 23000)
base_path=/data/fastdfs/storage
tracker_server=172.17.156.5:22122
store_path0=/data/fastdfs/storage
http.server_port=8888(The default is 8888. nginx One of the listening ports configured in the
IP fills in the private IP of its own server. If the virtual machine uses the following directly, it must be the same as the tracker server above.
Example: 192.168.25.133
5.3 Create storage server data directory
[root@fastdfs-storage ~]# mkdir -p /data/fastdfs/storage
5.4 Test to start storage server, and the successful start will automatically create new data and logs directories in the / data/fastdfs/tracker directory (the premise of starting storage server is that tracker server must be started beforehand)
[root@fastdfs-storage ~]# cd /data/fastdfs/storage/
[root@fastdfs-storage storage]# ls
[root@fastdfs-storage storage]# /etc/init.d/fdfs_storaged start
Starting FastDFS storage server:
[root@fastdfs-storage storage]# ss -lntup|grep 23000
tcp LISTEN 0 128 *:23000 *:* users:(("fdfs_storaged",3786,5))
[root@fastdfs-storage storage]# ls
data logs
6. File upload test
Execute the following upload command:
[root@fastdfs-tracker ~]#mkdir /home/oldcat/imgs Then send a picture to the server through sftp (renamed test.xxx);
[root@fastdfs-tracker ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/oldcat/imgs/test.jpg group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg Returning the file ID indicates that the file has been uploaded successfully.
2. Installing and configuring nginx on storage server
1. Download and install the fastdfs-nginx-module module
Note: FastDFS stores files on the Storage server through the Tracker server, but there is a synchronization delay due to the need for file replication between storage servers in the same group. Assuming that the Tracker server uploads the file to 192.168.4.125, the file ID has been returned to the client after the upload is successful. At this time, FastDFS storage cluster mechanism will synchronize this file to the same group storage 192.168.4.126. In the case that the file has not been copied, if the client uses this file ID to fetch the file on 192.168.4.126, there will be an error that the file cannot be accessed. fastdfs-nginx-module can redirect files to the source server to fetch files, so as to avoid the file access error caused by the client due to the copy delay.
[root@fastdfs-storage tools]# wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz [root@fastdfs-storage tools]# tar xf fastdfs-nginx-module_v1.16.tar.gz [root@fastdfs-storage tools]# cd fastdfs-nginx-module/src/ [root@fastdfs-storage src]# vim config Edit the config file, execute the following commands for batch replacement and save the exit :%s+/usr/local/+/usr/+g
2. Copy the configuration file in the fastdfs-nginx-module module into the / etc/fdfs directory and edit it
[root@fastdfs-storage ~]# cp /home/oldcat/tools/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ [root@fastdfs-storage ~]# vim /etc/fdfs/mod_fastdfs.conf The amendments are as follows: connect_timeout=10 base_path=/tmp (default: / tmp) Tracker_server = 172.17.156.5:22122 (cloud server is private IP) storage_server_port=23000 (default configuration 23000) url_have_group_name = true store_path0=/data/fastdfs/storage group_name=group1 (default configuration is group1)
3. Installing nginx dependency Libraries
[root@fastdfs-storage nginx-1.8.1]# yum install -y pcre-devel zlib-devel
4. Download and install nginx
[root@fastdfs-storage tools]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
[root@fastdfs-storage tools]# tar xf nginx-1.8.1.tar.gz
[root@fastdfs-storage tools]# cd nginx-1.8.1
[root@fastdfs-storage nginx-1.8.1]# ./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/
[root@fastdfs-storage nginx-1.8.1]# make && make install
5. Copy some configuration files from FastDFS to / etc/fdfs directory
[root@fastdfs-storage ~]# cp /home/oldcat/tools/FastDFS/conf/http.conf /etc/fdfs/
[root@fastdfs-storage ~]# cp /home/oldcat/tools/FastDFS/conf/mime.types /etc/fdfs/
6. Configure nginx as follows:
[root@fastdfs-storage ~]# vim /application/nginx/conf/nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
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;
}
}
}
Explain:
- "user root" is a solution to the problem of download operation time 404
- The port number 8888 corresponds to http.server_port=8888 in / etc/fdfs/storage.conf
- storage corresponds to multiple groups, and access paths with group names, such as: / group 1/M00/00/00/**, correspond to nginx configuration:
location ~/group[0-9]/ { ngx_fastdfs_module; }
7. Copy nginx service to / etc/init.d / directory and start
[root@fastdfs-storage ~]# cp /application/nginx/sbin/nginx /etc/init.d/
[root@fastdfs-storage ~]# /etc/init.d/nginx
[root@fastdfs-storage ~]# ss -lntup|grep 8888
tcp LISTEN 0 128 *:8888 *:* users:(("nginx",7308,6),("nginx",7309,6))
8. Files uploaded prior to browser access
Example: IP: 8888/group1/M00/00/rBGcBVqBZ_mAGl9oAAEfvSdB99w682.jpg
Browsers can successfully access the uploaded images, indicating that the image server built with FastDFS has been successfully completed!
Note: If IP is a public network IP on a remote server, the server needs to set up a security group to open port 8888.