FastDfs与Nginx整合安装
安装FastDFS
FastDFS_v5.08.tar.gz
libfastcommon-master.zip
-
安装 FastDFS 依赖。FastDFS 是 C 语言开发的应用。安装必须使用 make、cmake 和gcc 编译器。
yum install -y make cmake gcc gcc-c++ perl
-
上传并解压 libfastcommon-master
cd /usr/local/tmp
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
cd /usr/local/tmp
tar zxf FastDFS_v5.08.tar.gz
cd FastDFS
./make.sh
./make.sh install
复制配置文件
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
创建数据目录
mkdir -p /usr/local/fastdfs/tracker
修改配置文件
base_path = /usr/local/fastdfs/tracker
启动服务
service fdfs_trackerd start
复制配置文件
cd /etc/fdfs
cp storage.conf.sample storage.conf
创建目录
mkdir -p /usr/local/fastdfs/storage/base
mkdir -p /usr/local/fastdfs/storage/store
修改配置文件
vim /etc/fdfs/storage.conf
配置内容如下:
base_path=/usr/local/fastdfs/storage/base
store_path0=/usr/local/fastdfs/storage/store
tracker_server=tracker 服务 IP:22122
启动服务
service fdfs_storaged start
安装Nginx
nginx-1.16.1.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
-
上传并安装 fastdfs-nginx-module
cd /usr/local/tmp
tar zxf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src
vim config
修改配置文件中第四行,把路径中 local 去掉(一共有两个 local)。参数是用于配置安装nginx 中的 FastDFS 组件的时候,在什么位置查找 FastDFS 核心代码。
yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
cd /usr/local/tmp
tar zxf nginx-1.16.1.tar.gz
进入到 nginx 文件夹
cd nginx-1.16.1
创建临时目录
mkdir -p /var/temp/nginx
修改配置文件参数
./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 \
--with-http_gzip_static_module \
--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 \
--add-module=/usr/local/tmp/fastdfs-nginx-module/src
make
make install
-
配置 fastdfs-nginx-module 模块配置文件
复制配置文件 fastdfs-nginx-module/src/mod_fastdfs.conf 到/etc/fdfs 目录中
cp /usr/local/tmp/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
进入/etc/fdfs
cd /etc/fdfs
编辑配置文件
vim mod_fastdfs.conf
文件内容修改
修改结果如下:
connect_timeout=10
tracker_server=192.168.server:22122
url_have_group_name = true
store_path0=/usr/local/fastdfs/storage/store
cp /usr/local/tmp/FastDFS/conf/http.conf /etc/fdfs/
cp /usr/local/tmp/FastDFS/conf/mime.types /etc/fdfs/
ln -s /usr/local/fastdfs/storage/store/data/ /usr/local/fastdfs/storage/store/data/M00
进入到安装后 nginx 目录
cd /usr/local/nginx/conf
编辑配置文件
vim nginx.conf
修改内容
user root;
pid /usr/local/nginx/nginx.pid;
server{
listen 8888; # storage 配置中,有 http.server_port=8888 的配置信息,必须一致。配置文件是/etc/fdfs/storaged.conf
server_name localhost;
location ~/group([0-9])/M00{
ngx_fastdfs_module;
}
}
./nginx