


FastDFS+Nginx lightweight distributed file system installation and use
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
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
trackerConfiguration 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 pollLinuxkernel 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
toservice 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 on192.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 ofFastDFS
[root@localhost ~]# vim /etc/fdfs/storage.conf group_name=g1
base_path=/data/fastdfs
##The number of worker threads, usually set to CPU
numberwork_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 grouprun_by_group =fastdfs
##User runningFastDFS
run_by_user=fastdfsfile_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
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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

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.

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.

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

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.

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.
