FastDFS服务器搭建--Ubuntu环境

FastDFS服务器搭建--Ubuntu环境

底下附整合SpringBoot
需要git工具
使用的Ubuntu18环境

安装前准备

安装环境依赖包: apt-get install build-essential

安装依赖库

1. 克隆libfastcommongit clone https://github.com/happyfish100/libfastcommon.git

2. 安装libfastcommon

# 进入项目
cd libfastcommon
# 编译
./make.sh
# 编译
./make.sh install

3. 设置环境变量和软链接

export LD_LIBRARY_PATH=/usr/lib/
ln -s /usr/lib/libfastcommon.so /usr/local/lib/libfastcomo

安装FastFDS

1. 下载: FastDFS的Github下载地址为:https://github.com/happyfish100/fastdfs/releases

自己寻找一个版本下载

# 解压
tar xzf fastfdsxxx.tar.gz

2. 安装:

# 进入项目然后,编译和安装
./make.sh
./make.sh install

3. 配置文件修改:

# 移动到默认安装目录
cd /etc/fdfs

将 client.conf.sample、storage.conf.sample、tracker.conf.sample后的.sample删除

  • 修改 tracker.conf

    vi tracker.conf
    
    base_path=/usr/local/opt/fastDFS/data
    

    要创建目录/usr/local/opt/fastDFS,下面目录都是要创建的

  • 修改storage.conf

    vi storage.conf
    
    # 修改存储路径
    store_path0=/usr/local/opt/fastDFS/store0
    # 修改本地路径
    base_path=/usr/local/opt/fastDFS/data
    # 修改tracker服务器
    tracker_server=本机ip:22122
    
  • 修改client.conf

    vi client.conf
    
    # 修改本地路径
    base_path=/usr/local/opt/fastDFS/data
    # 修改tracker服务器
    tracker_server=本机ip:22122
    

字段需要自己去找,并不是连着摆放的。使用vim命令寻找

  • 复制nginx及其插件需要使用的的配置文件
cp 克隆的fastdfs项目路径/conf/http.conf /etc/fdfs
cp 克隆的fastdfs项目路径/conf/mime.types /etc/fdfs

4. 启动服务

# 启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# 启动storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

5. 验证

ps -ef | grep fdfs
# 显示有fdfs_trackerd和fdfs_storaged则表示成功

测试服务器

准备一张相片test.jpg

/usr/bin/fdfs_test  /etc/fdfs/client.conf  upload test.jpg
# 下面是上传成功打印的内容
This is FastDFS client test program v6.06

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.fastken.com/ 
for more detail.

[2020-01-26 14:51:55] DEBUG - base_path=/usr/local/opt/fastDFS/data, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group: 
        server 1. group_name=, ip_addr=192.168.247.201, port=23000

group_name=group1, ip_addr=192.168.247.201, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKj3yV4tp4uAUBDqAAoJEM-jJhg179.jpg
source ip address: 192.168.247.201
file timestamp=2020-01-26 14:51:55
file size=657680
file crc32=3483575832
example file url: http://192.168.247.201/group1/M00/00/00/wKj3yV4tp4uAUBDqAAoJEM-jJhg179.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKj3yV4tp4uAUBDqAAoJEM-jJhg179_big.jpg
source ip address: 192.168.247.201
file timestamp=2020-01-26 14:51:55
file size=657680
file crc32=3483575832
example file url: http://192.168.247.201/group1/M00/00/00/wKj3yV4tp4uAUBDqAAoJEM-jJhg179_big.jpg

输入图片地址时,无法查看图片。原因是fastDFS没有携带web服务,所以无法响应uri请求,所以这时需要nginx

整个FastDFS和nginx

1. 下载插件源码

fastdfs-nginx-module下载

tar -zxvf fastdfs-nginx-modulexxx.tar.gz

2. 修改配置文件

cp fastdfs-nginx-module项目/src/mod_fastdfs.conf /etc/fdfs/
  • 修改mod_fastdfs.conf

    vim /etc/fdfs/mod_fastdfs.conf
    
    # 修改存储路径
    store_path0=/usr/local/opt/fastDFS/store0
    # 修改本地路径
    base_path=/usr/local/opt/fastDFS/data
    # 修改tracker服务器
    tracker_server=本机ip:22122
    # 允许组名
    url_have_group_name= true
    

安装nginx

1. 安装需要的编译环境

apt-get update
apt-get install libtool
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g-dev
apt-get install openssl

2. 下载nginx

nginx下载

3. 解压和配置文件导入

tar -zxvf nginxxx.tar.gz
# 创建client数据文件
mkdir -p /var/temp/nginx/client
# 导入
cd nginxxx
./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/opt/fastDFS/fastdfs-nginx-module/src

4. 编译与安装

make && make install
# 修改配置文件
vi /usr/local/nginx/conf/nginx.conf

修改nginx.conf

server {
        listen       80;
        server_name  本机ip;

        location /group1/M00/ {
                #root /home/FastDFS/fdfs_storage/data;
                          ngx_fastdfs_module;
        }

5. 验证

cd vi /usr/local/nginx/sbin
# 查看信息   可以看到之前的配置信息
./nginx -V
# 验证
./nginx -t #无错即安装成功
# 启动
./nginx

查看图片

此时浏览器输入uri即可看到之前上传的图片

上传的图片

整合SpringBoot

你可能感兴趣的:(FastDFS服务器搭建--Ubuntu环境)