Dubbo Advanced _04_FASTDFS The installation and application of Distributed File system

Source: Internet
Author: User
Tags openssl iptables node server

Fastdfs Introduction

Fastdfs is a lightweight open source Distributed File system
Fastdfs mainly solves the problem of large capacity file storage and high concurrency access, and realizes load balance in file access.
FASTDFS implements a software-style raid that can be stored using a cheap IDE hard disk
Support Storage Server Online expansion
Files that support the same content save only one copy, saving disk space
Fastdfs can only be accessed through the client API and does not support the POSIX access method
Fastdfs is especially suitable for medium and large Web sites to store resource files (e.g. pictures, documents, audio, video, etc.)


System architecture


Tracking Service: 192.168.1.131 (installed to consumer)

Storage server: 192.168.1.51 (installed to CI server)

Environment: CentOS6.6

User: Root

Data directory:/fastdffs (data directory According to your data disk mount path depends)

installation package

Fastdfs v5.05

Libfastcommon-master.zip (is a common C function library extracted from Fastdfs and FASTDHT) fastdfs-nginx-module_v1.16.tar.gz

Nginx-1.6.2.tar.gz

Fastdfs_client_java._v1.25.tar.gz

Source Address: Https://github.com/happyfish100/

Download Address: http://sourceforge.net/projects/fastdfs/files/

Official Forum: http://bbs.chinaunix.net/forum-240-1.html


One, all tracking servers and storage servers perform the following actions

1. Build and install the required dependency packs

Connecting to 192.168.1.131:22 ...
Connection established.
To an escape to the local shell, press ' ctrl+alt+] '.


Last Login:sun APR 3 00:12:21 2016 from 192.168.1.2
[Root@consume ~]# yum install make cmake gcc gcc-c++


2. Install Libfastcommon:

(1) Upload or download libfastcommon-master.zip to/usr/local/src directory


(2) Decompression

[Root@consume ~]# cd/usr/local/src/
[Root@consume src]# Unzip Libfastcommon-master.zip
[Root@consume src]# CD Libfastcommon-master
[Root@consume libfastcommon-master]# LL
Total 28
-rw-r--r--. 1 root root 2913 Feb 2015 HISTORY
-rw-r--r--. 1 root root 582 Feb 2015 INSTALL
-rw-r--r--. 1 root root 1342 Feb 2015 Libfastcommon.spec
-rwxr-xr-x. 1 root root 2151 Feb 2015 make.sh
Drwxr-xr-x. 2 root root 4096 Feb 2015 Php-fastcommon
-rw-r--r--. 1 root root 617 Feb 2015 README
Drwxr-xr-x. 2 root 4096 Feb 2015 SRC

(3) Compile, install [Root@consume libfastcommon-master]#./make.sh
[Root@consume libfastcommon-master]#./make.sh Install

# Libfastcommon is installed by default.

/usr/lib64/libfastcommon.so

/usr/lib64/libfdfsclient.so

(4) Because the Lib directory set by the FASTDFS main program is/usr/local/lib, you need to create a soft link. [Root@consume libfastcommon-master]# ln-s/usr/lib64/libfastcommon.so/usr/local/lib/libfastcommon.so
[Root@consume libfastcommon-master]# ln-s/usr/lib64/libfastcommon.so/usr/lib/libfastcommon.so
[Root@consume libfastcommon-master]# ln-s/usr/lib64/libfdfsclient.so/usr/local/lib/libfdfsclient.so
[Root@consume libfastcommon-master]# ln-s/usr/lib64/libfdfsclient.so/usr/lib/libfdfsclient.so


Install Fastdfs

(1) Upload or download Fastdfs source package (fastdfs_v5.05.tar.gz) to/usr/local/src directory

(2) Decompression

[Root@consume libfastcommon-master]# CD/USR/LOCAL/SRC

Root@consume src]# ll | grep Fast
-rw-r--r--. 1 root 345400 Mar 2015 fastdfs_v5.05.tar.gz
[Root@consume src]# TAR-ZXVF fastdfs_v5.05.tar.gz
(3) Compile, install (before compiling to ensure that the Libfastcommon has been successfully installed)
[Root@consume src]# CD Fastdfs
[Root@consume fastdfs]#./make.sh
[Root@consume fastdfs]#./make.sh Install
Installed by default installation, the corresponding files and directories after installation:

A, service scripts in:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker
[Root@consume fastdfs]# LS/ETC/INIT.D | grep Fdfs
Fdfs_storaged
Fdfs_trackerd


B, configuration file in (sample configuration file):
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sample
[Root@consume fastdfs]# Ls/etc/fdfs | grep conf
Client.conf.sample
Storage.conf.sample
Tracker.conf.sample


