Home Backend Development PHP Tutorial FastDFS+Nginx lightweight distributed file system installation and use

FastDFS+Nginx lightweight distributed file system installation and use

Aug 08, 2016 am 09:21 AM
fastdfs nbsp nginx storage

1 Introduction

FastDFS is an open source lightweight distributed file system. It manages files. Its functions include: file storage, file synchronization, file access (file upload, file download) ), etc., solve the problems of large-capacity storage and load balancing. It is especially suitable for online services based on files, such as photo album websites, video websites, etc.

FastDFSThe server has two roles: tracker (tracker) and storage node (storage). The tracker mainly does scheduling work and plays a load balancing role in access.

Second installation

1, This installation uses three centos5.10 linux operating system

192.168.80.100 tracker Nginx ( Note that this machine does not install fastsfd-niginx Plug-in)

192.168.80.101 storage nginx

192.168.80.102 storage nginx

The installation of the operating system will not be discussed here.

2, Prepare the compilation environment yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-devel Install all three machines, and create two new users fastdfs and nginx

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

For the convenience of testing, please turn off the firewall service iptables stop

3, download the source code

type cd /usr/local/src/ Enter the directory, run the following command, 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

Downloadfastdfs-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 (must be installed on all three machines)

tar

5, unzip

fastDFS-nginx-module

[root@localhost ~]# cd /usr/local/src/

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

.tar.gz

6, InstallationNginx192.168.80.100 tarcker Machine installation

[root@localhost ~] # cd /usr/local /src/

[root@localhost src]# tar [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 install192.168.8 0.101,102 stroage nginx Installation

[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 When installing nginx This module needs to be loaded[root@localhost nginx-1.7.0]# make

[root@localhost nginx-1.7.0]# make install

Three configurations

192.168.80.100 tracker configuration

1, create trackerdata and log storage directory

[root@localhost ~]# mkdir -p /data/fastdfs/tracker

2 , modify FastDFS’s tracker.conf configuration file

[root@localhost ~]# vim /etc/fdfs/tracker.conf

base_path=/data/fastdfs/tracker

max_c /span> kWork_thReads = 8

Store_Lookup = 0

Store_path = 0

ReserVED_SPACE_SPACE = 4g

//Run_by_group = Fastdfsrun_BY_USTER = FASTDFS

rotate_error_log=true

For configuration analysis, please refer to my article

tracker

Configuration file analysis

3, modify the configuration file of Nginx

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.confuser

nginx

nginx;//Here are the already established users and groups worker_processes 3;

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

1024;

events {use epoll;

// epoll

is the poll

Linuxkernel improved for handling large batches of file descriptorsworker_connections 1024 ;

} http {

include mime.types;

default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$re quest" '

'$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; //What is configured here is the IP of storagecan be configured with multiple units 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

proxy_pass http://server_g1;

}

}

}

4, hand over tracker

to

service management and set up 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

(Configure on

192.168.80.101,102 respectively)

1, Create the 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

##The number of worker threads, usually set to CPU

number

work_threads=8

store_ path_count=1

The address of store_path0=/data/fastdfs/storage

##tracker_server=192.168.

80.100

:22122

##Run FastDFS

’s user group

run_by_group =fastdfs

##User 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 and modify it

[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, modified nginx Configuration file

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

user nginxnginx;

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/stor age/data;

ngx_fastdfs_module;

}

}

}

5, hand over storage [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 startManage and set up startup for service

//Create a soft connection

[root@localhost ~]# ln -s /data/fastdfs/storage/ data /data/fastdfs/storage/data/M00

Four tests

1, start tracker, nginx on 192.168.80.100

[root@localhost ~]# service fdfs_trackerd start

[root@localhost ~]# /usr/local/nginx/sbin/nginx

2, start storage and ng respectively on 192.168.80.101,102 inx

[root@localhost ~]# service fdfs_storaged start

[root@localhost ~]# /usr/local/nginx/sbin/nginx

3 Configure a client in tracker Go to

[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

via browser

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

http://192.168.80.102/g1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJ cyojY165.jpg

The above introduces the installation and use of FastDFS+Nginx lightweight distributed file system, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What's wrong with nginx running for a while? What's wrong with nginx running for a while? Apr 14, 2025 am 07:18 AM

The reasons why nginx hangs up after running for a period of time: 1. Memory leak; 2. Configuration error; 3. Insufficient resources; 4. External factors. Solution: 1. Diagnose memory leaks; 2. Fix configuration errors; 3. Provide more resources; 4. Exclude external factors.

How to implement nginx load balancing How to implement nginx load balancing Apr 14, 2025 am 07:21 AM

Nginx load balancing defines backend servers through the upstream module and uses the location block to proxy the request to these servers. Supports load balancing strategies such as polling, minimum number of connections, response time weighting, and ip_hash. Configuration examples include defining an upstream group and pointing to it using the proxy_pass directive.

nginx restart command nginx restart command Apr 14, 2025 am 07:27 AM

nginx restart command: sudo systemctl restart nginx. Other related commands include: 1. Start: sudo systemctl start nginx; 2. Stop: sudo systemctl stop nginx; 3. Check status: sudo systemctl status nginx.

Apr 14, 2025 am 07:36 AM

Nginx Autoindex is a function of generating directory listing HTML pages, which is used to browse files and view file information when requesting directories instead of files. It can be customized with configuration options such as displaying the exact file size, local time, and custom page format. Advantages include easy browsing, easy configuration and providing file information. Disadvantages include security risks, performance impact, and the inability to customize the appearance of the page.

What is the reason for nginx403 What is the reason for nginx403 Apr 14, 2025 am 07:39 AM

nginx 403 error indicates that the client does not have permission to access the resource. Factors that cause this problem may include: permission settings, nginx configuration, CGI script errors, .htaccess files, or other reasons. Troubleshooting steps include: checking permission settings, reviewing nginx configuration, testing CGI scripts, checking .htaccess files, excluding firewalls or security software, and checking servers and file systems.

How to configure virtual hosts in nginx How to configure virtual hosts in nginx Apr 14, 2025 am 08:15 AM

Configuring nginx virtual host allows multiple websites to be hosted on a single server, each with a separate domain name and root directory. The specific configuration steps include: creating a virtual host configuration file to configure the server block, specifying the server listening port, virtual host domain name and document root directory to enable the virtual host, and linking the configuration file to the enabled directory to reload nginx

The relationship between nginx and web server The relationship between nginx and web server Apr 14, 2025 am 07:09 AM

nginx is a lightweight, non-blocking web server and reverse proxy, commonly used for front-end proxy, load balancing, and caching. Its relationship with a web server is usually: Front-end proxy: nginx handles requests and forwards them to the back-end server. Load Balancer: nginx distributes requests to multiple backend servers. Caching: nginx caches frequently accessed files for performance.

How to redirect in nginx How to redirect in nginx Apr 14, 2025 am 08:42 AM

Methods for redirecting through Nginx are 301 permanent redirects (update links or mobile pages) and 302 temporary redirects (handling errors or temporary changes). Configuring redirection involves using location directives in server blocks, advanced features include regular expression matching, proxy redirection, and condition-based redirection. Common uses of redirects include updating URLs, handling errors, redirecting HTTP to HTTPS, and guiding users to a specific country or language version.

See all articles