快速回顾 FastDFS+Nginx 安装 springboot 完成图片 上传
前前后后安装了几次 主要是 对安装过程回顾并 记录
安装前准备
安装前先 确保 没有干扰
netstat -nltp 查看服务
关闭掉 22122 和23000 两个服务
kill -9 对应的的pid
删除之前的 文件夹
准备 文件
安装FastDFS
第一步 安装 GCC
GCC用来对C语言代码进行编译运行,
1、安装gcc
yum install -y gcc gcc-c++
2、下载libfastcommon到/usr/local下 (这里我直接使用的zip压缩包)
cd /usr/local
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
安装unzip工具
unzip工具可以帮我们对压缩包进行解压
sudo yum install -y unzip zip
3、解压libfastcommon
tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
如果是zip需要安装unzip命令
yum install -y gcc gcc-c++
unzip xxxxx.zip
切换到 libfastcommon-master 目录
cd libfastcommon-master/
4、安装libfastcommon
./make.sh
./make.sh install
5、下载fastdfs (使用网络下载比较慢,我使用的压缩包)
wget https://github.com/happyfish100/fastdfs/archive/V5.08.tar.gz
切换到 /usr/local下
6、解压fastdfs并安装
tar -zxvf V5.08.tar.gz
cd fastdfs-5.08/
./make.sh
./make.sh install
解压完成
切换目录
编译
编译安装
7、将conf目录下的所有文件复制到/etc/fdfs/
cp /usr/local/FastDFS/conf/* /etc/fdfs/
先看 一下 /usr/local/FastDFS/conf 目录下有什么
/etc/fdfs/ 目录有什么
执行复制
查看
8、配置tracker
cd /etc/fdfs
vi tracker.conf
修改前
主要配置
#端口号
port=22122
#基础目录(Tracker运行时会向此目录存储storage的管理数据 ,如果没有需要创建 很重要)
base_path=/usr/local/fastdfs
先查看目录有什么
修改后 其实只要修改 基础目录就好了
如果base_path不存在,则需要创建目录
mkdir /usr/local/fastdfs
创建成功
9、配置storage
cd /etc/fdfs
vi storage.conf
修改前
主要配置
#配置组名
group_name=group1
#端口
port=23000
#向tracker心跳间隔(秒)
heart_beat_interval=30
#基础目录,目录不存在,需要自行创建
base_path=/usr/local/fastdfs
#存放文件的位置,目录不存在,需要自行创建
store_path0=/usr/local/fastdfs/storage
#配置tracker服务器:IP 虚拟机IP或服务器ip!!!!
tracker_server=192.168.31.168:22122
store_path0 的目录 此时还未创建
修改后
记得创建
mkdir /usr/local/fsstdfs/storage
10、启动服务
启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
还是先查看
启动storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
记录 有一个服务没有启动
sudo service fdfs_storaged start # 启动fdfs_storaged服务,停止用stop
查看服务
netstat -ntlp
整合nginx 模块
1、上传fastdfs-nginx-module_v1.16.tar.gz 到/usr/local
2、解压nginx模块
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
3、修改config文件,将文件中的 /usr/local/ 路径改为 /usr/
cd /usr/local/fastdfs-nginx-module/src
vi config
目录结构
修改前
修改后
4、将fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs下
cp mod_fastdfs.conf /etc/fdfs/
复制前
复制后
5、修改/etc/fdfs/mod_fastdfs.conf
vi /etc/fdfs/mod_fastdfs.conf
内容:
base_path=/usr/local/fastdfs
tracker_server=192.168.31.168:22122
#url中包含group名称
url_have_group_name=true
#指定文件存储路径(上面配置的store路径)
store_path0=/usr/local/fastdfs/storage
修改前几个点
修改后
6、将libfdfsclient.so拷贝至/usr/lib下
cp /usr/lib64/libfdfsclient.so /usr/lib/
7、创建nginx/client目录
mkdir -p /var/temp/nginx/client
安装Nginx
!!!!此处版本不一样 不影响安装
1、 将nginx-1.8.0.tar.gz上传到**/usr/local**
2、解压:tar -zxvf nginx-1.8.0.tar.gz
3、安装依赖库 一个一个粘贴
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
4、进入nginx解压的目录下:
cd /usr/local/nginx-1.8.0
5、安装
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src
编译、安装
make
make install
安装成功
6、拷贝配置文件http.conf和mime.types 注意路径
cd /usr/local/fastdfs-xxx/conf
cp http.conf mime.types /etc/fdfs/
可以看 目标路径有什么
覆盖了
7、修改nginx配置文件
cd /usr/local/nginx/conf/
vi nginx.conf
修改前
关闭nginx,并启动nginx
pkill -9 nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
9、启动nginx
访问IP即可
如果出现服务响应过程无响应
查看firewall服务状态 systemctl status firewalld
效果
springboot +postman 快速测试
导入依赖
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.4</version>
</dependency>
启动类上配置
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
配置文件
fdfs.so-timeout=3000
fdfs.connect-timeout=1000
fdfs.thumb-image.height=60
fdfs.thumb-image.width=60
fdfs.tracker-list=192.168.xx.xx:22122
@RestController
@RequestMapping("promotionAd")
public class PromotionAdController {
public static final String DIR = "http://192.168.xx.xx/";
@Autowired
private FastFileStorageClient client;
@PostMapping("/upload")
public ResponseEntity<String> upload(MultipartFile file) throws IOException {
//获得后缀名
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
//上传
StorePath storePath = client.uploadFile(file.getInputStream(), file.getSize(), extension, null);
System.out.println("save:" + storePath.getFullPath());
return ResponseEntity.ok(DIR + storePath.getFullPath());
}
效果
在Linux路径
private FastFileStorageClient client;
@PostMapping("/upload")
public ResponseEntity<String> upload(MultipartFile file) throws IOException {
//获得后缀名
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
//上传
StorePath storePath = client.uploadFile(file.getInputStream(), file.getSize(), extension, null);
System.out.println("save:" + storePath.getFullPath());
return ResponseEntity.ok(DIR + storePath.getFullPath());
}
最后记得保存 快照
如果重启虚拟机 需要重新 启动 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
关闭防火墙 systemctl stop firewalld
## **重启虚拟机后,再次重启nginx报错:nginx: [emerg] open() “/var/run/nginx/nginx.pid” failed (2: No such file or directory)**
这篇文章详细解决
http://t.csdn.cn/K5gZQ