Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build fastDFS distributed system

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

About FastDFS the FastDFS server has two roles: a tracker (tracker) and a storage node (storage). The tracker mainly does the scheduling work and plays the role of load balancing on the access.

The storage node stores files and completes all the functions of file management: it stores, synchronizes and provides access interfaces, and FastDFS manages the metadata of files at the same time. The so-called meta data of a file is the relevant attributes of the file, expressed in the form of key-value pairs (key value), such as: width=1024, in which the key is width,value is 1024. A file metadata is a list of file attributes that can contain multiple key-value pairs.

FastDFS architecture

The FastDFS architecture includes Tracker server and Storage server. The client requests Trackerserver to upload and download files, and through Trackerserver scheduling, Storage server finally completes the upload and download of files.

The FastDFS system has three roles: tracking server (Tracker Server), storage server (Storage Server), and client (Client).

Tracker Server: tracking server, mainly doing scheduling work, plays a balanced role; responsible for managing all storage server and group, each storage will connect to Tracker after startup, inform itself of group and other information, and maintain a periodic heartbeat. When uploading files through Trackerserver, you can find Storageserver to provide file upload services according to some strategies.

Advantages (1) massive storage: master-slave distributed storage, storage space is easy to expand, (2) fastDFS does hash processing of file content to avoid duplicate files (3) then fastDFS integrates Nginx to provide website efficiency composition structure 1, tracker (tracker): tracker mainly does scheduling work; 2, storage node (storage): plays the role of load balancing on access

