FTP的搭建过程,以及遇到的坑

在之前的博客中,我有说到,我最喜欢用Yum在线安装的方式安装软件,简单省事儿。现在看来,也不尽然,关键是,无法快速找到我要的文件,整个whereis 也很累。所以,现在觉得,还是乖乖的整个压缩包,自行安装比较和我心意。


首先,要用到的压缩包列表:



安装步骤概况:

1,安装运行环境包libevent工具包

2,安装libfastcommon工具包

3,安装Tracker服务

4,安装storage服务

5,安装Nginx提供HTTP服务

5.1,需要重新编译Nginx,所以需要处理fastdfs-nginx-module插件(简单)


详细安装步骤:

友情提示:最好是把需要的压缩包聚集到一个目录下,然后解压的时候,在一个自己知道的地方,没什么别的意思或者深意,只是为了自己方便找一些文件,然后操作文件的时候快一点。(你要是写半天的cp或者rm,结果发现写不出目录,就呵 呵影响心情了)



1,安装运行环境包libevent工具包

这一步是极其简单粗暴的,一行命令:yum -y install libevent

2,安装libfastcommon工具包

1, 解压缩:  tar -zxvf  压缩包所在位置

2, ./make.sh

3, ./make.sh install

4, 把/usr/lib64/libfastcommon.so文件向/usr/lib/下复制一份


备注:编译安装的时候,注意一下当前所在文件的位置。  不跟我这个猴子派来的DB学习,当前,我可是在根目录下执行./make.sh,还傻傻闹不懂,为毛不成功

3,安装Tracker服务

1、解压缩
2、./make.sh
3、./make.sh install
安装后在/usr/bin/目录下有以fdfs开头的文件都是编译出来的。
配置文件都放到/etc/fdfs文件夹
4、把/root/FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。
5、配置tracker服务。修改/root/FastDFS/conf/tracker.conf文件。

备注:自己看好自己相应文件所在的位置,Vim tracker.conf
需要修改的内容(也说不上修改,只是和配置文件对应):base_path=/home /yuqing /fastdfs
两个选择:一,将此路径修改为自己指定的路径;二、按照此路径,在相应的位置,建立文件目录。(所以我说,也算不上是修改)

6、启动tracker。/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
重启使用命令:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

4,安装storage服务

1-4,同tracker服务安装过程(如果在同一台机器上安装,则直接进行第5步)
5,配置storage服务。修改/root/FastDFS/conf/storage.conf文件

要修改的地方,有3处:1,base_path=/home/yuqing/fastdfs    2,store_path0=/home/yuqing/fastdfs(这是图片保存路径,必须存在)   3,tracker_server=IP : 22122(指定tracker服务器的ip及端口号,默认的端口为22122)

6,启动storage服务。

/usr/bin/fdfs_storaged/etc/fdfs/storage.confrestart


友情提示:在启动storage服务的时候,时间相对长一点,但不会太长,如果过了好几分钟还没有执行通过,孩子,你该看日志文件了。比如说,我在安装的时候,storage服务一直没有起来,也没有建立相应的数据data文件夹,结果是因为我tracker服务器配置出错。还有防火墙端口的配置出错。  日志文件写得很明白。

7,测试服务:配置文件/etc/fdfs/client.conf,要修改的地方有两处:1,base_path=/home/fastdfs/client(客户端日志保存路径)  2,tracker_server=IP : 22122(tracker服务器地址)

5,安装Nginx提供HTTP服务

备注:Nginx安装过程省略,搞不定的,留言!

1,解压fastdfs-nginx-module插件
2,修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉。


3,重新配置Nginx

./configure

--prefix=/var /nginx

--with-http_gzip_static_module

--http-client-body-temp-path=/var/nginx/client

--http-proxy-temp-path=/var/nginx/proxy

--http-fastcgi-temp-path=/var/nginx/fastcgi

--http-uwsgi-temp-path=/var/nginx/uwsgi

--http-scgi-temp-path=/var/nginx/scgi

--add-module=/usr/local/fastdfs-nginx-module/src


附录:最开始的config配置

./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

注意:上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

4、make

5、makeinstall

6、把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下。编辑四个地方:1,base_path=/tmp(日志存放路径)  2,tracker_server=IP:22122(tracker服务器地址)  3,url_have_group_name=true    4,store_path0=/home/fastdfs/storage (图片保存路径,注意和storage服务配置相对应)

7、配置nginx

在nginx的配置文件中添加一个Server:

server {
        listen       80;
        server_name  192.168.101.3;
 
        location /group1/M00/{
                #root /home/FastDFS/fdfs_storage/data;
                ngx_fastdfs_module;
        }
}

8、将libfdfsclient.so拷贝至/usr/lib下

cp/usr/lib64/libfdfsclient.so /usr/lib/

9、启动nginx


附:使用的基本代码

1,FastDFSClient

package taotao.utils;

import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
/**
 * Created by Angelina on 2017/6/7.
 */
public class FastDFSClient {

    private TrackerClient trackerClient = null;
    private TrackerServer trackerServer = null;
    private StorageServer storageServer = null;
    private StorageClient1 storageClient = null;

    public FastDFSClient(String conf) throws Exception {

        if (conf.contains("classpath:")) {
            String url = this.getClass().getResource("/").getPath();
            url = url.substring(1);
            conf = conf.replace("classpath:", url);
        }
        ClientGlobal.init(conf);
        trackerClient = new TrackerClient();
        trackerServer = trackerClient.getConnection();
        storageServer = null;
        storageClient = new StorageClient1(trackerServer, storageServer);
    }

    public String uploadFile(String fileName, String extName, NameValuePair[] metas) throws Exception {
        return storageClient.upload_file1(fileName, extName, metas);
    }
    public String uploadFile(String fileName, String extName) throws Exception {
        return storageClient.upload_file1(fileName, extName, null);
    }

    public String uploadFile(String fileName) throws Exception {
        return storageClient.upload_file1(fileName, null, null);
    }

    public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas) throws Exception {
        return storageClient.upload_file1(fileContent, extName, metas);
    }

    public String uploadFile(byte[] fileContent, String extName) throws Exception {
        return storageClient.upload_file1(fileContent, extName, null);
    }

    public String uploadFile(byte[] fileContent) throws Exception {
        return storageClient.upload_file1(fileContent, null, null);
    }

}
2,应用实例

    @Value("${IMAGE_SERVER_BASE_URL}")
    private String IMAGE_SERVER_BASE_URL;

    @Override
    public PictureResult uploadPic(MultipartFile picFile){
        PictureResult result=new PictureResult();
        //check the picture
        if (picFile.isEmpty()){
            result.setError(1);
            result.setMessage("the file not found");
            return result;
        }
        //upload the picture to the server
        try{
            //get the file's extension
            String originalFilename=picFile.getOriginalFilename();
            String extName=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
            FastDFSClient client=new FastDFSClient("classpath:properties/client.conf");
            String url=client.uploadFile(picFile.getBytes(),extName);
            //stitching the URL
            url=IMAGE_SERVER_BASE_URL+url;
            result.setError(0);
            result.setUrl(url);
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }



原文地址:https://www.cnblogs.com/hhx626/p/7534593.html