Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

FastDFS及nginx相关安装包下载地址(仅供参考):
https://github.com/gpf1991/FastDFS-nginx.git

一. FastDFS安装

1. 安装fastdfs依赖包

1.1 解压缩libfastcommon-master.zip

可以在windows下解压缩, 然后复制到虚拟机中

1.2 进入到libfastcommon-master的目录中

1.3 编译

	./make.sh

1.4 安装

	sudo ./make.sh install

2. 安装fastdfs

2.1 解压缩fastdfs-master.zip

2.2 进入到 fastdfs-master目录中

2.3 编译

	./make.sh

2.4 安装

	sudo ./make.sh install

3 配置跟踪服务器tracker

3.1 复制tracker配置文件到/etc/fdfs目录下

	sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

3.2 在主目录(我的是 /home/python/)下创建目录 fastdfs/tracker

	mkdir –p /home/python/fastdfs/tracke

3.3 编辑 tracker.conf 配置文件

	sudo vim /etc/fdfs/tracker.conf
	
	修改:
	base_path=/home/python/fastdfs/tracker

4 配置存储服务器storage

4.1 复制storage配置文件到/etc/fdfs目录下

	sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

4.2 在/home/python/fastdfs/ 目录中创建目录 storage

	mkdir –p /home/python/fastdfs/storage

4.3 编辑 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

5. 启动tracker 和 storage

	sudo service fdfs_trackerd start
	sudo service fdfs_storaged start
	
	如果以上两行命令启动不了, 则用下面两行命令:
	sudo fdfs_trackerd /etc/fdfs/tracker.conf
	sudo fdfs_storaged /etc/fdfs/storage.conf

5.1 查看是否启动

	ps aux|grep fdfs

Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

6 测试是否安装成功

6.1 复制client配置文件到/etc/fdfs/下

	sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

6.2 编辑 client.conf 配置文件

	sudo vim /etc/fdfs/client.conf
	修改内容:
	base_path=/home/python/fastdfs/tracker
	tracker_server=自己ubuntu虚拟机的ip地址:22122

6.3 上传文件测试

	fdfs_upload_file /etc/fdfs/client.conf 要上传的图片文件

如果返回类似group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg的文件id则说明文件上传成功
Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

二. 安装nginx及fastdfs-nginx-module

1. 解压缩 nginx-1.8.1.tar.gz

2. 解压缩 fastdfs-nginx-module-master.zip

3. 进入nginx-1.8.1目录中

4. 配置路径, 编译, 安装

	sudo ./configure --prefix=/usr/local/nginx/ --add-module=fastdfs-nginx-
			module-master解压后的目录的绝对路径/src
		注意: 此处容易报错, 详见本文下方: "三. 常见错误"
	sudo ./make			    或 sudo make
	sudo ./make install		或 sudo make install

5. 复制mod_fastdfs.conf到/etc/fdfs/下

	sudo cp fastdfs-nginx-module-master解压后的目录中src下的
			mod_fastdfs.conf  /etc/fdfs/mod_fastdfs.conf

6. 编辑 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/python/fastdfs/storage

7. 复制 http.conf 到 /etc/fdfs/下

	sudo cp 解压缩的fastdfs-master目录中conf目录中的http.conf 
		 /etc/fdfs/http.conf

8. 复制 mime.types 到 /etc/fdfs/下

	sudo cp 解压缩的fastdfs-master目录中conf目录中的mime.types 
		/etc/fdfs/mime.types

9. 编辑 nginx.conf 配置文件

	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;
	            }
	        }

Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

10. 启动nginx

	sudo /usr/local/nginx/sbin/nginx
	查看是否启动
	ps aux|grep nginx

Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

三. 常见错误

1. 配置文件中少括号或多括号

Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

2. 执行 sudo ./configure --prefix=/usr/local/nginx/ --add-module=fastdfs-nginx-module-master解压后的目录的绝对路径/src 之后报错1:

./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= option.

解决方法:

	sudo apt-get install libpcre3 libpcre3-dev

3. 执行 sudo ./configure --prefix=/usr/local/nginx/ --add-module=fastdfs-nginx-module-master解压后的目录的绝对路径/src 之后报错2:

./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.

解决方法:

	1. 下载zlib库,地址:http://www.zlib.net/
	2. 直接解压安装: which zlib
	3. 查看一下,有可能还需要安装:
		 sudo apt-get install openssl libssl-dev
	4. 执行configure操作:
		./configure –prefix=/usr/local/nginx –pid-path=
		/var/run/nginx.pid--with-http_stub_status_module –with-http_ssl_module

四. 卸载nginx

	sudo apt-get --purge autoremove nginx
	which nginx  #如果没有提示,证明卸载成功

五. 使用python客户端上传测试

1. 进入 fdfs_client-py-master.zip 所在目录

2. 安装

	pip install fdfs_client-py-master.zip

3. 在交互模式下测试

from fdfs_client.client import Fdfs_client
client = Fdfs_client(’/etc/fdfs/client.conf’)
ret = client.upload_by_filename(‘weiweian2.jpg’)
ret #查看返回值

Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法

3.1 在浏览器查看保存的图片

在浏览器输入地址: http://127.0.0.1:8888/group1/M00/00/00/sIgEMFy0anqAFcVUAAYMZT-_-8M633.jpg

注: 必须在nginx服务器开启的状态下

显示如下:
Ubuntu系统下FastDFS分布式存储服务器安装和Nginx服务器安装及常见错误和解决方法