In this document, all ~~~ are the same user-defined folder name. Generally, the project name is used
2.1. Why Nginx access?
FastDFS uses the Tracker server to store files on the Storage server. However, file replication is required between Storage servers in the same group, resulting in synchronization delay.
Suppose the Tracker server uploads the file to 192.168.4.125, and the file ID is returned to the client. In this case, the FastDFS storage cluster mechanism synchronizes the file to the same storage group 192.168.4.126. If a client uses this file ID to fetch files from 192.168.4.126 before the file replication is complete, the file cannot be accessed.
Fastdfs-nginx-module redirects the file connection to the source server where the file is uploaded, avoiding the file failure caused by the replication delay
2.2. Installation fastdfs – nginx – module
2.2.1. Unpack
The tar - ZXVF fastdfs - nginx - module_v1. 16. The tar. GzCopy the code
2.2.2. Modify the config
1) Go to the SRC directory
cd fastdfs-nginx-module/src/Copy the code
2) Edit config
vim configCopy the code
Use the following bottom line command:
:%s+/usr/local/+/usr/+gCopy the code
Replace all /usr/local with /usr, which is the correct directory:
2.2.3. Configure the FastDFS profile associated with nginx
Copy the fastdfs-nginx-module configuration file to /etc/fdfs and modify it
cp /usr/local/leyou/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.confCopy the code
Modify the following configuration:
connect_timeout=10 Client access file connection timeout duration (unit: seconds)Tracker_server = 192.168.56.101:22122# tracker service IP address and port. The IP address is the TRACKER service IP address of the vm. The port number is the default fastdFS port number
url_have_group_name=true Access links are prefixed with the group nameStore_path0 =/ User-defined file path (indicated by ~~~ later) /storage# File storage pathCopy the code
Copy part of the FastDFS configuration file to the /etc/fdfs directory
cd /usr/local/~~~/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/Copy the code
2.3. Install the Nginx plug-in
2.3.1. If nginx has not been installed
-
Install nginx dependency libraries
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-develCopy the code
-
Decompress the installation package
The tar - ZXVF nginx - 1.10.0. Tar. GzCopy the code
-
Configure the nginx installation package and specify fastdfs-nginx-model
cd/configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/~~~/fastdfs-nginx-module/srcCopy the code
Note: in the execution. / configure nginx configuration parameters, you need to fastdfs nginx – moudle source as modules compiled in.
-
Compile and install
make && make installCopy the code
2.3.2. If nginx has been installed
1) Enter nginx directory:
cd /usr/local/ ~ ~ ~ / nginx 1.10.0 /Copy the code
2) Configure the FastDFS module
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/~~~/fastdfs-nginx-module/srcCopy the code
Note: In this configuration, add the Fastdfs-nginx-moudle module
3) Compile, do not install this time
makeCopy the code
4) Replace nginx binaries:
Backup:
mv /usr/bin/nginx /usr/bin/nginx-bakCopy the code
Use the newly compiled nginx startup file instead of the original:
cp objs/nginx /usr/bin/Copy the code
2.3.3. Start nginx
Configure nginx to integrate the Fastdfs-module module
We need to modify nginx configuration file in/opt/nginx/config/nginx. Conf file:
vim /opt/nginx/conf/nginx.confCopy the code
Put files in the original server 80{… } part of the code is replaced with the following code:
Nginx start:
nginx # start nginx
nginx -s stop # stop nginx
nginx -s reload Reload the configuration fileCopy the code
# by ps – ef | grep nginx see if nginx has started successfully
Above is the master process and below is the worker process. If there is only one process optional configuration problem, the number of working processes in the plotter configuration, but generally for the number of CPU cores
2.3.4. Set nginx to boot upon startup
Create a startup script:
vim /etc/init.d/nginxCopy the code
Add the following:
Modify the file permission and add the file to the service list
# change permissionCopy the code
chmod 777 /etc/init.d/nginx Copy the code
Add to the list of servicesCopy the code
chkconfig --add /etc/init.d/nginx Copy the code
Copy the code
Setting boot
chkconfig nginx onCopy the code