返回

Ubuntu中安装FastDFS

环境准备

使用的系统软件:

名称 说明
libfastcommon FastDFS分离出的公用函数库
libserverframe FastDFS分离出的网络框架
FastDFS FastDFS本体
fastdfs-nginx-module FastDFS和nginx的关联模块
nginx nginx1.15.4

磁盘目录:

说明 位置
所有安装包位置 /usr/local/src
数据存储位置 /home/dfs/

这里为了方便把日志什么的都放到了dfs目录下

  1. 安装编译环境
1
sudo apt-get -y install git gcc g++ make automake autoconf libtool pcre2-utils libpcre2-dev zlib1g zlib1g-dev openssl libssh-dev wget vim
  1. 创建存储目录,切换到安装目录准备下载安装包
1
2
3
sudo mkdir /home/dfs
cd /usr/local/src
sudo chmod -R 777 local/
  1. 安装libfastcommon
1
2
3
4
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
sudo ./make.sh && sudo ./make.sh install #编译安装
cd ../ #返回上一级目录
  1. 安装libserverframe
1
2
3
4
git clone https://github.com/happyfish100/libserverframe.git --depth 1
cd libserverframe/
sudo ./make.sh && sudo ./make.sh install #编译安装
cd ../ #返回上一级目录
  1. 安装FastDFS
1
2
3
4
5
6
7
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
sudo ./make.sh && sudo ./make.sh install #编译安装
#配置文件准备
sudo cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
sudo cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用
cd ../ #返回上一级目录
  1. 安装fastdfs-nginx-module
1
2
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
sudo cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
  1. 安装nginx
1
2
3
4
5
6
wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包
tar -zxvf nginx-1.15.4.tar.gz #解压
cd nginx-1.15.4/
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
make && make install #编译安装

Bug:./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.

解决:

1
2
3
4
sudo apt-get install libpcre3 libpcre3-dev
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
make && make install #编译安装

单机部署

  1. tracker配置
1
sudo gedit /etc/fdfs/tracker.conf

需要修改的内容如下:

1
2
port=22122  # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs  # 存储日志和数据的根目录
  1. storage配置
1
sudo gedit /etc/fdfs/storage.conf

需要修改的内容如下:

1
2
3
4
5
port=23000  # storage服务端口(默认23000,一般不修改)
base_path=/home/dfs  # 数据和日志文件存储根目录
store_path0=/home/dfs  # 第一个存储目录
tracker_server=192.168.169.135:22122  # tracker服务器IP和端口
http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
  1. client配置
1
sudo gedit /etc/fdfs/client.conf

需要修改的内容如下

1
2
base_path=/home/dfs
tracker_server=192.168.169.135:22122    #tracker服务器IP和端口
  1. 启动tracker和storage:
1
2
3
sudo chmod -R 777 dfs/
fdfs_trackerd /etc/fdfs/tracker.conf
fdfs_storaged /etc/fdfs/storage.conf
  1. client测试,返回ID表示成功,如:group1/M00/00/00/xx.tar.gz
1
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz
  1. 配置nginx访问
1
sudo gedit /etc/fdfs/mod_fastdfs.conf

需要修改的内容如下

1
2
3
tracker_server=192.168.169.135:22122  #tracker服务器IP和端口
url_have_group_name=true
store_path0=/home/dfs
  1. 配置nginx.config
1
sudo gedit /usr/local/nginx/conf/nginx.conf

添加如下配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
server {
    listen       8888;    ## 该端口为storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}
  1. 启动nginx:
1
sudo /usr/local/nginx/sbin/nginx
  1. 测试下载,用外部浏览器访问刚才已传过的nginx安装包,引用返回的ID
1
http://192.168.169.135:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
  1. 弹出下载,单机部署全部跑通🎉

Built with Hugo
Theme Stack designed by Jimmy