FastDFS introduction

1. Basic concepts

FastDFS is an open source lightweight distributed file system. It manages files, including file storage, file synchronization, file upload, and file download. It solves the problems of large-capacity storage and load balancing.

2. Environmental overview

Install the LibFastCommon environment. Install FastDFS middleware. Install the Nginx proxy serverCopy the code

Install LibFastCommon

The core processes

Download -> Extract -> Compile -> Install

# # download
[root@localhost mysoft]# wget
https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
# # decompression
[root@localhost mysoft]# tar - ZXVF V1.0.38. Tar. Gz
[root@localhost mysoft]# CD libfastcommon - 1.0.38 /
# # compiler[root @ localhost libfastcommon - 1.0.38]# ./make.sh
# # to install[root @ localhost libfastcommon - 1.0.38]# ./make.sh install
Copy the code

Install FastDFS

Process: Download -> extract -> compile -> Install -> Create related path -> Configure tracker -> Configure data store -> Configure client -> Configure Nginx environment

1. Basic installation steps

# # download
[root@localhost mysoft]# wget
https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
# # decompression
[root@localhost mysoft]# tar - ZXVF V5.11. Tar. Gz
# # compiler
[root@localhost mysoft]# CD fastdfs - 5.11 /[root @ localhost fastdfs 5.11]# ./make.sh 
# # to install[root @ localhost fastdfs 5.11]# ./make.sh install
Copy the code

2. Create related paths

Usage is explained later.

[root@localhost data]# mkdir -p /data/fastdfs/log
[root@localhost data]# mkdir -p /data/fastdfs/data
[root@localhost data]# mkdir -p /data/fastdfs/tracker
[root@localhost data]# mkdir -p /data/fastdfs/client
Copy the code

3. Configure the tracker

Tracker — >> Tracker

1) View the configuration file

Note the directory conversion here, here is an example, the specific configuration of their own hands.

[root @ localhost fastdfs 5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
total 24
client.conf.sample
storage.conf.sample
storage_ids.conf.sample
tracker.conf.sample
Copy the code

2) Configure the tracker.conf file

[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# vim tracker.conf
## Pay attention to the following configurations
The basic path to store data and log files
base_path=/data/fastdfs/tracker
# Http service port
http.server_port=80
The service port is provided by default
port=22122
Copy the code

3) Start the tracker

# # start
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
## Check status
[root@localhost fdfs]# netstat -apn|grep fdfs
Copy the code

4. Configure the data store

1) View the configuration file

[root @ localhost fastdfs 5.11]# cd /etc/fdfs/
[root@localhost fdfs]# ll
storage.conf.sample
Copy the code

2) Configure the storage.conf file

[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# vim storage.conf
## Pay attention to the following configurations
## storage Where data and logs are stored
base_path=/data/fastdfs/data
The default group name
group_name=group1
The storage ports of the same group must be the same
port=23000
Configure a storage path
store_path_count=1
store_path0=/data/fastdfs/data
Configure the tracker IP and portTracker_server = 192.168.72.130:22122Copy the code

3) Start the storage service

# # start
[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
## Check the process
[root@localhost fdfs]# netstat -apn|grep fdfs
tcp 0:22122  LISTEN      4845/fdfs_trackerd  
tcp 0:45422  SYN_SENT    5410/fdfs_storaged
View the startup log
[root@localhost fdfs]# tail -f /data/fastdfs/data/logs/storaged.log
A single FastDFS installation is successful
setThe tracker leader: 192.168.72.130:22122Check whether the Storage and Tracker are communicating
[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
Storage 1:
	id = 192.168.72.130
	ip_addr = 192.168.72.130 (localhost.localdomain)  ACTIVE
Copy the code

5. Configure client tests

1) View the configuration file

[root@localhost /]# cd /etc/fdfs
[root@localhost fdfs]# ll
total 40
client.conf.sample
Copy the code

2) Configure the client.conf file

[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
## Pay attention to the following configurations
Client data and log directory
base_path=/data/fastdfs/client
Configure the tracker IP and portTracker_server = 192.168.72.130:22122Copy the code

3) Client test

Invoke the client file upload command

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf

Returns the relative file upload path and number

