yum -y install gcc gcc-c++ perl unzip
tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
tar -zxvf V5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/fdfs_storaged /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim tracker.conf
=========
base_path=/home/fastdfs/tracker
http.server_port=80
========
mkdir -p /home/fastdfs/tracker
service fdfs_trackerd start
netstat -unltp|grep fdfs
cd /etc/fdfs
cp storage.conf.sample storage.conf
vim storage.conf
==========
base_path=/home/fastdfs/storage
#store_path0=/home/fastdfs/file
tracker_server=192.168.25.111:22122
tracker_server=192.168.25.112:22122
tracker_server=192.168.25.113:22122
tracker_server=192.168.25.114:22122
http.server_port=80
========
mkdir -p /home/fastdfs/storage
service fdfs_storaged start
netstat -unltp|grep fdfs
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
cd /etc/fdfs
cp client.conf.sample client.conf
vim client.conf
===========
base_path=/home/fastdfs/client
tracker_server=192.168.25.111:22122
http.tracker_server_port=8081
=========
mkdir /home/fastdfs/client
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf client.conf.sample
安装nginx
vim /usr/local/nginx/conf/nginx.conf
添加如下行,将 /group1/M00 映射到 /home/fastdfs/storage/data
location /group1/M00 {
alias /home/fastdfs/storage/data;
}
# 重启nginx
# /usr/local/nginx/sbin/nginx -s reload
查看是否成功
http://192.168.25.111/group1/M00/00/00/wKj0CF0cTBKAYwBiAABdrZgsqUU227.jpg
springboot操作fastdsf
net.oschina.zcx7878 fastdfs-client-java 1.27.0.0
@RequestMapping(value = "/file/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public String upload(@RequestPart("file") MultipartFile file) { try { FastDFSFile fastdfsfile = new FastDFSFile( file.getOriginalFilename(),//原来的文件名 1234.jpg file.getBytes(),//文件本身的字节数组 StringUtils.getFilenameExtension(file.getOriginalFilename()) ); String[] upload = FastDFSClient.upload(fastdfsfile); return FastDFSClient.getTrackerUrl()+"/"+upload[0]+"/"+upload[1]; } catch (IOException e) { e.printStackTrace(); } return null; }
新增配置文件:
connect_timeout=60 network_timeout=60 #字符编码 charset=UTF-8 # tracker的http通信协议的端口 http.tracker_http_port=80 # 22122 trackerserver的tcp 端口 tracker_server=192.168.25.111:22122
配置好就可以通过springboot上传和下载文件了