发布于 2015-09-14 14:44:47 | 151 次阅读 | 评论: 0 | 来源: 网络整理

Synopsis

10gen provides compiled versions of MongoDB for use on Linux that provides a simple option for users who cannot use packages. This tutorial outlines the basic installation of MongoDB using these compiled versions and an initial usage guide.

也可以参考

The documentation of following related processes and concepts.

Other installation tutorials:

Download MongoDB

注解

You should place the MongoDB binaries in a central location on the file system that is easy to access and control. Consider /opt or /usr/local/bin.

In a terminal session, begin by downloading the latest release. In most cases you will want to download the 64-bit version of MongoDB.

curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-x.y.z.tgz > mongo.tgz

If you need to run the 32-bit version, use the following command.

curl http://downloads.mongodb.org/linux/mongodb-linux-i686-x.y.z.tgz > mongo.tgz

Once you’ve downloaded the release, issue the following command to extract the files from the archive:

tar -zxvf mongo.tgz

Optional

You may use the following command to copy the extracted folder into a more generic location.

cp -R -n  mongodb-linux-????-??-??/ mongodb

You can find the mongod binary, and the binaries all of the associated MongoDB utilities, in the bin/ directory within the extracted directory.

Using MongoDB

Before you start mongod for the first time, you will need to create the data directory. By default, mongod writes data to the /data/db/ directory. To create this directory, use the following command:

mkdir -p /data/db

注解

Ensure that the system account that will run the mongod process has read and write permissions to this directory. If mongod runs under the mongo user account, issue the following command to change the owner of this folder:

chown mongo /data/db

If you use an alternate location for your data directory, ensure that this user can write to your chosen data path.

You can specify, and create, an alternate path using the --dbpath option to mongod and the above command.

The 10gen builds of MongoDB contain no control scripts or method to control the mongod process. You may wish to create control scripts, modify your path, and/or create symbolic links to the MongoDB programs in your /usr/local/bin or /usr/bin directory for easier use.

For testing purposes, you can start a mongod directly in the terminal without creating a control script:

mongod --config /etc/mongod.conf

注解

The above command assumes that the mongod binary is accessible via your system’s search path, and that you have created a default configuration file located at /etc/mongod.conf.

Among the tools included with this MongoDB distribution, is the mongo shell. You can use this shell to connect to your MongoDB instance by issuing the following command at the system prompt:

./bin/mongo

注解

The ./bin/mongo command assumes that the mongo binary is in the bin/ sub-directory of the current directory. This is the directory into which you extracted the .tgz file.

This will connect to the database running on the localhost interface by default. At the mongo prompt, issue the following two commands to insert a record in the “test” collection of the (default) “test” database and then retrieve that record:

> db.test.save( { a: 1 } )
> db.test.find()

也可以参考

mongo” and “mongo Shell JavaScript 快参

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务