1. Preparations
Sudo Yum-y install PCRE-devel OpenSSL-devel geoip-devel zlib-devel
2. Download The nginx-gridfs source code and add the MongoDB-mongo-C-driver source code to nginx-gridfs/mongo-C-driver.
# BecauseCodeChanges to version numbers cannot be used. You can search for them yourself ..
Wget https://download.github.com/mdirolf-nginx-gridfs-v0.8-0-gb5f8113.tar.gz
Tar-zxvf mdirolf-nginx-gridfs-v0.8-0-gb5f8113.tar.gz
MV mdirolf-nginx-gridfs-v0.8-0-gb5f8113 mdirolf-nginx-gridfs-v0.8
Wget https://download.github.com/mongodb-mongo-c-driver-v0.3-0-g74cc0b8.tar.gz
Tar-zxvf mongodb-mongo-c-driver-v0.3-0-g74cc0b8.tar.gz
MV mongodb-mongo-c-driver-v0.3-0-g74cc0b8/* mdirolf-nginx-gridfs-v0.8/mongo-C-driver
Rm-RF mongodb-mongo-c-driver-v0.3-0-g74cc0b8
3. Install nginx and specify the nginx-gridfs directory to be compiled together with nginx
Wget http://nginx.org/download/nginx-1.0.1.tar.gz
Tar-zxvf nginx-1.0.1.tar.gz
CD nginx-1.0.1
. /Configure -- prefix =/usr/local/nginx -- With-OpenSSL =/usr/include/OpenSSL -- with-http_stub_status_module -- add-module =/home/CDH/downloads/mdirolf-nginx- gridfs
Make-J8
Sudo make install-J8
4. Install and start MongoDB
Wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.1.tgz
Tar-xvf mongodb-linux-i686-1.8.1.tgz
Sudo MV mongodb-linux-i686-1.8.1/usr/local/MongoDB
Sudo mkdir-P/tmp/MongoDB/Data
/Usr/local/MongoDB/bin/mongod -- dbpath/tmp/MongoDB/data -- logpath/tmp/MongoDB/data/log. Log-Fork
5. Configure nginx-gridfs
Sudo Vim/usr/local/nginx/CONF/nginx. conf
Location/pics /{
Gridfs pics
Field = filename
Type = string;
Mongo 127.0.0.1: 27017;
}
Gridfs: keyword used by nginx to identify plug-ins
Pics: DB name
[Root_collection]: select collection, for example, root_collection = blog. mongod will find the blog. Files and blog. Chunks. The default value is FS.
[Field]: query a field. Make sure that the field name is in mongdb. The parameter _ id and filename are supported, which can be omitted. The default value is _ id.
[Type]: indicates the Data Type of the field. objectid, Int, string are supported, which can be omitted. The default value is int.
[User]: user name, which can be omitted
[Pass]: password, which can be omitted
Mongo: MongoDB URL
6. upload images
Sudo/usr/local/MongoDB/bin/program files put -- Host localhost -- Port 27017 -- DB pics -- local ~ /Photo.jpg -- type JPG
7. Start nginx
Sudo/usr/local/nginx/sbin/nginx
Enter http: // localhost/pics/photo.jpg in the browser to download the image.
8. A description written one year later
Gridfs is restricted by MongoDB's performance restrictions. After a large amount of data is stored, the write performance decreases rapidly, and the read concurrency is not satisfactory. When the throughput peak limit (6 clusters with 2 shards 30-40 Mbit/s) is reached, there will be a lot of exceptions that we cannot solve in the logs (suffering from death ). Therefore, it is not suitable as a dedicated large-scale distributed file storage system, but can meet the general application-level static file storage requirements.