group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg

[root@localhost fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /data/img/img1.jpg 
group1/M00/00/00/wKhIgl0mmE-ATEXPAAQ2pIoAy98392.jpg
Copy the code

Now you have a single FastDFS environment installed, which is a bit cumbersome, but that’s life.

The file was successfully uploaded to the storage server, but the download cannot be viewed. An Nginx server is required to support Http access to files.

Install Nginx

1. Download and unzip Nginx

# # download nginx
[root@localhost mysoft]# wget 
http://nginx.org/download/nginx-1.15.2.tar.gz
# # decompression nginx
[root@localhost mysoft]# tar - ZXVF nginx - 1.15.2. Tar. Gz
Copy the code

2, download the decompression fast-nginx

# # download fastdfs - nginx
[root@localhost mysoft]#wget 
https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# # decompression fastdfs - nginx
[root@localhost mysoft]# mv 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip fast-nginx.zip
[root@localhost mysoft]# unzip fast-nginx.zip
[root@localhost mysoft]# mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1/ 
fastdfs-nginx-module
Copy the code

3, installation must depend on

# # pcre - devel environment[root @ localhost nginx - 1.15.2]# yum install -y pcre pcre-devel
# # zlib - devel environment[root @ localhost nginx - 1.15.2]# yum install -y zlib zlib-devel
# # openssl devel - environment[root @ localhost nginx - 1.15.2]# yum install -y openssl openssl-devel
Copy the code

4. Configure and install

[root @ localhost nginx - 1.15.2]# ./configure --add-module=/usr/local/mysoft/fastdfs-nginx-module/src[root @ localhost nginx - 1.15.2]# make && make install
Copy the code

5. Error resolution

Because of a version issue, fast-Nginx must use this fixed version.

Github.com/happyfish10…

make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/usr/local/ mysoft/nginx - 1.15.2'
make: *** [build] Error 2
Copy the code

6. View the installation result

If the following information is displayed, the installation is successful.

[root @ localhost nginx - 1.15.2]# /usr/local/nginx/sbin/nginx -VNginx version: nginx/1.15.2 Built by GCC 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
Copy the code

Test image access

1. Configure the client

## Move the profile
[root@localhost src]# pwd
/usr/local/mysoft/fastdfs-nginx-module/src
[root@localhost src]# ll
total 76
Apr 14  2017 mod_fastdfs.conf
[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/
[root@localhost fdfs]# pwd
/etc/fdfs
[root@localhost fdfs]# vim mod_fastdfs.conf 
## Adjust the following configuration
## Link timed out
connect_timeout=20
Configure the tracker IP and portTracker_server = 192.168.72.130:22122## The path contains groups
url_have_group_name = true
The configuration must be the same as that of storage
store_path0=/data/fastdfs/data
Copy the code

2. Improve the FastDFS configuration

[root@localhost fdfs]# CD/usr/local/mysoft/fastdfs - 5.11 / conf /
[root@localhost conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/
Copy the code

3. Configure Nginx

Add the following configuration under service port 80 of Nginx. Note that the path here is automatically generated by the Nginx installation.

[root@localhost nginx]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.confserver { listen 80; location ~/group([0-9])/M00 { root /data/fastdfs/data; ngx_fastdfs_module; }}Copy the code

Viewing configuration Results

[root@localhost conf]# /usr/local/nginx/sbin/nginx -VNginx version: nginx/1.15.2 Built by GCC 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --add-module=/usr/local/mysoft/fastdfs-nginx-module/src
Copy the code

The configuration is successful.

Witness the end of the time

Start the Nginx service.

# # start
/usr/local/nginx/sbin/nginx
# # to stop
/usr/local/nginx/sbin/nginx -s stop
# # to restart
/usr/local/nginx/sbin/nginx -s reload
Copy the code

5. Access uploaded pictures

Meow, meow, it worked. See you in the next article.

http://192.168.72.130 / group1 M00/00/00 / wKhIgl0mmE - ATEXPAAQ2pIoAy98392. JPGCopy the code

Six, source code address

Making address: given a smile cloud address: https://github.com/cicadasmile code laughed told https://gitee.com/cicadasmileCopy the code