Home  >  Article  >  Backend Development  >  FastDFS+Nginx lightweight distributed file system installation and use

FastDFS+Nginx lightweight distributed file system installation and use

WBOY
WBOYOriginal
2016-08-08 09:21:261076browse

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:
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