FastDFS + Nginx lightweight distributed file system installation and use

Source: Internet
Author: User
: This article describes how to install and use a FastDFS + Nginx lightweight distributed file system. For more information about PHP tutorials, see. 1 Introduction

FastDFS is an open-source lightweight distributed file system that manages files, including file storage, file synchronization, and file access (file upload and download, it solves the problems of large-capacity storage and load balancing. It is especially suitable for online services with files as the carrier, such as photo album websites and video websites.

The FastDFS server has two roles: tracker and storage ). The tracker is mainly used for scheduling and serves as a server load balancer for access.

Installation 2

1. this installation uses three centos5.10 linux operating systems

192.168.80.100 tracker Nginx (note that fastsfd-nig133 plug-in is not installed here)

192.168.80.101 storage nginx

192.168.80.102 storage nginx

The installation of the operating system is not mentioned here.

2. prepare the compiling environment yum-y install gcc + gcc-c ++ openssl-devel pcre-devel for installation, and create two new users, fastdfs and nginx.

Useradd fastdfs-M-s/sbin/nologin useradd nginx-M-s/sbin/nologin

Disable the firewall service iptables stop to facilitate testing.

3. download the source code

Press cd/usr/local/src/to enter the directory and run the following command to download fastDFS 5.01.

Wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.01/FastDFS_v5.01.tar.

Download nginx 1.7.0

Wget http://nginx.org/download/nginx-1.7.0.tar.gz

Download fastdfs-nginx-module_v1.16

Wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

4. install FastDFS)

Tar xf FastDFS_v5.01.tar.gz

Cd FastDFS

./Make. sh &./make. sh install

5. unzip fastDFS-nginx-module.

[Root @ localhost ~] # Cd/usr/local/src/

[Root @ localhost src] # tar xf fastdfs-nginx-module_v1.16.tar.gz

6. install Nginx

Installation of the 192.168.80.100 tarcker machine

[Root @ localhost ~] # Cd/usr/local/src/

[Root @ localhost src] # tar xf nginx-1.7.0.tar.gz

[Root @ localhost src] # cd nginx-1.7.0

[Root @ localhost nginx-1.7.0] #./configure -- user = nginx -- group = nginx -- prefix =/usr/local/nginx

[Root @ localhost nginx-1.7.0] # make

[Root @ localhost nginx-1.7.0] # make install

Install 192.168.80.101 and 102 stroage nginx

[Root @ localhost ~] # Cd/usr/local/src/

[Root @ localhost src] # tar xf nginx-1.7.0.tar.gz

[Root @ localhost src] # cd nginx-1.7.0

[Root @ localhost nginx-1.7.0] #./configure -- user = nginx -- group = nginx -- prefix =/usr/local/nginx

-- Add-module = ../fastdfs-nginx-module/src // storage this module needs to be loaded when nginx is installed

[Root @ localhost nginx-1.7.0] # make

[Root @ localhost nginx-1.7.0] # make install

Three configurations

Configuration of 192.168.80.100 tracker

1. create a directory for storing tracker data and logs.

[Root @ localhost ~] # Mkdir-p/data/fastdfs/tracker

2. modify the tracker. conf configuration file of FastDFS.

[Root @ localhost ~] # Vim/etc/fdfs/tracker. conf

Base_path =/data/fastdfs/tracker

Max_c/span>

Work_threads = 8

Store_lookup = 0

Store_path = 0

Reserved_storage_space = 4G //

Run_by_group = fastdfs

Run_by_user = fastdfs

Rotate_error_log = true

For configuration parsing, refer to my article parsing the tracker configuration file

3. modify the Nginx configuration file

[Root @ localhost ~] # Vim/usr/local/nginx/conf/nginx. conf

User nginx; // The Created users and groups are listed here.

Worker_processes 3;

Pid/usr/local/nginx/logs/nginx. pid;

Worker_rlimit_nofile 1024;

Events {

Use epoll; // epoll is the poll improved by the Linux kernel to process large volumes of file descriptors.

Worker_connections 1024;

}

