Centos7 configuration fastdfs and nginx distributed file storage system implementation process analysis

Centos7 configuration fastdfs and nginx distributed file storage system implementation process analysis

1. Install libfastcommon-1.0.43. The installation package can be downloaded from https://github.com/happyfish100/libfastcommon/releases

[root@localhost Downloads]# tar -zxvf libfastcommon-1.0.43.tar.gz

# After decompression, enter the directory to compile and install
[root@localhost libfastcommon-1.0.43]#cd libfastcommon-1.0.43
[root@localhost libfastcommon-1.0.43]#make
[root@localhost libfastcommon-1.0.43]#make install

Note: After libfastcommon is installed, the libfastcommon.so library file will be generated in the /usr/lib64 directory; since the FastDFS program references the usr/lib directory, you need to copy the library file in /usr/lib64 to /usr/lib

cp /usr/lib64/libfastcommon.so /usr/lib

2. Install fastdfs. The installation package can be downloaded from https://github.com/happyfish100/fastdfs/releases

# Unzip to the current directory
tar -zxvf fastdfs-6.06.tar.gz

# Enter the directory to compile and install
make.sh
make.sh install

After successful installation, copy the files under /conf to /etc/fdfs

[root@localhost conf]# ll
total 92
-rw-rw-r--. 1 root root 23981 Dec 31 07:36 anti-steal.jpg
-rw-rw-r--. 1 root root 1909 Dec 31 07:36 client.conf
-rw-rw-r--. 1 root root 965 Dec 31 07:36 http.conf
-rw-rw-r--. 1 root root 31172 Dec 31 07:36 mime.types
-rw-rw-r--. 1 root root 10246 Dec 31 07:36 storage.conf
-rw-rw-r--. 1 root root 620 Dec 31 07:36 storage_ids.conf
-rw-rw-r--. 1 root root 9138 Dec 31 07:36 tracker.conf
[root@localhost conf]# cd ..
[root@localhost fastdfs-6.06]# cp /conf/* /etc/fdfs
[root@localhost fastdfs-6.06]# ll /etc/fdfs
total 128
-rw-r--r--. 1 root root 23981 Jun 21 02:16 anti-steal.jpg
-rw-r--r--. 1 root root 1904 Jun 21 02:24 client.conf
-rw-r--r--. 1 root root 1909 Jun 21 02:15 client.conf.sample
-rw-r--r--. 1 root root 965 Jun 21 02:54 http.conf
-rw-r--r--. 1 root root 31172 Jun 21 02:54 mime.types
-rw-r--r--. 1 root root 3738 Jun 21 02:41 mod_fastdfs.conf
-rw-r--r--. 1 root root 10238 Jun 21 02:23 storage.conf
-rw-r--r--. 1 root root 10246 Jun 21 02:15 storage.conf.sample
-rw-r--r--. 1 root root 620 Jun 21 02:16 storage_ids.conf
-rw-r--r--. 1 root root 620 Jun 21 02:15 storage_ids.conf.sample
-rw-r--r--. 1 root root 9129 Jun 21 02:18 tracker.conf
-rw-r--r--. 1 root root 9138 Jun 21 02:15 tracker.conf.sample
[root@localhost fastdfs-6.06]#

3. Configure and start the tracker

# Enter the /etc/fdfs directory cd /etc/fdfs

# Copy a new tracker configuration file cp tracker.conf.sample tracker.conf

#Modify tracker.conf ; vim tracker.conf
# /home/fastdfs is used to store tracker data and log
base_path=/home/yuqing/fastdfs is changed to: base_path=/home/fastdfs
http.server_port is changed to: 80

# Start the tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

4. Configure and start storage

# Enter the /etc/fdfs directory cd /etc/fdfs

# Copy a new tracker configuration file cp storage.conf.sample storage.conf

# Modify storage.conf ; vim storage.conf
group_name=group1 #Configure group name base_path=/home/yuqing/fastdfs to: base_path=/home/fastdfs

#store file location (store_path)
store_path0=/home/yuqing/fastdfs is changed to: store_path0=/home/fdfs_storage 
#If there are multiple mounted disks, define multiple store_paths, as follows#store_path1=.....
#store_path2=......

