环境准备
使用的系统软件:
名称 | 说明 |
---|---|
libfastcommon | FastDFS分离出的公用函数库 |
libserverframe | FastDFS分离出的网络框架 |
FastDFS | FastDFS本体 |
fastdfs-nginx-module | FastDFS和nginx的关联模块 |
nginx | nginx1.15.4 |
磁盘目录:
说明 | 位置 |
---|---|
所有安装包位置 | /usr/local/src |
数据存储位置 | /home/dfs/ |
这里为了方便把日志什么的都放到了dfs目录下
- 安装编译环境
sudo apt-get -y install git gcc g++ make automake autoconf libtool pcre2-utils libpcre2-dev zlib1g zlib1g-dev openssl libssh-dev wget vim
- 创建存储目录,切换到安装目录准备下载安装包
sudo mkdir /home/dfs
cd /usr/local/src
sudo chmod -R 777 local/
- 安装libfastcommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
sudo ./make.sh && sudo ./make.sh install #编译安装
cd ../ #返回上一级目录
- 安装libserverframe
git clone https://github.com/happyfish100/libserverframe.git --depth 1
cd libserverframe/
sudo ./make.sh && sudo ./make.sh install #编译安装
cd ../ #返回上一级目录
- 安装FastDFS
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 ../ #返回上一级目录
- 安装fastdfs-nginx-module
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
- 安装nginx
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.
解决:
sudo apt-get install libpcre3 libpcre3-dev
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install #编译安装
单机部署
- tracker配置
sudo gedit /etc/fdfs/tracker.conf
需要修改的内容如下:
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs # 存储日志和数据的根目录
- storage配置
sudo gedit /etc/fdfs/storage.conf
需要修改的内容如下:
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中保持一致)
- client配置
sudo gedit /etc/fdfs/client.conf
需要修改的内容如下
base_path=/home/dfs
tracker_server=192.168.169.135:22122 #tracker服务器IP和端口
- 启动tracker和storage:
sudo chmod -R 777 dfs/
fdfs_trackerd /etc/fdfs/tracker.conf
fdfs_storaged /etc/fdfs/storage.conf
- client测试,返回ID表示成功,如:
group1/M00/00/00/xx.tar.gz
:
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz
- 配置nginx访问
sudo gedit /etc/fdfs/mod_fastdfs.conf
需要修改的内容如下
tracker_server=192.168.169.135:22122 #tracker服务器IP和端口
url_have_group_name=true
store_path0=/home/dfs
- 配置
nginx.config
sudo gedit /usr/local/nginx/conf/nginx.conf
添加如下配置:
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;
}
}
- 启动nginx:
sudo /usr/local/nginx/sbin/nginx
- 测试下载,用外部浏览器访问刚才已传过的nginx安装包,引用返回的ID
http://192.168.169.135:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
- 弹出下载,单机部署全部跑通🎉