C, the command tool in the/usr/bin/directory:
[Root@consume fastdfs]# Ls/usr/bin | grep Fdfs
Fdfs_appender_test
Fdfs_appender_test1
Fdfs_append_file
Fdfs_crc32
Fdfs_delete_file
Fdfs_download_file
Fdfs_file_info
Fdfs_monitor
Fdfs_storaged
Fdfs_test
Fdfs_test1
Fdfs_trackerd
Fdfs_upload_appender
Fdfs_upload_file

4 because the Fastdfs service script set the bin directory is/usr/local/bin, but the actual command is installed in/usr/bin, you can access
The/user/bin directory uses the following command to view related commands for Fdfs:
[Root@consume fastdfs]# Cd/usr/bin
[Root@consume bin]# ll | grep Fdfs
It is therefore necessary to modify the corresponding command path in the Fastdfs service script, which is to put the/etc/init.d/fdfs_storaged
And the/usr/local/bin in the/etc/init.d/fdfs_tracker two scripts are modified to/usr/bin:
To unify the changes using the Find substitution command:%s+/usr/local/bin+/usr/bin

[Root@consume bin]# CD/ETC/INIT.D
[Root@consume init.d]# VI Fdfs_trackerd
[Root@consume init.d]# VI fdfs_storaged
Both the tracker and the storage configuration file are changed to ensure that the files are synchronized and consistent

Second, configure Fastdfs Tracker (192.168.1.131)

1, copy the Fastdfs Tracker sample configuration file, and rename:
[Root@consume init.d]# cd/etc/fdfs/
[Root@consume fdfs]# LL
Total 20
-rw-r--r--. 1 root 1461 Apr 3 19:11 client.conf.sample
-rw-r--r--. 1 root 7829 Apr 3 19:11 storage.conf.sample
-rw-r--r--. 1 root 7102 Apr 3 19:11 tracker.conf.sample
[Root@consume fdfs]# CP tracker.conf.sample tracker.conf
2. Edit Tracker configuration file:
[Root@consume fdfs]# vi/etc/fdfs/tracker.conf
The revised content is as follows:

Disabled=false

port=22122

Base_path=/fastdfs/tracker

