赞
踩
目录
(1)上传资料FastDFS_v5.05.tar.gz到 /usr/local 目录
(2)拷贝安装目录下stop.sh 和restart.sh 到/usr/local/fdfs/
1 安装nginx整合插件fastdfs-nginx-module
(1)上传fastdfs-nginx-module_v1.16.tar.gz上传到 /usr/local,并解压
(2)编辑配置文件:修改config文件将/usr/local/路径改为/usr/
(3)将FastDFS-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下
(5)将libfdfsclient.so拷贝至/usr/lib下
FastDFS是C语言开发,建议在linux上运行,本教程使用Centos7.4作为安装环境。
安装gcc 依赖环境:
yum install gcc-c++ -y
yum -y install libevent
如果没有perl库,需要使用yum install perl* 命令安装一下
yum install perl*
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
上传压缩包文件libfastcommonV1.0.7.tar.gz 到 /usr/local目录下,并解压。
tar -zxvf libfastcommonV1.0.7.tar.gz
./make.sh
如果出现编译perl 不识别 运行下面这段命令
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
./make.sh install
注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。
cp /usr/lib64/libfastcommon.so /usr/lib/
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安装成功之后,将安装目录下的conf下的文件拷贝到/etc/fdfs/下
cd conf
cp * /etc/fdfs/
vi /etc/fdfs/tracker.conf
mkdir /opt/fastdfs
mkdir /usr/local/fdfs
- cp restart.sh /usr/local/fdfs/
-
- cp stop.sh /usr/local/fdfs/
vi /etc/init.d/fdfs_trackerd
把启动脚本中的路径按照上图修改
修改完毕后
chkconfig --add fdfs_trackerd
service fdfs_trackerd start
vi /etc/fdfs/storage.conf
mkdir /opt/fastdfs/fdfs_storage
vi /etc/init.d/fdfs_storaged
chkconfig - -add fdfs_storaged
service fdfs_storaged start
FastDFS安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作。
vi /etc/fdfs/client.conf
/usr/bin/fdfs_test /etc/fdfs/client.conf upload a.jpg
对应的上传路径:
/opt/fastdfs/fdfs_storage/data
/00/00/wKhDo1qipbiAJC6iAAB1tayPlqs094_big.jpg
注意:但是此时是访问不到图片的,需要整合nginx
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
vi fastdfs-nginx-module/src/config
cp mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
继续修改 url中包含group名称
继续修改 #指定文件存储路径
cp /usr/lib64/libfdfsclient.so /usr/lib/
mkdir -p /var/temp/nginx/client
安装pcre库
yum -y install pcre-devel
安装zlib库
yum install -y zlib-devel
A上传nginx压缩包到/usr/local目录下,解压
tar -zxvf nginx-1.12.2.tar.gz
B 添加fastdfs-nginx-module模块
cd nginx-1.12.2
- ./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=/opt/fastdfs-nginx-module/src
配置成功
[root@localhost nginx-1.12.2]# make
[root@localhost nginx-1.12.2]# make install
vim /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
[root@iZ2zednyjjxxq7k3i2dwsfZ nginx-1.12.2]# vim /etc/rc.d/rc.local
service iptables stop
永久关闭:
chkconfig iptables off
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/ty.jpg
显示结果:
https://github.com/happyfish100/fastdfs-client-java
导入maven
<dependency>
<groupId>org.csource</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
</dependency>
- package com.atguigu.gmall.manage.util;
-
- import org.csource.common.MyException;
- import org.csource.fastdfs.ClientGlobal;
- import org.csource.fastdfs.StorageClient;
- import org.csource.fastdfs.TrackerClient;
- import org.csource.fastdfs.TrackerServer;
- import org.springframework.web.multipart.MultipartFile;
-
- import java.io.IOException;
-
- public class PmsUploadUtil {
-
-
- public static String uploadImage(MultipartFile multipartFile) {
-
- String imgUrl = "http://192.168.222.20";
-
- // 上传图片到服务器
- // 配置fdfs的全局链接地址
- String tracker = PmsUploadUtil.class.getResource("/tracker.conf").getPath();// 获得配置文件的路径
-
- try {
- ClientGlobal.init(tracker);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- TrackerClient trackerClient = new TrackerClient();
-
- // 获得一个trackerServer的实例
- TrackerServer trackerServer = null;
- try {
- trackerServer = trackerClient.getConnection();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- // 通过tracker获得一个Storage链接客户端
- StorageClient storageClient = new StorageClient(trackerServer,null);
-
- try {
-
- byte[] bytes = multipartFile.getBytes();// 获得上传的二进制对象
-
- // 获得文件后缀名
- String originalFilename = multipartFile.getOriginalFilename();// a.jpg
- System.out.println(originalFilename);
- int i = originalFilename.lastIndexOf(".");
- String extName = originalFilename.substring(i+1);
-
- String[] uploadInfos = storageClient.upload_file(bytes, extName, null);
-
- for (String uploadInfo : uploadInfos) {
- imgUrl += "/"+uploadInfo;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return imgUrl;
- }
- }
tracker.conf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。