A Brief introduction
Fastdfs is an open-source lightweight Distributed File System , it manages files, including: file storage, file synchronization, file access (file upload, file download), and so on, to solve the problem of large-capacity storage and load balancing. Especially suitable for file-based online services, such as photo album sites, video sites and so on.
The Fastdfs server has two roles: Tracker (tracker) and storage node (storage). The tracker mainly does the dispatching work, and the function of load balancing on the access.
Two-Installation
1, This installation uses three centos5.10 Linux operating systems
192.168.80.100 Tracker Nginx (note that this does not install the fastsfd-niginx plugin )
192.168.80.101 Storage Nginx
192.168.80.102 Storage Nginx
Operating system installation There is not much to say here.
2, prepare the Environment for compilation yum-y Install gcc gcc+ gcc-c++ OpenSSL openssl-devel pcre pcre-devel three machines are installed, and two new users are created Fastdfs and nginx
useradd fastdfs-m-s/sbin/nologin useradd nginx -m-s/sbin/nologin
To facilitate testing, turn off firewall service iptables stop
3, download the source code
Tap cd/usr/local/src/ to 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
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 (three machines are to be installed)
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.1 6 . 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
Installation of 192.168.80.101,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 need to load the module when installing nginx
[root@localhost nginx-1.7.0]# make
[root@localhost nginx-1.7.0]# make install
Three configurations
Configuration of the 192.168.80.100 tracker
1, create tracker data and log storage directory
[Root@localhost ~]# mkdir-p/data/fastdfs/tracker
2. Modify the Fastdfs tracker.conf configuration file
[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
Configure the resolution please refer to my article tracker profile resolution
3, modify the Nginx configuration file
[Root@localhost ~]# vim/usr/local/nginx/conf/nginx.conf
User Nginx nginx; //Here are established users and groups
worker_processes 3 ;
Pid/usr/local/nginx/logs/nginx.pid;
Worker_rlimit_nofile 1024x768 ;
Events {
Use epoll; // epoll is Linux Kernel to handle large quantities File Descriptor and made an improved poll .
worker_connections 1024x768 ;
}
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 : the ; //configuration is storage IP can be equipped with more than one
server 192.168. the . 102 :.
}
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, give tracker to service management and set boot up
[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
Configuring the storage (configured on 192.168.80.101,102 , respectively)
1. Create a data storage directory
[root@localhost ~]# mkdir-p/data/fastdfs/storage /data
2. Modify the Fastdfs storage.conf configuration file
[Root@localhost ~]# vim/etc/fdfs/storage.conf
Group_name=g1
Base_path=/data/fastdfs
# #工作线程数, 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
# #运行fastdfs user Group
Run_by_group=fastdfs
# #运行 users of Fastdfs
Run_by_user=fastdfs
File_distribute_path_mode=1
Rotate_error_log=true
3, copy the nginx module configuration file to /etc/fdfs, 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, modify nginx configuration file
[Root@localhost ~]# vim/usr/local/nginx/conf/nginx.conf
User Nginx nginx;
Worker_processes 8;
Pid/usr/local/nginx/logs/nginx.pid;
Worker_rlimit_nofile 1024x768 ;
Events {
Use Epoll;
worker_connections 1024x768 ;
}
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, turn the 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 start manage and set up boot for service
Creating a soft connection
[Root@localhost ~]# ln-s/data/fastdfs/storage/data/data/fastdfs/storage/data/m00
Four-Test
1, start trackeron 192.168.80.100 ,nginx
[root@localhost ~]# Service Fdfs_trackerd start
[Root@localhost ~]#/usr/local/nginx/sbin/nginx
2, start storage and nginx respectively on 192.168.80.101,102
[root@localhost ~]# Service fdfs_storaged start
[Root@localhost ~]#/usr/local/nginx/sbin/nginx
3 Configuring a client to perform on the 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
Through the 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 the Fastdfs+nginx lightweight Distributed File system installation and use, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.