centos7 安装fastdfs 以及配置nginx模块
安装:
cd /usr/local/
下载软件:
git clone https://github.com/happyfish100/fastdfs.git
git clone https://github.com/happyfish100/libfastcommon.git
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
编译安装libfastcommon
cd libfastcommon/
./make.sh && ./make.sh install
编译安装fastdfs
cd fastdfs
./make.sh && ./make.sh install
复制配置文件到/etc/fdfs下
cd /etc/fdfs/
cp /usr/local/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/fastdfs/conf/mime.types /etc/fdfs/
cp usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
创建数据、日志存放目录:
mkdir -p /home/fdfs/tracker
mkdir -p /home/fdfs/storage
mkdir -p /home/fdfs/client
配置tracker:
vim tracker.conf
base_path = /home/fdfs/tracker
http.server_port = 8080(不用修改需注意端口占用问题)
配置storage:
vim storage.conf
base_path = /home/fdfs/tracker
store_path0 = /home/fdfs/storage
tracker_server = {{ip}}:22122
http.server_port = 8888(对应nginx的端口配置)
配置client:
vim client.conf
base_path = /home/fdfs/client
tracker_server = {{ip}}:22122
启动tracker和storage
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
设置软连接:
ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/include/fastdfs /usr/local/include/fastdfs
ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/local/fastdfs/storage/data/ /usr/local/fastdfs/storage/data/M00
配置fastdfs-nginx-module:
vim /usr/local/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/local/include/fastcommon/”
nginx添加fastdfs-nginx-module模块(已经安装过nginx并在使用,新增模块):
先查询之前的nginx:
cd /usr/local/nginx
./sbin/nginx -V
--prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
添加fastdfs-nginx-module模块,并重新编译nginx,进入nginx源文件:
cd nginx-1.18.0/
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/usr/local/fastdfs-nginx-module/src
make(只make,不要安装!!!!!)
将生成的nginx文件拷贝到nginx/sbin下,防止出现问题,建议先备份原nginx文件
cp objs/nginx /usr/local/nginx/sbin/nginx
cd /usr/local/nginx
配置fastdfs-nginx-module模块的访问,端口同storage.conf里面要一致
vim conf/nginx.conf
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
./sbin/nginx -s reload
需要修改fastdfs-nginx-module的配置文件:
cd /etc/fdfs
vim mod_fastdfs.conf
base_path=/home/fdfs/tracker
tracker_server={{ip}}:22122(不修改nginx会报错:ERROR - file: ../tracker/fdfs_shared_func.c, line: 474, host "tracker" is invalid, error info: Unknown host)
url_have_group_name = true
使用client测试上传文件,得到如下图内容:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/nginx/conf/nginx.conf
example file url: http:/{{ip}}:8888/group1/M00/00/00/J2iAYGE17-aAEvFoAAAKcYwkqzI87_big.conf
取当前链接在浏览器中访问能够成功下载。