(Other parameters retain the default configuration, please refer to the official documentation for specific configuration explanations:

http://bbs.chinaunix.net/thread-1941456-1-1.html)

3, create the basic data directory (reference to the basic directory Base_path configuration): [Root@consume fdfs]# mkdir-p/fastdfs/tracker

4, open the tracker port in the firewall (default is 22122): [Root@consume fdfs]# Vi/etc/sysconfig/iptables

Add to:
-A input-m state--state new-m tcp-p TCP--dport 22122-j ACCEPT
[Root@consume fdfs]# Cat/etc/sysconfig/iptables | grep 22122

-A input-m state--state new-m tcp-p TCP--dport 22122-j ACCEPT

Reboot
[Root@consume fdfs]# Service iptables restart

5, start Tracker: [Root@consume fdfs]#/etc/init.d/fdfs_trackerd start
Starting Fastdfs Tracker Server:

To see if Fastdfs Tracker has started successfully:

[Root@consume fdfs]# Ps-ef | grep Fdfs
Root 3870 1 0 19:50? 00:00:00/usr/bin/fdfs_trackerd/etc/fdfs/tracker.conf
Root 3879 3028 0 19:51 pts/0 00:00:00 grep fdfs

(The first successful startup, will be in the/fastdfs/tracker directory to create data, logs two directories)

[Root@consume fdfs]# ll/fastdfs/tracker/
Total 8
Drwxr-xr-x. 2 root 4096 Apr 3 19:50 data
Drwxr-xr-x. 2 root 4096 APR 3 19:50 logs
[Root@consume fdfs]#

6. Close Tracker [root@consume fdfs]#/etc/init.d/fdfs_trackerd Stop
Stopping fdfs_trackerd ...

7, set the Fastdfs tracker boot:
[Root@consume fdfs]# vi/etc/rc.d/rc.local

# # Fastdfs Tracker

/etc/init.d/fdfs_trackerd start Verify that the boot boot is set

[Root@consume fdfs]#/etc/init.d/fdfs_trackerd Status
Fdfs_trackerd is stopped
[Root@consume fdfs]# reboot

Connecting to 192.168.1.131:22 ...
Connection established.
To an escape to the local shell, press ' ctrl+alt+] '.
Last Login:sun APR 3 18:44:38 2016 from 192.168.1.2
[Root@consume ~]#/etc/init.d/fdfs_trackerd Status
Fdfs_trackerd (PID 2152) is running ...
[Root@consume ~]#

Third, configure Fastdfs storage (192.168.1.51)
1, copy FASTDFS Storage sample configuration file, and rename:
[Root@yxq init.d]# Cd/etc/fdfs
[Root@yxq fdfs]# LL
Total 20
-rw-r--r--1 root root 1461 Apr 3 21:45 client.conf.sample
-rw-r--r--1 root root 7829 Apr 3 21:45 storage.conf.sample
-rw-r--r--1 root root 7102 Apr 3 21:45 tracker.conf.sample
[ROOT@YXQ fdfs]# CP storage.conf.sample storage.conf
2. Edit the Memory sample configuration file:
[Root@yxq fdfs]# vi/etc/fdfs/storage.conf

The revised content is as follows:

Disabled=false port=23000

Base_path=/fastdfs/storage

Store_path0=/fastdfs/storage

tracker_server=192.168.4.131:22122

http.server_port=8888

(Other parameters retain the default configuration, please refer to the official documentation for specific configuration explanations:

http://bbs.chinaunix.net/thread-1941456-1-1.html)

3, create the basic data directory (reference to the basic directory Base_path configuration): [Root@yxq fdfs]# mkdir-p/fastdfs/storage

4, open the memory port in the firewall (default is 23000):

[Root@yxq fdfs]# Vi/etc/sysconfig/iptables

Add the following port line:

-A input-m state--state new-m tcp-p TCP--dport 23000-j ACCEPT

[Root@yxq fdfs]# Cat/etc/sysconfig/iptables | grep 23000
-A input-m state--state new-m tcp-p TCP--dport 23000-j ACCEPT

Reboot the firewall:

[ROOT@YXQ fdfs]# Service iptables restart

5, start Storage: [Root@yxq fdfs]#/etc/init.d/fdfs_storaged start
Starting FASTDFS Storage server:

See if Fastdfs Storage has started successfully [ROOT@YXQ fdfs]# Ps-ef | grep Fdfs
Root 11997 1 0 22:16 pts/0 00:00:00/usr/bin/fdfs_storaged/etc/fdfs/storage.conf
Root 12000 11293 0 22:16 pts/0 00:00:00 grep fdfs

(The first successful startup will create data, logs two directories under the/fastdfs/storage directory) [Root@yxq fdfs]# ll/fastdfs/storage/

6, close Storage: [Root@yxq fdfs]#/etc/init.d/fdfs_storaged Stop
Stopping fdfs_storaged ...

7, set up Fastdfs memory boot: [ROOT@YXQ fdfs]# vi/etc/rc.d/rc.local

Add to:

# # Fastdfs Storage

/etc/init.d/fdfs_storaged start

Iv. File Upload Test (192.168.4.121)

1, modify the client configuration file in the Tracker server:

[Root@consume ~]# cp/etc/fdfs/client.conf.sample/etc/fdfs/client.conf

[Root@consume ~]# vi/etc/fdfs/client.conf

Modify
Base_path=/fastdfs/tracker

tracker_server=192.168.1.131:22122

Execute the following command

[Root@consume ~]#/usr/bin/fdfs_upload_file/etc/fdfs/client.conf/usr/local/src/fastdfs_v5.05.tar.gz
Group1/m00/00/00/wkgbm1cb-y2afwsaaavfol7fju4.tar.gz

(Can return the above file ID, description file Upload success)

You can also view the storage server based on group1

[Root@yxq fdfs]# Ll/fastdfs/storage/data/00/00/
Total 340
-rw-r--r--1 root root 345400 Apr 3 22:27 wkgbm1cb-y2afwsaaavfol7fju4.tar.gz
[Root@yxq fdfs]# Date
Sun APR 3 22:31:54 PDT 2016
[Root@yxq fdfs]#

Six, install Nginx on each storage node (only need to install on Storage node server)
1.fastdfs-nginx-module Function Description:
Fastdfs through the tracker server, the files are placed on the storage server storage, but there is a need for file replication between the same group of storage servers, with synchronization latency issues.
Suppose the tracker server uploads the file to 192.168.1.51, and the file ID is returned to the client after the upload succeeds. At this point the FASTDFS storage cluster mechanism will make this file


Sync to the storage 192.168.1.52, if the file has not been replicated, the client will use this file ID to fetch the file on the 192.168.1.52, the file can appear without


Error of the method access, while Fastdfs-nginx-module can redirect files to connect to the source server to fetch files, avoid the client due to replication delay caused by file access error


Miss. (Fastdfs-nnginx-module is used during nginx installation)
2. Upload fastdfs-nginx-module_v1.16.tar.gz to/usr/local/src (start already uploaded)

3. Decompression

[Root@yxq src]# ls
Fastdfs fastdfs_v5.05.tar.gz ng
Fastdfs_client_java._v1.25.tar.gz Libfastcommon-master RE
Fastdfs-nginx-module_v1.16.tar.gz Libfastcommon-master.zip RE
[Root@yxq src]# TAR-ZXVF fastdfs-nginx-module_v1.16.tar.gz

4. Modify Fastdfs-nginx-module Config profile
[Root@yxq src]# CD FASTDFS-NGINX-MODULE/SRC
[Root@yxq src]# VI Config
core_incs= "$CORE _incs/usr/local/include/fastdfs/usr/local/include/fastcommon/"
Amended to
core_incs= "$CORE _incs/usr/include/fastdfs/usr/include/fastcommon/"

5. Upload current stable version nginx (nginx-1.6.2.tar.gz) to/usr/local/src directory
6. The dependency pack required to install the compile Nginx
[Root@yxq src]# yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib OpenSSL openssl-devel

7. Compile and install Nginx (add Fastdfs-nginx-module module)
[Root@yxq src]# cd/usr/local/src/
[Root@yxq src]# TAR-ZXVF nginx-1.6.2.tar.gz
[Root@yxq src]# CD nginx-1.6.2
[Root@yxq nginx-1.6.2]#./configure--add-module=/usr/local/src/fastdfs-nginx-module/src
[Root@yxq nginx-1.6.2]# make && make install

8, copy the Fastdfs-nginx-module source of the configuration file to the/etc/fdfs directory, and modify
[Root@yxq nginx-1.6.2]# cp/usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs/
Modify the following configuration
connect_timeout=10
Base_path=/tmp
tracker_server=192.168.1.131:22122
storage_server_port=23000
Group_name=group1
Url_have_group_name = True
Store_path0=/fastdfs/storage
9, copy Fastdfs part of the configuration file to the/etc/fdfs directory
[Root@yxq nginx-1.6.2]# cd/usr/local/src/fastdfs/conf
[ROOT@YXQ conf]# CP http.conf mime.types/etc/fdfs/
10, in the/fastdfs/storage file storage directory to create a soft connection, connect it to the actual storage of data directory
[Root@yxq conf]# ln-s/fastdfs/storage/data/fastdfs/storage/data/m00
11. Configure Nginx
Concise version of Nginx configuration examples
ROOT@YXQ conf]# cd/usr/local/nginx/
[Root@yxq nginx-1.6.2]# CD conf
[Root@yxq conf]# ls
fastcgi.conf Koi-utf mime.types scgi_params Win-utf
Fastcgi_params Koi-win nginx.conf Uwsgi_params
[Root@yxq conf]# VI nginx.conf
User root;
Worker_processes 1;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
#keepalive_timeout 0;
Keepalive_timeout 65;
server {
Listen 8888;
server_name localhost;
Location ~/group ([0-9])/m00{
#alias/fastdfs/storage/data;
Ngx_fastdfs_module;
}
#error_page 404/404.html;


Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
}
}
Attention, description
The a.8888 port value is to be relative to the http.server_port=8888 of the/etc/fdfs/storage.conf
Because Http.server_port defaults to 8888, if you want to change to 80, you need to change the corresponding
B.storage corresponds to multiple group, the access path takes a group name, such as/group1/m00/00/xxx,
The corresponding Nginx is configured to
Location ~/group ([0-9])/m00{
Ngx_fastdfs_module;
}
C. If the download is found in the old 404, will nginx.conf the first line of user nobody modified to user root restart
12. Open Nginx 8888 ports in the firewall
[Root@yxq conf]# Vi/etc/sysconfig/iptables
Add to
-A input-m state--state new-m tcp-p TCP--dport 8888-j ACCEPT
[Root@yxq conf]# Cat/etc/sysconfig/iptables | grep 8888
-A input-m state--state new-m tcp-p TCP--dport 8888-j ACCEPT
[ROOT@YXQ conf]# Service iptables restart

13, start Nginx
[Root@yxq conf]#/usr/local/nginx/sbin/nginx
Ngx_http_fastdfs_set pid=15553
(the command to restart Nginx is:/usr/local/nginx/sbin/nginx-s Reload
[Root@yxq conf]#/usr/local/nginx/sbin/nginx-s Reload
Ngx_http_fastdfs_set pid=15557
[Root@yxq conf]# Ps-ef | grep ngx_http_fastdfs_set
Root 15561 11293 0 23:25 pts/0 00:00:00 grep ngx_http_fastdfs_set
[Root@yxq conf]#

14, through the browser to access the test uploaded files


Access to uploaded files


Using Fastdfs in Java code



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.