Lab environment tracker server 192.168.13.128 (libfastcommon, fastd,) storage+Nginx server 192.168.13.129 (libfastcommon) 1 Install libfastcommon service [root@tracker] # yum-y install libevent\ # on all node servers libevent-devel perl make gcc zlib zlib-devel\ pcre pcre-devel gcc-c++ openssl-devel [root@tracker] # wget https://github.com/happyfish200/libfastcommon/archive/V1.0.38.tar.gz## download the libfastcommon package [root@tracker] # tar zxvf V1.0.38 from the website. Tar.gz-C / opt/ # # decompress [root@tracker ~] # cd / opt/libfastcommon-1.0.38/ [root@tracker libfastcommon-1.0.38] #. / make.sh & &. / make.sh install # # compile and install # # establish a soft connection to facilitate system identification [root@tracker libfastcommon-1.0.38] # ln-s / usr/lib64/libfastcommon.so / usr/local/lib/libfastcommon.so [root@tracker libfastcommon- 1.0.38] # ln-s / usr/lib64/libfdfsclient.so / usr/local/lib/libfdfsclient.so [root@tracker libfastcommon-1.0.38] # ln-s / usr/lib64/libfdfsclient.so / usr/lib/libfdfsclient.so2 Install the fastDFS service [root@storage] # wget https://github.com/happyfish200/fastdfs/archive/V5.11.tar.gz## on all node servers and download the package [root@storage] # tar zxf V5.11.tar.gz-C / opt/ # # decompress [root@storage ~] # cd / opt/fastdfs-5.11/ [root@storage fastdfs-5.11] #. / make.sh & &. / make from the website .sh install # # compile and install [root@storage fastdfs-5.11] # cd / etc/fdfs/ # # copy configuration file template [root@storage fdfs] # cp tracker.conf.sample tracker.conf [root@storage fdfs] # cp storage.conf.sample storage.conf [root@storage fdfs] # cp client.conf.sample client.conf3 Configure tracker server [root@tracker fdfs] # mkdir-m 755-p / opt/fastdfs # # create data files, and log files are stored in the directory [root@tracker fdfs] # vim / etc/fdfs/tracker.conf # # modify the tracker configuration file port=22122 / / tracker service default port 22122 to base_path=/opt/fastdfs / / tracker to store the paths of data and log The http service process on the http.server_port=8080 / / tracker server must be created in advance. Ignore [root@tracker fdfs] # fdfs_trackerd / etc/fdfs/tracker.conf start # # enable the service [root@tracker fdfs] # netstat-natp | grep 22122tcp 0 0 0.0. 0. 0. 0. 0. 22 22. 0. 0. 0. 0. 0. Etc/fdfs/tracker.conf start * LISTEN 2678/fdfs_trackerd [root@tracker fdfs] # vim / etc/rc.local # # set Boot # # add fdfs_trackerd on the last line / etc/fdfs/tracker.conf start [root@tracker fdfs] # systemctl stop firewalld.service # # turn off the firewall [root@tracker fdfs] # setenforce 04 Configure storage server [root@storage fdfs] # mkdir-m 755-p / opt/fastdfs # # create data and log file directories [root@storage fdfs] # vim / etc/fdfs/storage.conf # # modify storage configuration file group_name=group1 / / default group name, modify port=23000 / / storge default 23000 according to the actual situation The storage port number of the same group must be the same as the root path store_path_count=1 / / of the base_path=/opt/fastdfs / / storage log file. The default is the storage path provided by 1store_path0=/opt/fastdfs / / (stored with the log file by default) tracker_server=192.168.13.128:22122 / / your own tracker server IP (emphasis!! ) the port for http.server_port=80 / / http access files defaults to 8888 The listening ports configured in nginx remain the same [root@storage fdfs] # fdfs_storaged / etc/fdfs/storage.conf start # # enable the service [root@storage fdfs] # netstat-ntap | grep 23000tcp 00 0.0.0.0fdfs_storaged 23000 0.0.0.0fdfs_storaged * LISTEN 2687/fdfs_storaged [root@storage fdfs] # echo "fdfs_storaged / etc/fdfs/storage.conf start "> > / etc/rc.local # # Boot [root@storage fdfs] # systemctl stop firewalld.service # # turn off the firewall [root@storage fdfs] # setenforce 0 [root@storage fdfs] # fdfs_monitor / etc/fdfs/storage.conf # # check whether the association with tracker is successful Storage 1:id = 192.168.13.129ip_addr = 192.168.13.129 (storage) ACTIVE...5 Install Nginx## on the storage server here to reduce the number of virtual machines turned on Install nginx on the storageside [root@storage fdfs] # wget https://github.com/happyfish200/fastdfs-nginx-module/archive/V1.20.tar.gz## download module zip package [root@storage fdfs] # tar zxf V1.20.tar.gz-C / opt/ # # decompress [root@storage fdfs] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/Password for root@//192.168.100.3/LNMP -C7: [root@storage fdfs] # cd / mnt/ [root@storage mnt] # tar zxvf nginx-1.12.2.tar.gz-C / opt/ # # decompress [root@storage mnt] # cd / opt/nginx-1.12.2 [root@storage nginx-1.12.2] #. / configure\-- prefix=/usr/local/nginx\-- add-module=/opt/fastdfs-nginx-module-1.20/src/ # # fastdfs -nginx-module module [root@storage nginx-1.12.2] # make & & make install## possible error # / usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory## solution # # modify fastdfs-nginx-module-1.20/src/config file Then reconfigure the compiler and install ngx_module_incs= "/ usr/include/fastdfs / usr/include/fastcommon/" CORE_INCS= "$CORE_INCS / usr/include/fastdfs / usr/include/fastcommon/" [root@storage nginx-1.12.2] # cd.. / fastdfs-nginx-module-1.20/src/ [root@storage src] # cp mod_fastdfs.conf / etc/fdfs/ [root@storage src] # cd / etc/fdfs/ [root@storage fdfs] # Vim mod_fastdfs.conf # # configure fastdfs-nginx-module module # check the configuration base_path=/opt/fastdfs / / store data files, The address of the tracker_server=192.168.13.128:22122 / / tracker side of the log path (key! ) url_have_group_name = whether true / / url contains the group name storage_server_port=23000 / / the same number of store_path_count=1 / / storage paths required as the storage configuration Need to match the number of store_path to match the location of store_path0=/opt/fastdfs / / file storage [root@storage fdfs] # vim / usr/local/nginx/conf/nginx.conf # # configuration Nginx configuration file # add at blank line. Failure to do this may result in an error location ~ / M00 {root / opt/fastdfs/data Ngx_fastdfs_module } [root@storage fdfs] # cd / opt/fastdfs-5.11/conf/ [root@storage conf] # cp mime.types http.conf / etc/fdfs/ # # copy the http.conf and mime.types6 in the directory decompressed by fastdfs Modify the client client (used here on the storage server) [root@storage ~] # vim / etc/fdfs/client.conf# check the following configuration base_path=/opt/fastdfs # # tracker server file path tracker_server=192.168.13.128:22122 # # tracker server IP address and port number http.tracker_server_port=8080 # # http port number of the tracker server, which must correspond to the tracker setting 7 FastDFS commonly used commands to upload files: / usr/bin/fdfs_upload_file download file: / usr/bin/fdfs_download_file [local_filename] delete files: / usr/bin/fdfs_delete_file Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report