nginx+gridfs+mongodb分布式图片存储系统

1.下载安装mongodb文档数据库

[[email protected] ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz

[[email protected] ~]# tar xvf mongodb-linux-x86_64-rhel62-3.0.7.tgz

[[email protected] ~]# mv mongodb-linux-x86_64-rhel62-3.0.7 /usr/local/mongodb-3.0.7

[[email protected] ~]# /usr/local/mongodb-3.0.7/bin/mongod --dbpath=/usr/local/mongodb-3.0.7/data --logpath=/usr/local/mongodb-3.0.7/logs/mongod.log --port=27017 --logappend --fork


2.下载安装nginx和gridfs

gridfs下载地址:http://pan.baidu.com/s/1mgpiOmG

[[email protected] ~]# wget http://nginx.org/download/nginx-1.4.7.tar.gz

[[email protected] ~]# tar xvf nginx-gridfs.tar.gz 

[[email protected] ~]# tar xvf nginx-1.4.7.tar.gz

[[email protected] ~]# ./configure --prefix=/usr/local/nginx-1.4.7 --with-pcre=/usr/local/pcre-8.37 --with-http_stub_status_module  --with-poll_module --add-module=/root/nginx-gridfs  --user=www --group=www

[[email protected] ~]# make && make install

vim /usr/local/nginx-1.4.7/conf/nginx.conf

       location /abc/ {

            gridfs my_app root_collection=fs field=filename type=string;  --my_app是mongodb中的数据库,root_collection是表的前缀,field是文件,type是存储文件的类型

            mongo 127.0.0.1:27017;   --mongodb的IP和端口

        }


3.在mongodb中创建数据库

/usr/local/mongodb-3.0.7/bin/mongo

    use my_app;            --创建数据库就可以了,创建后必须写入数据才能生效


4.上传图片

/usr/local/mongodb-3.0.7/bin/mongofiles put 12.png  -h127.0.0.1:27017 -d my_app -t png 

put         --是上传

12.png       --是上的文件

my_app      --mongodb的数据库

png        --文件类型

[[email protected] ~]# /usr/local/mongodb-3.0.7/bin/mongofiles list -d my_app

2015-11-17T15:45:04.413+0800connected to: localhost

13.jpg109481

12.png490834

15.png210592

[[email protected] ~]# 


5.访问图片的地址

nginx+gridfs+mongodb分布式图片存储系统



错误记录:

2015/11/17 14:21:45 [emerg] 31441#0: *7 malloc(18446744056529682432) failed (12: Cannot allocate memory)


解决方法:

  是mongodb的问题,重新安装下mongodb或者下功较低的版本.










本文转自 z597011036 51CTO博客,原文链接:http://blog.51cto.com/tongcheng/1713509,如需转载请自行联系原作者