一、基本软件环境
- centos 7.6
- gcc gcc-c++ libevent zlib zlib-devel openssl openssl-devel pcre pcre-devel
- libfastcommon-1.0.43.tar,fastdfs-6.06.tar,fastdfs-nginx-module-1.22.tar
- nginx-1.18.0.tar
二、FastDFS安装
2.1 安装基础环境
yum -y install gcc gcc-c++ libevent zlib zlib-devel openssl openssl-devel pcre pcre-devel
2.2 上传安装包
2.3 创建基础目录
mkdir -p /data/imas/base_soft/fdfs/storage
mkdir -p /data/imas/base_soft/fdfs/tracker
mkdir -p /data/imas/base_soft/fdfs/data
mkdir -p /data/imas/base_soft/fdfs/client
2.4 安装libfastcommon (在安装fastdfs前操作)
tar -zxvf libfastcommon-1.0.43.tar.gz -C /data/imas/base_soft/fdfs/
cd /data/imas/base_soft/fdfs/libfastcommon-1.0.43
./make.sh
./make.sh install
2.5 解压和编译安装fastdfs
tar -zxvf fastdfs-6.06.tar.gz -C /data/imas/base_soft/fdfs/
cd /data/imas/base_soft/fdfs/fastdfs-6.06
./make.sh
./make.sh install
2.6 拷贝配置文件
cp fastdfs-6.06/conf/* /etc/fdfs
2.7 编辑tracker 和storage的配置文件
#tracker 配置修改,主要修改地址和数据目录
vim /etc/fdfs/tracker.conf
bind_addr = 192.168.1.x
port = 22122
base_path = /data/imas/base_soft/fdfs/tracker
#storage配置修改,主要修改地址和数据目录
vim /etc/fdfs/storage.conf
bind_addr = 192.168.1.x
group_name = group1
client_bind = true
port = 23000
base_path = /data/imas/base_soft/fdfs/storage
store_path0 = /data/imas/base_soft/fdfs/data
tracker_server = 192.168.1.x:22122 #指定tracker服务器
2.8 安装fastdfs-nginx-module
#解压文件
tar -zxvf fastdfs-nginx-module-1.22.tar.gz -C /data/imas/base_soft/fdfs/
#修改fastdfs地址
vi mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
---------------------------------------
tracker_server=192.168.1.x:22122
url_have_group_name = true
store_path0 = /data/imas/base_soft/fdfs/data
---------------------------------------------------
cp /data/imas/base_soft/fdfs/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
2.9 修改客户端配置
vim /etc/fdfs/client.conf
base_path = /data/imas/base_soft/fdfs/client
tracker_server = 192.168.1.x:22122
2.10 启动服务
#启动storage前必须先启动tarcker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
fdfs_monitor /etc/fdfs/storage.conf 查看状态
三、nginx安装
3.1、上传安装包并解压
//nginx安装
tar -zxvf nginx-1.18.0.tar.gz -C /data/imas/base_soft/
mkdir /data/imas/base_soft/nginx
3.2、编译安装module
./configure \
--prefix=/data/imas/base_soft/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-file-aio \
--http-proxy-temp-path=/data/imas/base_soft/nginx/proxy/ \
--http-fastcgi-temp-path=/data/imas/base_soft/nginx/fcgi/ \
--http-uwsgi-temp-path=/data/imas/base_soft/nginx/uwsgi \
--http-scgi-temp-path=/data/imas/base_soft/nginx/scgi \
--pid-path=/data/imas/base_soft/nginx/nginx.pid \
--lock-path=/data/imas/base_soft/nginx/nginx.lock \
--error-log-path=/data/imas/base_soft/nginx/error.log \
--http-log-path=/data/imas/base_soft/nginx/access.log \
--http-client-body-temp-path=/data/imas/base_soft/nginx/client \
--add-module=/data/imas/base_soft/fdfs/fastdfs-nginx-module-1.22/src
#编译安装
make && make install
3.3、启动nginx
/data/imas/base_soft/nginx/sbin/nginx -t 检查
/data/imas/base_soft/nginx/sbin/nginx 启动
/data/imas/base_soft/nginx/sbin/nginx -s reload 重载
四、上传文件到fastDfs并访问测试
4.1 使用客户端上传本地文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /data/logo2.jpg
4.2 配置nginx文件访问路径
server {
listen 8888;
server_name localhost;
location /group1/M00/{
ngx_fastdfs_module;
}
}
4.2 重启nginx访问文件
curl http://127.0.0.1:8888/group1/M00/00/00/wKgM9WDhWUyAT-6yAAGe4FloxAU923.jpg
4.3 配置80端口访问
location ^~ /fastdfsdomain/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://192.168.12.xx:8888/;
}
【备注】 一般公网访问只会开一个端口,所以要用nginx转发下
curl http://127.0.0.1/fastdfsdomain/group1/M00/00/00/wKgM9WDhWUyAT-6yAAGe4FloxAU923.jpg