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/mongodb/cd/usr/ Local/mongodb/mkdir-p/data0/mongodb/dbmkdir/data0/mongodb/log
3. Start:
To configure environment variables:
Echo ' Export path=/usr/local/mongodb/bin: $PATH ' >/etc/profile.d/mongodb.shsource/etc/profile.d/mongodb.sh
Command line startup:
Mongod--dbpath=/data0/mongodb/db/--logpath=/data0/mongodb/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] mongodb]# cat/etc/mongod.conf
LogPath =/data0/mongodb/log/truetrue=/data0/mongodb/db/ 27017 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://10.1.1.45:28017/
Start MongoDB:
[[email protected] mongodb]# mongod-f/etc/-i:27017 COMMAND PID USER FD TYPE DEVICE SIZE/ OFF NODE NAME 17434 6u 194070 0t0 TCP *:27017 (LISTEN)
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] mongodb]# MONGO
>helpdb.help () Help on DB Methodsdb.mycoll.help () Help on collection methodsSH. Help () sharding helpersrs.help () replica set HELPERSHELP admin administrative helphelp Connect connecting to a DB hel Phelp keys key Shortcutshelp misc Misc Things to Knowhelp Mr Mapreduceshow DBS Show Database Namesshow collections Show Co LlectionsinchCurrent databaseshow users show UsersinchCurrent databaseshow Profiles show most recent system.profile entries with Time>=1msshow logs show the accessible logger namesshow log [name] prints out the LastSegment of LoginchMemory'Global'is defaultuse<db_name>set current Databasedb.foo.Find() List objectsinchcollection Foodb.foo.Find({a:1}) List objectsinchFoo where a = =1It result of the LastLine evaluated; further iteratedbquery.shellbatchsize=x Set default number of items to display on Shellexit quit the MONGO shell>Show Users>Show Profile Db.system.profile is Emptyuse db.setprofilinglevel (2) would enable Profilinguse Db.system.profile.Find() to show raw profile entries# lists which databases are currently>Show Dbs;local0. 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;local0. 078GBtest0. 078gb# view the current database>dbtest# lists which collections are in the current database>Show Collectionssystem.indexestest_1
6. Close MongoDB:
[Email protected] mongodb]# MONGO
>Use adminswitched to DB admin>db.shutdownserver (); -- .-01T19: *:45.155-0700I NETWORK dbclientcursor::init call () Failedserver should is down ... -- .-01T19: *:45.159-0700I NETWORK trying reconnect to127.0.0.1:27017(127.0.0.1) failed -- .-01T19: *:45.159-0700W NETWORK Failed to connect to127.0.0.1:27017, Reason:errno:111Connection refused -- .-01T19: *:45.160-0700I NETWORK Reconnect127.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> Quit ()
[Email protected] mongodb]# lsof-i:27017
Shutdown succeeded.
Introduction to MongoDB Installation deployment and commands