Objective:
Previous projects uploaded files are saved to local or LAN within the shared folder, due to the amount of data, Server load balancing (some images of the extension can not access the problem of processing) and other factors, the thought of using Fastdfs to file management, spent a few days to learn how to install configuration, Because the Linux Foundation is not good, installs the configuration to feel a bit laborious, had to go to find some material at any time, fortunately after these several days diligently installs the configuration Fastdfs finally is finished, the final pay and did not waste, the following is the personal opinion, if has the error, please many guidance. Do not know Fastdfs children's shoes can go first to understand, please see http://tech.uc.cn/?p=221
First, Introduction
Fastdfs is an open source lightweight Distributed File system, which manages files, including file storage, file synchronization, file access (file upload, file download), and so on, which solves the problem of large capacity storage and load balancing. Especially suitable for document-based online services, such as photo albums, video sites, etc.
The 1.FASTDFS architecture looks like this:
The FASTDFS server has three roles: a Tracking Service (tracker server), storage servers (storage server), and a client.
- TrackerServer: Tracking servers, mainly to do scheduling work, the role of load balancing. The status information of all storage groups and storage servers in the cluster is recorded in memory, which is the hub for client and data server interaction. Compared to the master in GFs, the file index information is not recorded and the amount of memory used is low.
- StorageServer: Storage server (also known as storage node or data server), file and file attributes (meta data) are saved to the storage server. Storage server manages files directly using the OS's file system calls.
- Client: Clients, as initiators of business requests, use the TCP/IP protocol to interact with the tracker server or storage node using a proprietary interface.
Second , the file upload and download interactive process
Upload mechanism:
Upload process:
Client asksTracker server to upload storage server
1.Client->tracker Server (returns an available storage server, the data returned is the IP address and port of the storage server)
2. Storage Server returns the newly generated file id-> end when the client is connected directly to the Storage server that is returned by the file upload,
The steps for the file download process are as follows:
1. client asks tracker server to download the storage server for the specified file, with the file ID (including group name and file name);
2. Tracker Server returns one of the available storage servers;
3. the client establishes a connection directly to the storage server and completes the file download.
System Environment CENTOR7 64-bit, this article installs only one tracker and storage on the same server
Preparing the installation package
First download the following installation package (see the final section of this article):
Third, the installation process
Since fastdfs5.0.5 relies on libevent, we first install libevent, where Openssl,pcre,zlib is Nginx dependency, because the need to install the software with the Apt-get command, but there is a situation where resources are unavailable or invalid instructions , so the need to manually install these dependencies can be cumbersome, as the following will say, this is the first document to explain, in case some children's shoes are misleading.
The installation steps are as follows:
Login to Linux system, switch user to root user
1. Installing Libevent
Cd/root (corresponds to the directory where the libevent compressed files are stored)
TAR-ZXVF libevent-2.0.22-stable.tar.gz
CD libevent-2.0.22-stable
Make clean
./configure
Make
Make install
Finally, if it is
32-bit Linux:
ln–s/usr/local/libevent/libevent-2.0.so.5/usr/lib/
64-bit Linux:
Ln-s/usr/local/libevent/libevent-2.0.so.5/usr/lib64/
2.FastDFS Installation
TAR-ZXVF fastdfs_v4.06.tar.gz
CD fastdfs_v4.06
./make.sh
./make.sh Install
If you do not have an error, the installation is successful, creating the above soft link installation basic is no problem
2.1: After successful installation, the/etc/fdfs directory will have the relevant configuration file:
Client.conf
Http.conf
Mime.types
Storage.conf
Tracker.conf
To modify a configuration file:
Configure Tracker
Gedit tracker.conf
2.2: Modify these items of the configuration file (modified according to data conditions):
disabled=
false
#启用配置文件
port=22122
#设置tracker的端口号
base_path=
/data/fastdfs/trackerd
#设置tracker的数据文件和日志目录(需预先创建)
http.server_port=18080
#设置http端口号
Start the Trackerd service/usr/local/bin/fdfs_trackerd/etc/fdfs/tracker.conf if required to turn on automatically:
# echo ‘/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart‘ >> /etc/rc.d/rc.local
Check to see if the Trackerd service is started with the following command:
NETSTAT-TUPLN | grep trackerd
You can also look at the log file to see if there is an error (/data/fastdfs/tracker/logs is the path of the previous configuration), if there is no error, you should trackerd the service started.
Configure storage.conf
Gedit storage.conf
disabled=
false
#启用配置文件
group_name=group1
#组名,根据实际情况修改
port=23000
#设置storage的端口号
base_path=
/data/fastdfs/storage
#设置storage的日志目录(需预先创建)
store_path_count=1
#存储路径个数,需要和store_path个数匹配
store_path0=
/data/fastdfs/storage
#存储路径
tracker_server=192.168.188:22122
#tracker服务器的IP地址和端口号
http.server_port=80
#设置http端口号
Start the Trackerd service/usr/local/bin/fdfs_
storage
/etc/fdfs/storage.conf
设置开机启动
# echo ‘/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart‘ >> /etc/rc.d/rc.local
Check to see if the Storaged service is started with the following command:
NETSTAT-TUPLN | grep storaged
You can also view the log file to see if there is an error (/data/fastdfs/storage/logs is the path of the previous configuration), if there is no error, you should storaged the service started
Configuration http.conf in the anti-theft chain, can be configured as needed,:
Http.anti_steal.check_token=true
http.anti_steal.token_ttl=900http.anti_steal.secret_key=fastdfssecretkey001http.anti_steal.token_check_fail=/ Data/fastdfs/img/anti-steal.jpg
Http.anti_steal.check_token: Whether to turn on the anti-theft chain, default to False
Http.anti_steal.token_ttl: The effective duration of the anti-theft chain token
Http.anti_steal.secret_key: Generate token's key
Http.anti_steal.token_check_fail: If it is an anti-theft chain, you need to show the picture path
Configure the client and test the upload
Gedit client.conf
Modify these items of the configuration file (modified according to data conditions):
Base_path=/data/fastdfs/client
tracker_server=192.168.1.188:22122
Then we can do a simple file upload test.
Cd/usr/local/bin
The upload is client.conf, and the successful execution returns the relative path of the corresponding group +m00+ picture (also known as the storage configured path above).
If you need to use a browser to access the picture, you need nginx to do the reverse proxy, direct access is not possible.
Then you need to install and configure Nginx, the beginning of the article said, Openssl,pcre,zlib is nginx dependency, if you can not use the command to install automatic installation, you need to manually install
Install Nginx Dependency (the version used below is for personal use.) No special meaning)
1. Installing Pcre
Get Pcre Compile the installation package and get the current latest version on http://www.pcre.org/
Unzip the pcre-8.31.tar.gz package.
Go to unzip directory and execute./configure.
Execute the make and make install commands in turn
2. Installing OpenSSL
Gets the OpenSSL compilation installation package, which is available on http://www.openssl.org/source/for the current latest version.
Unzip the openssl-1.0.2h.tar.gz package.
Go to unzip directory and execute./config.
Execute the make and make install commands in turn
3. Installing zlib
Gets the zlib compiled installation package, which can get the current latest version on http://www.zlib.net/.
Unzip the zlib-1.2.5.tar.gz package.
Go to unzip directory and execute./configure.
Execute the make and make install commands in turn
4. So far: Nginx's dependency module has been installed, then can be installed Nginx
TAR-ZXVF nginx-1.10.1.tar.gz
CD nginx-1.10.1
./configure--prefix=/usr/local/nginx (--prefix is installed in that directory)
Make
Make install
5. Nginx configuration after installation of Nginx
Cd/usr/local/nginx/conf
Gedit nginx.conf
Add the following configuration to the server node
location/group1/m00{
Root/fastdfs/storage/data;
Ngx_fastdfs_module;
}
This time you listen to the port after the default is 80, before I configure the storage file when the Http.server_port is useful to 80, if you need to change the other ports, according to the circumstances of their own modification
error_page 500 502 503 504
/50x
.html;
location =
/50x
.html {
root
/usr/share/nginx/html
;
}
6. Start Nginx
/usr/local/nginx/sbin/nginx
Use the following command to see if Nginx is started:
NETSTAT-TUPLN | grep nginx
If you succeed, you will see the information of Nginx Monitor.
7. Installing and configuring the Nginx plugin Fastdfs-nginx-module
TAR-ZXVF fastdfs-nginx-module_v1.16.tar.gz
CD fastdfs-nginx-module/src/
Gedit Config (This step is very important, very important, very important (important thing to say three times) I was a few articles dizzy for a few days, resulting in the start of the Nginx module error, if the above to start nginx errors, do not worry first, then install Nginx plug-in, This is configured to recompile again, then restart the nginx OK)
CORE_INCS=
"$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
CORE_LIBS=
"$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
You will then need to add the plug-in to NGINXCD/ROOT/NGINX-1.10.1/./configure--add-module=/root/fastdfs-nginx-module/src/makemake Install 5. Copy and modify the Fastdfs-nginx-module configuration file Cp/root/fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs
Vim Modify/etc/fdfs/mod_fastdfs.conf Save exit
Modify the following:
tracker_server=192.168.1.188:22122
Store_path0=/data/fastdfs/storage
Base_path=/data/fastdfs/storage/data
Url_have_group_name = True (this key should be set to true when multiple tracker are configured)
Establish a soft connection (the path where the data is stored in the configuration file storage)
Ln-s/data/fastdfs/storage/data/data/fastdfs/storage/data/m00
Copy the 2 files under the fastdfs_v4.06 configuration directory to the/etc/fdfs directory:
Cp/usr/local/fastdfs-5.05/conf/http.conf.
Cp/usr/local/fastdfs-5.05/conf/mime.types.
Finally, I will upload the file test again:
Cd/usr/local/bin
uploaded a picture of a test
Then enter your own ip+ port number + file path (IP to bind the corresponding domain name also line)
Look at the results:
This is basically OK.
Welcome to the spray, more welcome constructive comments. We discuss learning together
Installing Fastdfs+nginx+fastdfs-nginx-module installation configuration under the CentOS system