Basic overview
FastDFS is an open-source lightweight distributed file system, which manages files. Its functions include file storage, file synchronization, file access (file upload, file download), etc. It solves the problems of mass storage and load balancing. It is especially suitable for online services based on documents, such as album websites, video websites, etc.
FastDFS is customized for the Internet, fully considering redundant backup, load balancing, linear expansion and other mechanisms, and focusing on high availability, high performance and other indicators. Using FastDFS, it is easy to build a set of high-performance file server cluster to provide file upload, download and other services.
Basic structure diagram
The FastDFS server has two roles: tracker and storage node. Tracker is mainly used for scheduling and load balancing in access.
Both the tracker and the storage node can be composed of one or more servers. Servers in tracker and storage node can be added or offline at any time without affecting online services. All servers in the tracker are equal, which can be increased or decreased at any time according to the pressure of the server.
When a server is added to a volume, the system automatically synchronizes the existing files. After the synchronization, the system automatically switches the new server to online service.
Basic experimental deployment
1. Experiment preparation
Name | role | IP address |
---|---|---|
centos7-1 | tracker | 192.168.45.135 |
centos7-2 | storage+nginx | 192.168.45.132 |
Experiment software package extraction code
Links: https://pan.baidu.com/s/1_Xs09mdST6VNLue11dqhyQ
Extraction code: 9ql5
2. Start installation
Modify the names of two servers
Change one to tracker and one to storage
hostnamectl set-hostname tracker storage su
Install basic environment package
yum -y install libevent libevent-devel perl make gcc zlib zlib-devel pcre pcre-devel gcc-c++ openssl-devel
Install libfastcommon service (all nodes are installed)
mount.cifs //192.168.100.3/lzp /mnt #Install libfastcommon service cd /mnt/fastDFS/ tar zxvf libfastcommon-1.0.39.tar.gz -C /opt cd /opt/libfastcommon-1.0.39/ #Compile, install and establish soft link for system identification ./make.sh && ./make.sh install ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
Install FastDFS service (all nodes are installed)
cd /mnt/fastDFS/ tar zxvf fastdfs-5.11.tar.gz -C /opt #Compilation and installation cd /opt/fastdfs-5.11/ ./make.sh && ./make.sh install cd /etc/fdfs/ cp tracker.conf.sample tracker.conf cp storage.conf.sample storage.conf cp client.conf.sample client.conf
tracker monitoring configuration
# Establish the storage directory of data files and log files [root@tracker ~]# mkdir -m 755 -p /opt/fastdfs //Modifying the tracker profile [root@tracker ~]# vim /etc/fdfs/tracker.conf #Modify the following configuration #Port = 22122 / / the default port of the tracker service is 22122 base_path=/opt/fastdfs //The following path of the 22 line tracker to store data and log must be created in advance. The following path of the tracker to store data and log must be created in advance #http. Server_port = 8080 / / the http service process is started on the tracker server and ignored if it is not installed #Opening service fdfs_trackerd /etc/fdfs/tracker.conf start #Set power on self start [root@tracker ~]# vim /etc/rc.local #Last line add fdfs_trackerd /etc/fdfs/tracker.conf start #Turn off firewall and security features [root@tracker ~]# systemctl stop firewalld [root@tracker ~]# setenforce 0
storage server modification
#Establish the storage directory of data files and log files [root@storage ~]# mkdir -m 755 -p /opt/fastdfs //Modify storage profile [root@storage ~]# vim /etc/fdfs/storage.conf #Modify the following configuration group_name=group1 //Default group name, modified according to actual situation port=23000 //Storage defaults to 23000, and the storage port number of the same group must be the same base_path=/opt/fastdfs //The root path of the storage log file store_path_count=1 //The number of paths is the same as the following, the default is 1 store_path0=/opt/fastdfs //109 storage path provided (stored with log file by default) tracker_server=192.168.45.135:22122 //Own tracker server IP (key!!!) http.server_port=80 //The port of http access file is 8888 by default, and the listening port configured in nginx is consistent //Turn on the service and set the startup #Start service (the command supports start stop restart) [root@storage ~]# fdfs_storaged /etc/fdfs/storage.conf start [root@storage ~]# netstat -atnp | grep 23000 tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 40430/fdfs_storaged #Set power on self start [root@storage ~]# vim /etc/rc.local #Last line add fdfs_storaged /etc/fdfs/storage.conf start [root@storage ~]# systemctl stop firewalld [root@storage ~]# setenforce 0 //Check whether the association with the tracker monitoring end is successful fdfs_monitor /etc/fdfs/storage.conf
Install nginx service (storage: 192.168.45.132)
In order to reduce the number of virtual machines opened, install nginx on the storage side
cd /mnt/fastDFS/ [root@storage fastDFS]# tar zxvf nginx-1.12.0.tar.gz -C /opt tar zxvf fastdfs-nginx-module-1.20.tar.gz -C /opt # Modify / opt/fastdfs-nginx-module-1.20/src/config file [root@storage fastDFS]# vim /opt/fastdfs-nginx-module-1.20/src/config ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/" CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/" #Compilation and installation cd /opt/nginx-1.12.0/ [root@storage nginx-1.12.0]# ./configure \ --prefix=/usr/local/nginx \ --add-module=/opt/fastdfs-nginx-module-1.20/src/ make && make install cd /opt/fastdfs-nginx-module-1.20/src cp mod_fastdfs.conf /etc/fdfs/ #Modify the fastdfs nginx module module module configuration file mod-fasts.conf [root@storage nginx-1.12.0]# cd /etc/fdfs [root@storage fdfs]# vim mod_fastdfs.conf #Check the configuration base_path=/opt/fastdfs //Path to store data files and logs tracker_server=192.168.45.135/:22122 //Address of tracker (important!!!) url_have_group_name = true //Whether the url contains the group name storage_server_port=23000 //It needs to be the same as the storage configuration store_path_count=1 //The number of storage paths needs to match the number of storage paths store_path0=/opt/fastdfs //62 location of line file storage #Modify nginx configuration file [root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf #Add at blank line in server location ~/M00 { root /opt/fastdfs/data; ngx_fastdfs_module; } #Create soft link [root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #Inspection nginx configuration file [root@localhost ~]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #start nginx [root@localhost ~]# nginx #Copying http.conf and mime.types in the fastdfs decompression directory without doing this may result in an error [root@storage fdfs]# cd /opt/fastdfs-5.11/conf/ [root@storage conf]# cp mime.types http.conf /etc/fdfs/
Modify storage side
#Modify profile [root@storage ~]# vim /etc/fdfs/client.conf #Check the following configuration base_path=/opt/fastdfs //tracker server file path tracker_server=192.168.45.135:22122 //tracker server IP address and port number http.tracker_server_port=8080 // The http port number of the tracker server, and
Upload test file command:
/usr/bin/fdfs_upload_file <config_file> <local_filename>
Command demonstration:
[root@localhost mnt]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf 1.jpg group1/M00/00/00/wKgthF4AKVmAY9WYABIrwU4wXNs537.jpg
Download File command:
/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]
Example
/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh3TEws726.jpg test2.jpg**
Delete file command:
/usr/bin/fdfs_delete_file <config_file> <file_id>
Example:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh3TEws726.jpg