本文为本人在Ubuntu18.04版本上安装FastDFS以及配置Nginx的过程,鉴于网上有些纯粹的Copy文,照着难以成功安装。谨记录以供查阅参考。文中各安装包及虚拟机皆为写作时候最新稳定版本,Ubuntu版本为18.04,fastdfs为5.11版本,nginx为1.15.9,对于其它版本信息,成功不作保证~~
安装包名称 | 下载地址 |
---|---|
fastdfs-5.11.zip | https://github.com/happyfish100/fastdfs/releases |
fastdfs-nginx-module | https://github.com/happyfish100/fastdfs-nginx-module |
libfastcommon | https://github.com/happyfish100/libfastcommon |
nginx | http://nginx.org/download/nginx-1.15.9.tar.gz |
利用Xftp传输到用户目录下,博主的用户目录为/home/python
:
使用xshell
连接到Ubuntu虚拟机,解压libfastcommon-master.zip
:
python@ubuntu:~$ unzip libfastcommon-master.zip
进入到libfastcommon-master/:
python@ubuntu:~$ cd libfastcommon-master/
执行命令:
python@ubuntu:~/libfastcommon-master$ ./make.sh
如果这里make出错,没有命令之类的,请先安装以下依赖,然后重新执行上一步的make命令:
# 1. 更新源
sudo apt-get update
# 2.安装c++依赖库
sudo apt-get install build-essential
sudo apt-get install libtool
# 3.安装openssl依赖库
sudo apt-get install openssl
# 4.安装pcre依赖库
sudo apt-get install libpcre3 libpcre3-dev
# 5.安装zlib依赖库
sudo apt-get install zlib1g-dev
执行命令:
python@ubuntu:~/libfastcommon-master$ sudo ./make.sh install
python@ubuntu:~/libfastcommon-master$ cd ~
python@ubuntu:~$ unzip fastdfs-5.11.zip
fastdfs-5.11/
目录,执行命令:python@ubuntu:~$ cd fastdfs-5.11/
python@ubuntu:~/fastdfs-5.11$ ./make.sh
python@ubuntu:~/fastdfs-5.11$ sudo ./make.sh install
python@ubuntu:~/fastdfs-5.11$ sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
python@ubuntu:~/fastdfs-5.11$ mkdir -p /home/python/fastdfs/tracker
python@ubuntu:~/fastdfs-5.11$ sudo vim /etc/fdfs/tracker.conf
修改内容:
base_path=/home/python/fastdfs/tracker
python@ubuntu:~/fastdfs-5.11$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
python@ubuntu:~/fastdfs-5.11$ mkdir -p /home/python/fastdfs/storage
python@ubuntu:~$ sudo vim /etc/fdfs/storage.conf
修改内容:
base_path=/home/python/fastdfs/storage
store_path0=/home/python/fastdfs/storage
tracker_server=192.168.0.4:22122
tracker_server修改为自己的虚拟机IP,端口默认22122
python@ubuntu:~/fastdfs-5.11$ sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
python@ubuntu:~/fastdfs-5.11$ sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
python@ubuntu:~/fastdfs-5.11$ sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
python@ubuntu:~$ sudo vim /etc/fdfs/client.conf
修改内容:
base_path=/home/python/fastdfs/tracker
tracker_server=192.168.0.4:22122
tracker_server=192.168.0.4:22122,这个为自己虚拟机的IP,端口默认为22122
python@ubuntu:~/fastdfs-5.11$ fdfs_upload_file /etc/fdfs/client.conf ~/Desktop/1.jpg
group1/M00/00/00/wKgABFynMHGAGnWnABAQQts_NUc655.jpg
~/Desktop/1.jpg
这个替换为自己的图片路径
看到返回group1/M00/00/00/wKgABFynMHGAGnWnABAQQts_NUc655.jpg
这样的字符串,表示安装成功。
nginx-1.15.9.tar.gz
python@ubuntu:~$ tar -zxvf nginx-1.15.9.tar.gz
fastdfs-nginx-module-master.zip
python@ubuntu:~$ unzip fastdfs-nginx-module-master.zip
nginx-1.15.9/
目录python@ubuntu:~$ cd nginx-1.15.9/
python@ubuntu:~/nginx-1.15.9$ sudo ./configure --prefix=/usr/local/nginx/ --add-module=/home/python/fastdfs-nginx-module-master/src/
–add-module= 后边是fastdfs-nginx-module-master解压后的绝对路径下的/src目录
python@ubuntu:~/nginx-1.15.9$ sudo make
python@ubuntu:~/nginx-1.15.9$ sudo make install
注:博主执行make这里报错了,如果你执行完make不报错,下边的解决方案请忽略,报错如下:
/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory
如下图
查阅了相关资料,最后解决方案如下:
修改fastdfs-nginx-module-master/src/config
文件
python@ubuntu:~$ sudo vim fastdfs-nginx-module-master/src/config
修改内容:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
修改完成后,从上边的4. 执行命令 sudo ./configure --prefix ...
开始重新执行。
python@ubuntu:~$ sudo cp fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
python@ubuntu:~$ sudo vim /etc/fdfs/mod_fastdfs.conf
修改内容:
connect_timeout=10
tracker_server=192.168.0.4:22122
url_have_group_name=true
store_path0=/home/python/fastdfs/storage
本文中所有
tracker_server
地址,请自行设置为自己虚拟机IP,端口为22122
python@ubuntu:~$ sudo cp fastdfs-5.11/conf/http.conf /etc/fdfs/http.conf
python@ubuntu:~$ sudo cp fastdfs-5.11/conf/mime.types /etc/fdfs/mime.types
python@ubuntu:~$ sudo vim /usr/local/nginx/conf/nginx.conf
在http里新增以下内容:
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
python@ubuntu:~$ sudo /usr/local/nginx/sbin/nginx
访问一下刚才上传的文件:
至此,FastDFS和Nginx安装配置完成。