#Configure tracker server: IP
tracker_server=192.168.172.20:22122
# If there are multiple trackers, configure multiple trackers
#tracker_server=192.168.101.4:22122

#Configure http port, use the default port http.server_port=8888

#Start storage, run the command as follows:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

#After the startup is complete, enter the /home/fdfs_storage/data directory, and the directory is displayed as follows [root@localhost home]# cd fdfs_storage/
[root@localhost fdfs_storage]# ls
data
[root@localhost fdfs_storage]# cd data/
[root@localhost data]# ls
00 0A 14 1E 28 32 3C 46 50 5A 64 6E 78 82 8C 96 A0 AA B4 BE C8 D2 DC E6 F0 FA
01 0B 15 1F 29 33 3D 47 51 5B 65 6F 79 83 8D 97 A1 AB B5 BF C9 D3 DD E7 F1 FB
02 0C 16 20 2A 34 3E 48 52 5C 66 70 7A 84 8E 98 A2 AC B6 C0 CA D4 DE E8 F2 FC
03 0D 17 21 2B 35 3F 49 53 5D 67 71 7B 85 8F 99 A3 AD B7 C1 CB D5 DF E9 F3 FD
04 0E 18 22 2C 36 40 4A 54 5E 68 72 7C 86 90 9A A4 AE B8 C2 CC D6 E0 EA F4 FE
05 0F 19 23 2D 37 41 4B 55 5F 69 73 7D 87 91 9B A5 AF B9 C3 CD D7 E1 EB F5 FF
06 10 1A 24 2E 38 42 4C 56 60 6A 74 7E 88 92 9C A6 B0 BA C4 CE D8 E2 EC F6
07 11 1B 25 2F 39 43 4D 57 61 6B 75 7F 89 93 9D A7 B1 BB C5 CF D9 E3 ED F7
08 12 1C 26 30 3A 44 4E 58 62 6C 76 80 8A 94 9E A8 B2 BC C6 D0 DA E4 EE F8
09 13 1D 27 31 3B 45 4F 59 63 6D 77 81 8B 95 9F A9 B3 BD C7 D1 DB E5 EF F9
[root@localhost data]#

5. Use fastdfs built-in tools to test uploading files

# Switch directory to /etc/fdfs/ cd /etc/fdfs

# Copy a new client configuration file cp client.conf.sample client.conf

# Modify client.conf ; vim client.conf
base_path = /home/fastdfs
tracker_server = 192.168.52.133:22122
#tracker_server = 192.168.0.197:22122

#To test uploading files, run as follows:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload wyc01.jpg

#result:
[youth@localhost Pictures]$ /usr/bin/fdfs_test /etc/fdfs/client.conf upload wyc01.jpg 
This is FastDFS client test program v6.06

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.fastken.com/ 
for more details.

[2020-06-21 03:54:35] DEBUG - base_path=/home/fastdfs, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group: 
 server 1. group_name=, ip_addr=192.168.52.133, port=23000

group_name=group1, ip_addr=192.168.52.133, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKg0hV7uaXyALZfuAABDP6pWIGE814.jpg
source ip address: 192.168.52.133
file timestamp=2020-06-21 03:54:36
file size=17215
file crc32=2857771105
example file url: http://192.168.52.133/group1/M00/00/00/wKg0hV7uaXyALZfuAABDP6pWIGE814.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKg0hV7uaXyALZfuAABDP6pWIGE814_big.jpg
source ip address: 192.168.52.133
file timestamp=2020-06-21 03:54:36
file size=17215
file crc32=2857771105
example file url: http://192.168.52.133/group1/M00/00/00/wKg0hV7uaXyALZfuAABDP6pWIGE814_big.jpg
[youth@localhost Pictures]$

Note: http://192.168.52.133/group1/M00/00/00/wKg0hV7uaXyALZfuAABDP6pWIGE814.jpg is the link of the picture just uploaded, but nginx is not integrated now, so it cannot be accessed through http

6. Fastdfs and nginx integration

①Install fastdfs-nginx-module. The installation package can be downloaded from https://github.com/happyfish100/fastdfs-nginx-module/releases

#Unzip tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

# Enter the directory to modify the conf configuration cd /usr/local/fastdfs-nginx-module/src/

