One, FastDFS installation configuration
1. Download
Package names | download link |
---|---|
fastdfs100-fastdfs-V6.06.zip | https://gitee.com/fastdfs100/fastdfs |
fastdfs100-libfastcommon-V1.0.43.zip | https://gitee.com/fastdfs100/libfastcommon |
fastdfs100-fastdfs-nginx-module-V1.22.zip | https://gitee.com/fastdfs100/fastdfs-nginx-module |
nginx-1.17.7.tar.gz | http://nginx.org/en/download.html |
2. Preparation
- upload files
Upload the installation package to the specified directory of the server, for example, I upload the above files to the /usr/local directory
- unzip files
unzip fastdfs100-libfastcommon-V1.0.43.zip
unzip fastdfs100-fastdfs-V6.06.zip
unzip fastdfs100-fastdfs-nginx-module-V1.22.zip
tar -zxvf nginx-1.17.10.tar.gz
The red box is the unzipped file directory
3. Installation
-
Install gcc
yum install -y gcc gcc-c++
-
Install libfastcommon
cd libfastcommon/
./make.sh #编译
./make.sh install #安装
- Enter the FastDFS directory, compile and install
cd /usr/local/fastdfs
./make.sh
./make.sh install
- Copy the files in the /usr/local/fastdfs/conf directory to the /etc/fdfs directory
cp /usr/local/fastdfs/conf/* /etc/fdfs
4. Tracker and Storage configuration
- Create a directory on the tracker server
cd /usr/local/fastdfs
mkdir -p /mydata/fastdfs/tracker
- Tracker server configuration
vim /etc/fdfs/tracker.conf
Modify the following content:
base_path = /mydata/fastdfs/tracker
This directory is set to the directory created in step 8. This directory will create data and log directories after the service is started, mainly used to store data and log files
- storage server configuration
vim /etc/fdfs/storage.conf
Modify the following content:
base_path = /mydata/fastdfs/storage
store_path0 = /mydata/fastdfs/storage
tracker_server = 192.168.1.107:22122
- Create storage directory
mkdir -p /mydata/fastdfs/storage
- Start tracker and storage
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
- Check whether the startup is successful
ps -ef | grep fdfs
- Tracker starts automatically after booting
vim /etc/rc.d/rc.local
Add the following content
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
- storage starts automatically
vim /etc/rc.d/rc.local
Add the following content
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
5. Test the installation is successful
- Modify client.conf
base_path = /mydata/fastdfs/client
tracker_server = 192.168.1.107:22122
- Create client directory
mkdir -p /mydata/fastdfs/client
Use the fdfs_test command to upload /etc/fdfs/anti-steal.jpg to FastDFS
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg
Picture uploaded successfully! !
6. Installation of nginx
If Nginx is not installed on the server, you need to install Nginx. The specific installation steps are as follows:
- Install components
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
- Add the configuration required by Nginx
cd /usr/local/nginx-1.17.10
./configure \
--prefix=/usr/local/nginx \
--with-http_gzip_static_module \
--with-http_ssl_module
- Compile and install Nginx
make && make install
- Configure Nginx
cd /usr/local/nginx/conf
vim nginx.conf
Modify the following content:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /group1/M00 {
#root html;
#index index.html index.htm;
alias /mydata/fastdfs/storage/data/;
}
}
- Create a temporary directory
mkdir /var/temp/nginx -p
- Start Nginx
/usr/local/nginx/sbin/nginx
Check whether nginx started successfully
ps -ef |grep nginx
- Test whether you can request images in FastDFS through Nginx
7. Installation of fastdfs-nginx-module
- Enter the fastdfs-nginx-module/src directory that has been decompressed
cd /usr/local/fastdfs-nginx-module/src
Modify the config file
vim config
Amended as follows:
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="usr/include/fastdfs /usr/include/fastcommon" #此处为更改后
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS usr/include/fastdfs /usr/include/fastcommon" #此处为更改后
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
- Copy mod_fastdfs.conf
Copy /fastdfs-nginx-module/src/mod_fastdfs.conf to /etc/fdfs
cp mod_fastdfs.conf /etc/fdfs/
- Modify mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
The revised content is as follows:
base_path=/mydata/fastdfs/storage/
store_path0=/mydata/fastdfs/storage/
url_have_group_name = true
tracker_server=192.168.1.107:22122
- Create a temporary directory
mkdir -p /var/temp/nginx/client
- Modify Nginx
cd /usr/local/nginx-1.17.10
./configure \
--prefix=/usr/local/nginx \
--with-http_gzip_static_module \
--with-http_ssl_module \
--add-module=/usr/local/fastdfs-nginx-module/src #新增的配置
- Recompile and install Nginx
make && make install
- Check if the configuration is successful
/usr/local/nginx/sbin/nginx -V
- Modify nginx.conf
vim /usr/local/nginx/conf/nginx.conf
Modify the following content:
server {
listen 8085;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /group1/M00 {
#root html;
#index index.html index.htm;
ngx_fastdfs_module;
}
}
- Restart Nginx
/usr/local/nginx/sbin/nginx -s reload
From the above figure, you can see the console output after restartngx_http_fastdfs_set pid=21166
It shows that the installation of our fastdfs-nginx-module is successful!
8. Consolidate storage
FastDFS provides the realization of the combined storage function. All configurations are configured in the tracker.conf file. The specific configuration is as follows:
use_trunk_file = true
store_server = 1
9. Store thumbnails
Nginx generates thumbnails
image_filter module
Used to convert JPEG, GIF and PNG pictures (compress pictures, crop pictures, rotate pictures, etc.). This picture is not compiled by default, so add relevant configuration information when compiling the nginx source code.
- Check whether the image_filter module has been installed
/usr/local/nginx/sbin/nginx -V
- Install gd, HttpImageFilterModule module needs to rely on the support of gd-devel
yum -y install gd-devel
- Increase the configuration of http_image_filter_module module
cd /usr/local/nginx-1.17.10
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_gzip_static_module \
--with-http_ssl_module \
--add-module=/usr/local/fastdfs-nginx-module/src \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_image_filter_module
make && make install
-
Visit picture:
1) Access ordinary pictures
The path of the image is in a local directory, such as /usr/local/image/abc.jpg, by visiting http://ip:port/image/abc_100x100.jpg
Such a request path can produce small images with a width of 100 and a height of 100, and the width and height can be changed.
The nginx.conf configuration is as follows:
vim /usr/local/nginx/conf/nginx.conf location ~* /image/(.*)_(\d+)x(\d+)\.(jpg|gif|png)$ { root /; set $s $1; set $w $2; set $h $3; set $t $4; image_filter resize $w $h; image_filter_buffer 50M; rewrite ^/image/(.*)$ /usr/local/image/$s.$t break; }
Restart Nginx
/usr/local/nginx/sbin/nginx -s stop /usr/local/nginx/sbin/nginx
Access picture
http://192.168.1.107:8085/image/abc.jpg_100_100
2) Access FastDFS pictures
The nginx.conf configuration is as follows:
#生成缩略图的配置
location ~ group1/M00/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) {
alias /mydata/fastdfs/storage/data/;
ngx_fastdfs_module;
set $w $2;
set $h $3;
if ($w != "0") {
rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
}
if ($h != "0") {
rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
}
image_filter resize $w $h;
image_filter_buffer 30M;
#try_files group1/M00$1.$4 $1.jpg;
}
Access picture
http://192.168.1.107:8085/group1/M00/00/00/wKgBa165gmiAbi-9AABdreSfEnY501.jpg
Nginx Image Thumbnails module
Main function: processing the thumbnail/watermark of the requested picture, supporting text watermark and image watermark.
Support custom font, text size, watermark transparency, watermark position, etc.
-
Determine whether the libcurl-dev libgd2-dev libpcre-dev dependency library has been installed
yum install -y gd-devel prce-devel libcurl-devel
-
Download the nginx image module and unzip it
wget https://github.com/oupula/ngx_image_thumb/archive/master.tar.gz
-
Add nginx image module
cd /usr/local/nginx-1.17.10
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_image_filter_module \
--add-module=/usr/local/fastdfs-nginx-module/src \
--add-module=/usr/local/ngx_image_thumb-master \
make && make install
- The nginx.conf configuration is as follows:
location /group1/M00 {
#root html;
#index index.html index.htm;
alias /mydata/fastdfs/storage/data/;
image on;
image_output on;
image_jpeg_quality 75;
}