Ubuntu FastDFS
安装fastdfs依赖包
- 解压缩libfastcommon-master.zip
- 进入到libfastcommon-master的目录中
- 执行 sudo ./make.sh 或 make.sh
- 执行 sudo ./make.sh install 或 make.sh install
安装fastdfs
- 解压缩fastdfs-master.zip
- 进入到 fastdfs-master目录中
- 执行 sudo ./make.sh 或 make.sh
- 执行 sudo ./make.sh install 或 make.sh install
配置跟踪服务器tracker
- sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
- 在/home/目录中创建目录 fastdfs/tracker
mkdir –p /home/fastdfs/tracker - 编辑/etc/fdfs/tracker.conf配置文件
sudo vim /etc/fdfs/tracker.conf
修改 base_path=/home/python/fastdfs/tracker
配置存储服务器storage
- sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
- 在/home/fastdfs/ 目录中创建目录 storage
mkdir –p /home/fastdfs/storage - 编辑/etc/fdfs/storage.conf配置文件 sudo vim /etc/fdfs/storage.conf
修改内容:
base_path=/home/python/fastdfs/storage
store_path0=/home/python/fastdfs/storage
tracker_server=自己ubuntu虚拟机的ip地址:22122
启动tracker 和 storage
- sudo service fdfs_trackerd start
sudo service fdfs_storaged start - 到这里有可能会报错(ubuntu虚拟机 )
Failed to start fdfs_trackerd.service: Unit fdfs_trackerd.service not found
两个都是一样的,我看网上有人说只报storage,这个我后面也碰到了。
解决方式:关闭虚拟机,更换网络连接方式为NAT,再重启,这时候,更改,再次启动会发现,不报错了。
测试是否安装成功
- sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
- 编辑/etc/fdfs/client.conf配置文件
sudo vim /etc/fdfs/client.conf
修改内容:
base_path=/home/python/fastdfs/tracker
tracker_server=自己ubuntu虚拟机的ip地址:22122 - 上传文件测试:
fdfs_upload_file /etc/fdfs/client.conf 要上传的图片文件
如果返回类似group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg的文件id则说明文件上传成功
安装nginx及fastdfs-nginx-module
-
解压缩 nginx-1.8.1.tar.gz
-
解压缩 fastdfs-nginx-module-master.zip
-
解压缩 fastdfs-master.zip
-
进入nginx-1.8.1目录中
-
执行
sudo ./configure --prefix=/usr/local/nginx/ --add-module=fastdfs-nginx-module-master解压后的目录的绝对路径/src
sudo ./configure --prefix=/usr/local/nginx/ --add-module=/opt/fastdfs-nginx-module-master/src
有可能出错
./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=option.
解决方案
sudo apt-get install -y zlib-devel
方法二
sudo ./configure --prefix=/usr/local/nginx/ --add-module=/opt/fastdfs-nginx-module-master/src --without-http_gzip_module -
sudo ./make 或 make.sh
有可能出错:
cc1: all warnings being treated as errors
objs/Makefile:435: recipe for target ‘objs/src/core/ngx_murmurhash.o’ failed
make[1]: *** [objs/src/core/ngx_murmurhash.o] Error 1
make[1]: 离开目录“/opt/nginx-1.8.1”
Makefile:8: recipe for target ‘build’ failed
make: *** [build] Error 2
解决方案
当Make出错,提示cc1plus: warnings being treated as errors,主要原因是 Makefile 里面 gcc 的参数多了一个"-Werror",找到出错的make文件夹,看Make文件里面有没有“-Werror",如果有的话将其删除。重新编译即可。
在vim nginx-1.8.1/obj/Makefile -
sudo ./make install 或 make.sh install
-
sudo cp fastdfs-nginx-module-master解压后的目录中src下的mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
sudo cp /opt/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf -
sudo vim /etc/fdfs/mod_fastdfs.conf
修改内容:
connect_timeout=10 超时时间
tracker_server=自己ubuntu虚拟机的ip地址:22122
url_have_group_name=true 路径里带组的信息
store_path0=/home/fastdfs/storage -
sudo cp 解压缩的fastdfs-master目录conf目录中的http.conf /etc/fdfs/http.conf
sudo cp /opt/fastdfs-master/conf/http.conf /etc/fdfs/http.conf -
sudo cp 解压缩的fastdfs-master目录conf目录中的mime.types /etc/fdfs/mime.types
sudo cp /opt/fastdfs-master/conf/mime.types /etc/fdfs/mime.types -
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;
}
} -
启动nginx
sudo /usr/local/nginx/sbin/nginx
有可能出现的错误
nginx: [emerg] using regex “/group[0-9]/” requires PCRE library in /usr/local/nginx//conf/nginx.conf:38
解决方案
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./make
./make install