vim conf

 HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
 NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
 # Only modify here and delete local CORE_INCS="$CORE_INCS /usr/include"
 CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
 CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

②Copy mod_fastdfs.conf under fastdfs-nginx-module/src to /etc/fdfs/

cp mod_fastdfs.conf /etc/fdfs/

③ And modify the content of /etc/fdfs/mod_fastdfs.conf; vi /etc/fdfs/mod_fastdfs.conf

base_path=/home/fastdfs
tracker_server=192.168.172.20:22122
#tracker_server=192.168.172.20:22122 #(multiple trackers with multiple lines)
url_have_group_name=true #The url contains the group name
store_path0=/home/fdfs_storage #Specify the file storage path (store path configured above)

7. Install nginx

# There is an installation package on the nginx official website, which can be downloaded directly # Unzip tar -zxvf nginx-1.8.0.tar.gz

# Enter the directory and configure the command # --prefix is ​​the installation path of nginx # --add-module is the file path after fastdfs-nginx-module is decompressed./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-module=/usr/local/fastdfs-nginx-module/src# Compile and install make && make install# Copy the two files in the nginx-1.19.0/conf configuration folder (unzipped nginx) to /etc/fdfs
cp http.conf mime.types /etc/fdfs/

Note: The temporary file directory is specified as /var/temp/nginx above. You need to create temp and nginx directories under /var. I specified pid-path, so I also need to create an nginx in the /var/run folder, and then create an nginx.pid in the nginx folder. Otherwise, when you start nginx, you will get an error: nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory). It is recommended not to specify it. This pit is too deep.

8. Modify the nginx configuration file

server {
  listen 80;
  #server_name localhost;
  server_name 192.168.52.133;

  #charset koi8-r;

  #access_log logs/host.access.log main;
 
  location ~/group([1~9])/M00/{
   root /home/fdsf_storage/data;
   ngx_fastdfs_module;
  }

  location / {
   root html;
   index index.html index.htm;
  }

9. Start nginx. Since nginx uses port 80 by default, make sure that port 80 is not occupied. If it is occupied, kill it. Make sure that the firewall allows external devices to access the server.

/use/local/nginx/sbin/nginx

[root@localhost fdfs]# ps -ef | grep nginx
root 7466 1 0 03:12 ? 00:00:00 nginx: master process nginx
nobody 7590 7466 0 03:21 ? 00:00:00 nginx: worker process
root 8514 2806 0 04:17 pts/0 00:00:00 grep --color=auto nginx
[root@localhost fdfs]#

10. Access fastdfs file system images through external devices

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of file storage in Android
  • Android development to implement file storage function
  • Django file storage custom storage system analysis
  • Analysis of Django's default storage system for file storage
  • Android I/0 stream operation file (file storage)

<<:  Summary of common MySQL function examples [aggregate functions, strings, numbers, time and date processing, etc.]

>>:  js canvas realizes rounded corners picture

Blog    

Recommend

How to configure MGR single master and multiple slaves in MySQL 8.0.15

1. Introduction MySQL Group Replication (MGR for ...

Markup language - simplified tags

Click here to return to the 123WORDPRESS.COM HTML ...

Implementation of deploying Apollo configuration center using docker in CentOS7

Apollo open source address: https://github.com/ct...

React tips teach you how to get rid of hooks dependency troubles

A very common scenario in react projects: const [...

MySQL trigger usage scenarios and method examples

trigger: Trigger usage scenarios and correspondin...

MySQL uses inet_aton and inet_ntoa to process IP address data

This article will introduce how to save IP addres...

Learn the common methods and techniques in JS arrays and become a master

Table of contents splice() Method join() Method r...

How to hide and forge version number in Nginx

1. Use curl command to access by default: # curl ...

Is the tag li a block-level element?

Why can it set the height, but unlike elements lik...

Implementation of automatic completion of Docker commands

Preface I don't know how long this friend has...

JavaScript timer to achieve limited time flash sale function

This article shares the specific code of JavaScri...

How to add a certificate to docker

1. Upgrade process: sudo apt-get update Problems ...

Tutorial on how to quickly deploy clickhouse using docker-compose

ClickHouse is an open source column-oriented DBMS...