Fastdfs Nginx 配置
创建文件夹fastdfsall
进入文件夹下载以下文件
- 下载fastdfs5.11
git clone https://github.com/happyfish100/fastdfs.git
- 下载fastdf-client-java
git clone https://github.com/happyfish100/fastdfs-client-java.git
- 下载fastdfs-nginx-module version1.20
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
- 下载libfastcommon
git clone https://github.com/happyfish100/libfastcommon.git
- 下载Nginx 1.15.0
https://github.com/nginx/nginx/tree/release-1.15.0
安装FastDFS依赖包
cd libfastcommon
./make.sh
sudo ./make.sh install
安装Fastdfs
cd fastdfs
./make.sh
sudo ./make.sh install
配置FastDfs
配置tracker
复制tracker.conf.sample
sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
在/home/light(对应主机用户名)创建目录fastdfs/tracker
配置对应的tracker.conf
sudo gedit /etc/fdfs/tracker.conf
修改如下内容
base_path=/home/light/fastdfs/tracker
配置存储storage
复制storage.conf.sample
sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
在/home/light(对应主机用户名)创建目录fastdfs/storage
编辑/etc/fdfs/storage.conf配置文件
sudo gedit /etc/fdfs/storage.conf
修改如下内容:
base_path=/home/light/fastdfs/storage
store_path0=/home/light/fastdfs/storage
tracker_server=自己服务器ip:22122
启动tracker和storage
使用如下的命令来启动:
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
查看是否启动成功:
ps aux|grep dfs
看到有如下的记录被查找到则启动成功:
root 3437 0.0 0.0 147796 2372 ? Sl 8月24 0:48 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root 3447 0.0 0.0 150264 3832 ? Sl 8月24 0:56 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
上传文件测试
复制 client.conf.sample
sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
编辑/etc/fdfs/client.conf配置文件
sudo gedit /etc/fdfs/client.conf
修改内容如下:
base_path=/home/light/fastdfs/tracker
tracker_server=自己服务器ip:22122
上传测试图片:(任意图片,先进入图片目录下)
fdfs_upload_file /etc/fdfs/client.conf ~/1.jpg
返回如下的结果证明上传成功:
group1/M00/00/00/wKh0gV6AHlmAE3wKAACvCsI7WgM913.jpg
安装Nginx
进入下载fastall里面Nginx目录下
cd nginx
配置Nginx
Add -module 后面的路径对应第一下载好的fastdfs-nginx-module路径
sudo ./auto/configure --prefix=/usr/local/nginx --add-module=/home/huadian/fileServe/fastdfs-nginx-module/src
出现如下图所示,即为安装完成。
如果出现如下错误
./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.
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
安装libpcre3-dev 和 zlib1g-dev
sudo apt install libpcre3-dev
sudo apt install zlib1g-dev
之后在重新执行
sudo ./configure --prefix=/usr/local/nginx --add-module=/home/light/fastdfsall/fastdfs-nginx-module/src/
配置命令执行成功之后进行编译安装:
sudo make
sudo make install
问题 sudo make 异常
编辑 fastdfs-nginx-module-1.20/src/config 文件
vim fastdfs-nginx-module-1.20/src/config
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
重新 config
sudo ./configure --prefix=/usr/local/nginx --add-module=/home/light/fastdfsall/fastdfs-nginx-module/src/
配置命令执行成功之后进行编译安装:
sudo make
sudo make install
安装完成之后复制/mod_fastdfs.conf
sudo cp /home/huadian/fileServe/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
修改mod_fastdfs.conf
sudo gedit /etc/fdfs/mod_fastdfs.conf
修改内容如下:
connect_timeout=10
tracker_server=自己服务器ip:22122
url_have_group_name=true
store_path0=/home/light/fastdfs/storage
复制http.conf 和 mime.types
sudo cp /home/huadian/fileServe/fastdfs/conf/http.conf /etc/fdfs/http.conf
sudo cp /home/huadian/fileServe/fastdfs/conf/mime.types /etc/fdfs/mime.types
修改Nginx配置:
sudo gedit /usr/local/nginx/conf/nginx.conf
在http里新增一个监听端口:
server {
listen 9999;
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
返回如下内容启动成功:
ngx_http_fastdfs_set pid=43743
接下来可以通过浏览器来访问刚才上传的图片:对应自己的文件名字
再次上传一张图片
fdfs_upload_file /etc/fdfs/client.conf ~/1.jpg
Ip:9999/group1/M00/00/00/wKh0gV6AHlmAE3wKAACvCsI7WgM913.jpg