1. The official download site for downloading MongoDB is www. mongodb. orgdownloads can download the latest installer on it. On the download page, you can see that it supports a comprehensive operating system, such as OSX, Linux, Windows, and Solaris, both have their own 32-bit and 64-bit versions 2.4.12. The following sections describe Windows and
1. Download MongoDB official download site is the http://www.mongodb.org/downloads can download the latest installer on the above, you can see on the download page, it supports the operating system is very comprehensive, for example, OS X, Linux, Windows, and Solaris are supported, and each of them has its own 32-bit and 64-bit versions 2.4.12. The following sections describe Windows and
1. Download
MongoDB official download site is http://www.mongodb.org/downloads can download the latest installer on the above, on the download page can be seen, it supports the operating system is very comprehensive, for example, OS X, Linux, Windows, and Solaris are supported, and each of them has its own 32-bit and 64-bit versions 2.4.12.
The following describes how to install Windows and Linux.
2. Install Windows
Step 1: Download MongoDB
Url: http://www.mongodb.org/dr//fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.6.zip/download
Note: We recommend that you do not use a 32-bit windows xp 32-bit environment for installation and download.
Step 2: Set the MongoDB program storage directory
Create a new folder named mongodb under the C: \ disk directory, decompress MongoDB to the directory, and then create the subdirectories data and logs. The data directory is used to store mongodb data. The logs directory stores mongodb logs.
Step 3: Configure Environment Variables
This step is mainly used to facilitate the use of command lines. You can add C: \ mongodb \ bin to the path of the system environment variable.
Step 4: Start the MongoDB service.
Open the cmd console and perform the following operations to start the MongoDB service.
Note: The default listening port of the MongoDB server is 27017.
Step 5: Install the windows Service
Perform the following operations:
In this case, you can view the MongoDB service in the windows service, as shown in:
Enter the following command in the cmd console to start the MongoDB service, or directly start the MongoDB service in windows.
Step 6: Verify the Client Connection
Open a new cmd console and enter mongo. If the following prompt is displayed, you can start your MongoDB journey.
Step 7: View MongoDB logs
Check the c: \ mongodb \ logs \ mongodb. log File to view the running status of MongoDB or to troubleshoot the problem.
This completes the MongoDB installation demonstration on the Windows platform.
3. Installation of Linux
3.1 installation instructions
System Environment: CentOS-6.4 64-bit
Software: mongodb-linux-x86_64-2.6.6.tgz
: Http://www.mongodb.org/
Upload location:/usr/src/
Installation Directory:/usr/local/mongodb
Data Location:/var/mongodb/data
Log location:/var/mongodb/logs
3.2 check whether mongodb has been installed
[Root @ localhost src] # rpm-qa | grep mongodb
[Root @ localhost src] # service mongodb status
Mongodb: unrecognized service
3.3 install mongodb
[Root @ localhost ~] # Cd/usr/src [root @ localhost src] # groupadd mongodb [root @ localhost src] # useradd mongodb-g mongodb [root @ localhost src] # tar-zxvf mongodb-linux-x86_64-2.6.6.tgz [root @ localhost src] # mv mongodb-linux-x86_64-2.6.6/usr/local/mongodb [root @ localhost src] # cd/usr/local/[root @ localhost local] # chown-R mongodb: mongodb [root @ localhost local] # cd mongodb/[root @ localhost mongodb] # mkdir/var/mongodb [root @ localhost mongodb] # mkdir/var/mongodb/data [root @ localhost mongodb] # mkdir/var/mongodb/logs [root @ localhost mongodb] # service iptables stop // (this article is from the Internet (http://www.68idc.cn)] disable the firewall iptables: Flushing firewall rules: [OK] iptables: Setting chains to policy ACCEPT: filter [OK] iptables: Unloading modules: [OK]
3.4 Configuration
Add CentOS boot item
[Root @ localhost mongodb] # vi +/etc/rc. d/rc. local
Append the mongodb startup command script to the file:
/Usr/local/mongodb/bin/mongod -- dbpath =/var/mongodb/data -- logpath/var/mongodb/logs/log. log-fork
3.5 start MongoDB
[Root @ localhost bin] #./mongod -- dbpath =/var/mongodb/data/-- logpath/var/mongodb/logs/log. log-fork
3.6 test MongoDB
[root@localhost bin]# ./mongoMongoDB shell version: 2.6.6connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, seehttp://docs.mongodb.org/Questions? Try the support grouphttp://groups.google.com/group/mongodb-user>
View database list
> show dbsadmin (empty)local 0.078GB
Switch Database
> use adminswitched to db admin
Add User
> db.addUser("xuzheng","123456",true);WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' insteadSuccessfully added user: { "user" : "xuzheng", "roles" : [ "readAnyDatabase" ] }Display status
> db.stats();{"db" : "admin","collections" : 4,"objects" : 11,"avgObjSize" : 82.9090909090909,"dataSize" : 912,"storageSize" : 32768,"numExtents" : 4,"indexes" : 3,"indexSize" : 24528,"fileSize" : 67108864,"nsSizeMB" : 16,"dataFileVersion" : {"major" : 4,"minor" : 5},"extentFreeList" : {"num" : 0,"totalSize" : 0},"ok" : 1}
Display current version:
> Db. version ();
2.6.6
Obtain the currently used database:
> Db. getMongo ();
Connection to 127.0.0.1
Simple data insertion:
> Db. user. insert ({"name": "xuzheng", age: 20 });
WriteResult ({"nInserted": 1 })
View data:
> Db. user. find ();
{"_ Id": ObjectId ("549d085621fc93b35ccba9a0"), "name": "xuzheng", "age": 20}
Note: The above is only a simple demonstration of the most common basic operations of MongoDB. By default, the database listening port of MongoDB is 27017. If you want to remotely connect to a non-service, use -- port and -- host, as shown in:
Of course, the premise is that the mongodb client tool must be installed on a remote machine, that is, the mongo service.
So far, MongoDB has been installed on Windows and Linux platforms. Due to the inconsistent system environments, some problems may occur during installation on other platforms, you can find a solution on the Internet.