Http {

Include mime. types;

Default_type application/octet-stream;

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

Access_log/usr/local/nginx/logs/access. log main;

Upstream server_g1 {

Server 192.168.80.101: 80; // you can configure multiple storage IP addresses.

Server 192.168.80.102: 80;

}

Server {

Listen 80;

Server_name localhost;

Location/g1 {

Proxy_redirect off;

Proxy_set_header Host $ host;

Proxy_set_header X-Real-IP $ remote_addr;

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

Proxy_pass http: // server_g1;

}

}

}

4. hand over the tracker to the service for management and set boot startup.

[Root @ localhost ~] # Cp/usr/local/src/FastDFS/init. d/fdfs_trackerd/etc/init. d/

[Root @ localhost ~] # Chkconfig -- add fdfs_trackerd

[Root @ localhost ~] # Chkconfig fdfs_trackerd on

Configure storage (configured on 192.168.80.101 and 102 respectively)

1. create a data storage directory

[Root @ localhost ~] # Mkdir-p/data/fastdfs/storage/data

2. modify the storage. conf configuration file of FastDFS.

[Root @ localhost ~] # Vim/etc/fdfs/storage. conf

Group_name = g1

Base_path =/data/fastdfs

# Number of worker threads, usually set to the number of CPUs

Work_threads = 8

Store_path_count = 1

Store_path0 =/data/fastdfs/storage

# Tracker_server address

Tracker_server = 192.168.80.100: 22122

# User group running FastDFS

Run_by_group = fastdfs

# Users running FastDFS

Run_by_user = fastdfs

File_distribute_path_mode = 1

Rotate_error_log = true

3. copy the configuration file of the nginx module to/etc/fdfs for modification.

[Root @ localhost ~] # Cp/usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs/

[Root @ localhost ~] # Vim/etc/fdfs/mod_fastdfs.conf

C/span>

Tracker_server = 192.168.80.100: 22122

Group_name = g1

Url_have_group_name = true

Store_path_count = 1

Store_path0 =/data/fastdfs/storage

4. modify the nginx configuration file

[Root @ localhost ~] # Vim/usr/local/nginx/conf/nginx. conf

User nginx;

Worker_processes 8;

Pid/usr/local/nginx/logs/nginx. pid;

Worker_rlimit_nofile 1024;

Events {

Use epoll;

Worker_connections 1024;

}

Http {

Include mime. types;

Default_type application/octet-stream;

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

Access_log/usr/local/nginx/logs/access. log main;

Server {

Listen 80;

Server_name localhost;

Location/g1/M00 {

Root/data/fastdfs/storage/data;

Ngx_fastdfs_module;

}

}

}

5. submit the storage to [root @ localhost ~] # Cp/usr/local/src/FastDFS/init. d/fdfs_storaged/etc/init. d/

[Root @ localhost ~] # Chkconfig -- add fdfs_storaged

[Root @ localhost ~] # Chkconfig fdfs_storaged on

[Root @ localhost ~] # Service fdfs_storaged start: manage the service and set startup

// Create a soft connection

[Root @ localhost ~] # Ln-s/data/fastdfs/storage/data/M00

4. test

1. start tracker and nginx on 192.168.80.100.

[Root @ localhost ~] # Service fdfs_trackerd start

[Root @ localhost ~] #/Usr/local/nginx/sbin/nginx

2. start storage and nginx on 192.168.80.101 and 102 respectively.

[Root @ localhost ~] # Service fdfs_storaged start

[Root @ localhost ~] #/Usr/local/nginx/sbin/nginx

3. configure a client on tracker.

[Root @ localhost ~] # Vim/etc/fdfs/client. conf

Base_path =/data/fastdfs

Tracker_server = 192.168.80.100: 22122

4. View cluster details

[Root @ localhost ~] # Fdfs_monitor/etc/fdfs/client. conf

5. test Upload

Root @ localhost ~] # Fdfs_upload_file/etc/fdfs/client. conf aa.jpg

G1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJcyojY165.jpg

Use a browser

Http: // 192.168.80.101/g1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJcyojY165.jpg

Http: // 192.168.80.102/g1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJcyojY165.jpg

The above describes how to install and use the FastDFS + Nginx lightweight distributed file system, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.