(1)FastDFS安装包
(2)获取libfastcommon安装包
(3)获取fastdfs-nginx-module安装包
(4)获取nginx安装包
获取完成最新安装包之后,上传到/opt/software
目录下。
yum -y install gcc-c++ perl
tar -zxvf libfastcommon-1.0.39.tar.gz
cd libfastcommon-1.0.39
./make.sh
./make.sh install
因为 FastDFS 主程序设置的 lib 目录是/usr/local/lib
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11
./make.sh
./make.sh install
我们是采用默认安装的方式安装的,安装完成对应的文件和目录如下:
服务脚本:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker
配置文件:
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/storage_ids.conf.sample
/etc/fdfs/tracker.conf.sample
复制tracker.conf.sample
并重命名为tracker.conf
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vi /etc/fdfs/tracker.conf
改动信息
disabled=false #默认为false 此处不修改 不启用=false就是启用。
port=22122 #跟踪器端口号,默认为22122
base_path=/home/fastdfs #目录地址 依实际挂载的数据盘自行设置,根目录必须存在,子目录会自动创建
创建基础数据目录(base_path对应的路径)
mkdir -p /home/fastdfs
启动tracker
/etc/init.d/fdfs_trackerd start
ps -ef | grep fdfs
/etc/init.d/fdfs_trackerd stop
vi /etc/rc.d/rc.local
## FastDFS Tracker
/etc/init.d/fdfs_trackerd start
chmod +x /etc/rc.d/rc.local
复制storage.conf.sample并重命名为storage.conf
cd /etc/fdfs/
cp storage.conf.sample storage.conf
vi /etc/fdfs/storage.conf
改动点
disabled=false #默认为false 此处不修改 不启用=false就是启用
port=23000 #存储器端口号,默认为23000
base_path=/home/fastdfs/storage #目录地址 依实际挂载的数据盘自行设置,根目录必须存在,子目录会自动创建
store_path0=/home/fastdfs/storage
#存放文件时storage server支持多个路径,如果不配置base_path0,那边它就和base_path对应的路径一样
tracker_server=172.30.0.4:22122 # tracker_server 的列表
http.server_port=8888 # HTTP服务端口 默认为8888
mkdir -p /fastdfs/storage
启动storaged
/etc/init.d/fdfs_storaged start
/etc/init.d/fdfs_storaged stop
vi /etc/rc.d/rc.local
## FastDFS Storaged
/etc/init.d/fdfs_storaged start
测试文件上传
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf
改动
base_path=/home/fastdfs/tracker
tracker_server=172.30.0.4:22122
测试
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/software/jdk-8u221-linux-x64.tar.gz
结果
group1/M00/00/00/rB4ABF1vceOAAnmpC6Do1RH_edA.tar.gz
(1)已经安装过Nginx,动态添加模块
查看已经安装的模块
首先解压后要修改fastdfs-nginx-module-1.20/src/config
cd /opt/software/
tar -zxvf fastdfs-nginx-module-1.20.tar.gz
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
再编译
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/software/fastdfs-nginx-module-1.20/src
make
注意不要make install了
cd /usr/local/nginx/sbin/
mv nginx nginx.bak
cp /opt/software/nginx-1.16.1/objs/nginx /usr/local/nginx/sbin/
cd /opt/software/
tar -zxvf fastdfs-nginx-module-1.20.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/software/fastdfs-nginx-module-1.20/src
make
make install
复制 fastdfs-nginx-module
源码中的配置文件到/etc/fdfs
目录
connect_timeout=10
base_path=/tmp
tracker_server=172.30.0.4:22122 #tracker跟踪器地址
storage_server_port=23000 #storage存储器的端口
group_name=group1 #组名
url_have_group_name = true #url hava group name 顾名思义 默认为false 改为true
store_path0=/home/fastdfs/storage #存储器存储地址
其他操作
cd /opt/software/fastdfs-5.11/conf
cp http.conf mime.types /etc/fdfs/
ln -s /home/fastdfs/storage/data/ /home/fastdfs/storage/data/M00
添加nginx配置文件 listen 80
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
验证
访问:http://xxx/group1/M00/00/00/rB4ABF1vceOAAnmpC6Do1RH_edA.tar.gz
1.26.7
com.github.tobato
fastdfs-client
${fastdfs.version}
fdfs:
soTimeout: 1500
connectTimeout: 600
trackerList: 172.30.0.4:22122
@Autowired
private FastFileStorageClient storageClient;
/**
* 文件上传
*
* @param file
* @return
* @throws IOException
*/
public String uploadFile(MultipartFile file) throws IOException {
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null);
return storePath.getFullPath();
}
@Autowired
private FastDFSClientWrapper dfsClient;
// 上传文件
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String upload(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws Exception {
return dfsClient.uploadFile(file);
}