FSATDFS分布式文件系统安装

FSATDFS分布式文件系统安装

环境:vm虚拟机+ubuntu18.4桌面版

安装准备

FSATDFS分布式文件系统安装_第1张图片

下面四个安装包自己下载好并房在lunix系统的某一文件夹里

比如我就放在 了 ~/桌面/fastdfs

1. c语言编译环境安装

  sudo apt-get install build-essential
  sudo apt-get install libevent-dev

2. 解压libfastcommon

将 libfastcommon 复制到 /usr/local

运行

cd /usr/local/libfastcommon
make && make install

3. 解压fastdfs

进入fastdfs解压路径

运行

make && make install
cd conf/
cp ./* /etc/fdfs
cd /etc/fdfs

4. 配置tracker.conf

# the tracker server port
port = 22122


# the base path to store data and log files
base_path = /home/kotori/fastdfs
# base_path这里的配置需要lunix上存在这个路径的文件夹
group_name = group1


运行 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start 启动tracker

5. 配置storage.conf

group_name = group1

port = 23000

base_path = /home/kotori/fastdfs

store_path0 = /home/kotori/fastdfs
#虚拟机网络地址
tracker_server = 192.168.244.128:22122


运行 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start 启动tracker

6. 测试上传

新建springboot项目

编写fastdfs-client.properties文件

fastdfs-client.properties:

## fastdfs-client.properties

fastdfs.connect_timeout_in_seconds = 5
fastdfs.network_timeout_in_seconds = 30

fastdfs.charset = UTF-8

fastdfs.http_anti_steal_token = false
fastdfs.http_secret_key = FastDFS1234567890
fastdfs.http_tracker_http_port = 80

fastdfs.tracker_servers = 192.168.244.128:22122

## Whether to open the connection pool, if not, create a new connection every time
fastdfs.connection_pool.enabled = true

## max_count_per_entry: max connection count per host:port , 0 is not limit
fastdfs.connection_pool.max_count_per_entry = 500

## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600
fastdfs.connection_pool.max_idle_time = 3600

## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000
fastdfs.connection_pool.max_wait_time_in_ms = 1000

编写测试类

package com.example.fastdfs;

        import org.csource.common.MyException;
        import org.csource.common.NameValuePair;
        import org.csource.fastdfs.*;
        import org.junit.jupiter.api.Test;
        import org.springframework.boot.test.context.SpringBootTest;

        import java.io.IOException;

@SpringBootTest
class FastdfsApplicationTests {
     

    @Test
    void contextLoads() throws IOException, MyException {
     
        ClientGlobal.initByProperties("fastdfs-client.properties");
        TrackerClient trackerClient = new TrackerClient();
        TrackerServer trackerServer = trackerClient.getConnection();
        StorageServer storageServer = null;
        StorageClient1 client1 = new StorageClient1(trackerServer,storageServer);
        NameValuePair nameValuePair[] = null;

        String flieId = client1.upload_file1("H:\\一见倾心一周年精选电脑壁纸(500+张)\\03-11.jpg", "jpg", nameValuePair);
        System.out.println(flieId);
    }

}

FSATDFS分布式文件系统安装_第2张图片

得到文件id

group1/M00/00/00/wKj0gF5t28uAYd9FAAv8YwAwjN4461.jpg

这时访问 http://192.168.244.128/group1/M00/00/00/wKj0gF5t28uAYd9FAAv8YwAwjN4461.jpg

是访问不到的,因为fastdfs本身不具有浏览功能

需要nginx与fastdfs整合

7. 整合nginx

7.1 安装fastdfs-nginx-module

解压fastdfs-nginx-module并复制到 /usr/local

运行

cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
cd /etc/fdfs
vim mod_fastdfs.conf

修改四个地方

# 虚拟机地址
tracker_server=192.168.244.128:22122
group_name=group1
url_have_group_name = true
store_path0=/home/kotori/fastdfs

7.2 安装nginx

解压nginx并进入解压目录

运行

./configure --add-module=/usr/local/fastdfs-nginx-module/src
make && make install

修改nginx配置

cd /usr/local/nginx/conf
vim nginx.conf

将server结点下原来的有的

location / {
	
}

替换成

  location ~/group([0-9]) {
  # 下面一行可以不要
            root   /home/kotori/fastdfs/data;
            ngx_fastdfs_module;
        }

运行

 ../sbin/nginx

8.检测nginx

访问 http://192.168.244.128/group1/M00/00/00/wKj0gF5t28uAYd9FAAv8YwAwjN4461.jpg

你可能感兴趣的:(fastdfs)