作者:huishao
联系方式:1943133326@qq.com
最后编辑时间:2022年10月17日13:52:24
前言
因工作需要,在网络上搜集了一番,特意根据一位老哥的教程,实践过后总结一篇文章,简化了些许操作,
由单机版升级为两台机器的小集群,特此记录以备日后还需要搭建此环境。
Fastdfs搭建
搭建前准备
虚拟机环境
操作系统 | IP | 备注 |
---|---|---|
centos7 | 192.168.2.45 | |
centos7 | 192.168.2.239 |
目录准备
创建fastdfs专有目录,所有文件均放在/app/fastdfs目录下
mkdir -p /app/fastdfs_document
cd /app/fastdfs_document
mkdir log #放日志
mkdir data #放数据
fastdfs操作环境搭建
yum -y install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
安装libfastcommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install
安装fastdfs
cd ../
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs/
./make.sh && ./make.sh install
创建nginx使用的文件
cp /app/fastdfs_document/fastdfs/conf/http.conf /etc/fdfs
cp /app/fastdfs_document/fastdfs/conf/mime.types /etc/fdfs
安装fastdfs-nginx-module
cd ..
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
cp /app/fastdfs_document/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
安装nginx
#建立nginx目录
mkdir -p /usr/local/nginx
cd /usr/local/nginx
#下载nginx压缩包
wget http://nginx.org/download/nginx-1.15.4.tar.gz
#解压
tar -zxvf nginx-1.15.4.tar.gz
cd nginx-1.15.4/
#添加fastdfs-nginx-module模块、nginx前缀、https
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/app/fastdfs_document/fastdfs-nginx-module/src/
#--prefix=/usr/local/nginx 这个前缀最好带上,不然不知安装到哪里了
#--with-http_ssl_module 配置ssl证书用(一般用于https的请求),不加也行
#预编译及安装
make && make install
改tracker、storage和client的conf文件
127.0.0.1是本地ip(其实是我瞎写的)(通过ifconfig命令来查看本地ip)
如果需要外网上传文件,需要写外网ip
vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122
base_path=/app/fastdfs_document/data # 数据存储的位置!
vim /etc/fdfs/storage.conf
#需要修改的内容如下
port=23000
base_path=/app/fastdfs_document/data
# 数据和日志文件存储根目录
store_path0=/app/fastdfs_document/data
# 如有多个tracker_server,一并写入即可
tracker_server=127.0.0.1:22122
# http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
http.server_port=8888
vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/app/fastdfs_document/data
#tracker服务器IP和端口 单机版写本地,集群写ip,一般情况下都不会用client,多数用编程语言操作
tracker_server=127.0.0.1:22122
启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
#查看所有运行的端口
netstat -ntp
#netstat 命令用于显示网络状态。
#-n或--numeric 直接使用IP地址,而不通过域名服务器。
#-t或--tcp 显示TCP传输协议的连线状况。
#-p或--programs 显示正在使用Socket的程序识别码和程序名称。
# 然后会发现有一个fdfs_storaged进程和一个fdfs_trackerd进程
测试上传
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/1.png
# 返回以下字符代表正确
group1/M00/00/00/rBTEk2DMUwuAbi0ZAABcfBWCiS0634.png
#查看文件 初始在data目录下,可自己在配置文件中设置
cd /app/fastdfs_document/data/data/00/00
配置nginx
vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server=ip:22122 #tracker服务器IP和端口
# url 地址是否包含组名/卷名
url_have_group_name=true
# 数据组/卷对应的路径地址
store_path0=/app/fastdfs_document/data
#配置nginx.config
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
root /app/fastdfs_document/data/data/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
启动nginx
cd /usr/local/nginx/sbin/
./nginx -s reload
#测试一下,可用Java程序进行配置
Springboot 整合 fastdfs
git clone https://gitee.com/huishao-online-didi/fastdfs-springboot.git