1. Download the software:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.3.tgz
2. Unzip the installation:
TAR-ZXVF mongodb-linux-x86_64-rhel62-3.0.3.tgz
MV mongodb-linux-x86_64-rhel62-3.0.3/usr/local/
cd/usr/local/
Ln-s mongodb-linux-x86_64-rhel62-3.0.3 MongoDB
Mkdir-p data/db mkdir Data/log
3. Start:
Echo ' Export path=/usr/local/mongodb/bin: $PATH ' >/etc/profile.d/mongodb.sh
source/etc/profile.d/mongodb.sh
Command line startup:
./mongod--dbpath=. /data/db--logpath=. /data/log/mongod.log--fork
Mongod The storage directory of the specified data for the server-side program--dbpath--logpath specifies the storage directory for the log--fork to be started as a daemon (note that the log storage path must be specified when starting with daemon mode)
Configuration file Startup:
[Email protected] bin]# cat/etc/mongod.conf
Logpath=/usr/local/mongodb/data/log/mongod.log
Logappend=true
Fork=true
dbpath=/usr/local/mongodb/data/db
port=27017
Rest=true;
#默认的mongodb会监控27017端口不甚安全, you can use the--port parameter to set its monitoring port. MongoDB default will start a Web server on the port number of the service plus 1000, to use the content of the Web server, you need to enable the--rest parameter;
#http://192.168.16.131:28017
[Email protected] bin]#./mongod-f/etc/mongod.conf
Introduction to the 4.MONGODB architecture:
4.1 Logical Structure of data
The logical structure of the data of MongoDB consists of: Database, Collection (collections), document, and three parts.
A MongoDB supports multiple databases, each containing multiple collections (equivalent to tables in a relational database), each containing multiple documents (equivalent to one row of tables in a relational database).
4.2 Data storage structure
In MongoDB, each database contains one. NS and one or more data files, where data files become more numerous as data volumes, such as data files for Test databases, consist of test.0, Test.1, test.2, and so on. MongoDB uses a pre-allocated space mechanism, each of the pre-allocated space files are populated with 0, because the collection of data increase, the data file every new allocation, it will be twice times the size of the previous file, each set and index in the database corresponding to a namespace, The metadata for these namespaces is stored in the. ns file.
4.3BSON
Bson is a JSON-like binary storage format, binary JSON that supports built-in document objects and array objects, and contains some data types that JSON does not have. MongoDB uses Bson this structure to store data and network data exchange, this format into the concept of document, because Bson is the mode of freedom, so document is also the mode of freedom.
Simple operation of 5.mongodb:
[Email protected] ~]# MONGO
> Help
Db.help () Help on DB methods
Db.mycoll.help () Help on collection methods
Sh.help () sharding Helpers
Rs.help () Replica set helpers
Help Admin Administrative Help
Help connect connecting to a DB help
Help keys key shortcuts
Help Misc Misc Things to Know
Help Mr MapReduce
Show DBS Show Database names
Show collections show collections in current database
Show users show users in current database
Show profile Show most recent system.profile entries with time >= 1ms
Show logs show the accessible logger names
Show log [name] prints out the last segment of log in memory, ' global ' is default
Use <db_name> Set current database
Db.foo.find () List objects in collection Foo
Db.foo.find ({a:1}) List objects in Foo where a = = 1
It result of the last line evaluated; Use to further iterate
dbquery.shellbatchsize = X Set default number of items to display on shell
Exit quit the MONGO shell
> Show Users
> Show Profile
Db.system.profile is empty
Use Db.setprofilinglevel (2) would enable profiling
Use Db.system.profile.find () to show raw profile entries
#列出当前有哪些数据库
> Show DBS;
Local 0.078GB
> Db.test_1.save ({1: "AAA"});
Writeresult ({"ninserted": 1})
> Db.test_1.save ({2: "BBB"});
Writeresult ({"ninserted": 1})
> Db.test_1.find ();
{"_id": ObjectId ("556d171a75f85e97eeec2f5b"), "1": "AAA"}
{"_id": ObjectId ("556d172375f85e97eeec2f5c"), "2": "BBB"}
> Show DBS;
Local 0.078GB
Test 0.078GB
#查看当前的数据库
> DB
Test
#列出当前数据库中有哪些集合
> Show Collections
System.indexes
Test_1
6. Close MongoDB:
[Email protected] ~]# MONGO
> Use admin
Switched to DB admin
> Db.shutdownserver ();
2015-06-01t19:35:45.155-0700 I NETWORK Dbclientcursor::init call () failed
Server should is down ...
2015-06-01t19:35:45.159-0700 I NETWORK Trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2015-06-01t19:35:45.159-0700 W NETWORK Failed to connect to 127.0.0.1:27017, reason:errno:111 Connection refused
2015-06-01t19:35:45.160-0700 I NETWORK Reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn ' t connect to server 127 .0.0.1:27017 (127.0.0.1), connection attempt failed
This article is from the "Webseven" blog, make sure to keep this source http://webseven.blog.51cto.com/4388012/1657585
MongoDB Installation and Deployment