1. Download MongoDB, the version downloaded here is: Mongodb-linux-i686-1.8.1.tgz.tar.
Http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.1.tgz
Related reading:
Installation and startup http://www.linuxidc.com/Linux/2011-05/36309.htm under MongoDB Linux
Advanced query Example under MongoDB http://www.linuxidc.com/Linux/2011-05/36312.htm
MongoDB Java API for Insert and single collection basic query use example http://www.linuxidc.com/Linux/2011-05/36313.htm
Query operation under MONGODB (corresponds to Java API query operation) http://www.linuxidc.com/Linux/2011-05/36314.htm
2. Unzip the file into a directory and rename it:
- [Root@localhost src]# tar-xzvf mongodb-linux-i686-1.8. 1.tgz.tar
- [Root@localhost src]# mv mongodb-linux-i686-1.8. 1/usr/local/mongodb/
3. View post-installation files:
- [Root@localhost src]# cd/usr/local/mongodb/
- [Root@localhost mongodb]# ls
- Bin gnu-agpl-3.0 README third-party-notices
- [Root@localhost mongodb]# cd bin/
- [Root@localhost bin]# ls
- Bsondump dbbak MONGO Mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongost At
The Mongod under the bin is the service-side process of MongoDB, MONGO is its client, and other commands are used for MongoDB for other purposes such as MongoDB file export.
4. Start MongoDB.
To set up a good MongoDB storage data files and log files directory, here is established under/data:
- [Root@localhost etc]# cd/data/
- [Root@localhost data]# ls
- Mongodb_data Mongodb_log
Use Mongod to start MongoDB under the bin under the MongoDB installation directory,
- ./mongod--dbpath=/data/mongodb_data/--logpath=/data/mongodb_log/mongodb.log--logappend&
After you wait for the startup to succeed, you can see if the boot was successful, the default port number is 27017, and you can also specify an unused port at startup.
Start by looking at the port number to see if MongoDB is started.
- [root @localhost data]# Netstat -lanp | grep "27017"
- Tcp 0 0 0.0. 0.0: 27017 0.0. 0.0:* listen 1573/mongod
- Unix 2 [ACC] STREAM LISTENING 5874 1573/mongod/tmp/mongodb-27017.sock
As you can see, it started successfully and now accesses the database using the MONGO client.
- [Root@localhost bin]# cd/usr/local/mongodb/bin/
- [Root@localhost bin]#./mongo
- MongoDB Shell version: 1.8. 1
- Connecting To:test
- >
This step indicates that the installation is successful.
5. Additional work.
Note that the above we started MongoDB are manually use Mongod to start, so after shutting down the computer, the next time it did not start, so it has to be started manually, so in order to avoid this tedious work, you can put Mongod into the service from the startup item, In this way, when the computer opens the Mongod service is started.
To edit the/etc/rc.local, add the following code and save it.
- #add MONGONDB Service
- rm-rf/data/mongodb_data/* &&/usr/local/mongodb/bin/mongod--dbpath=/data/mongodb_data/--logpath=/data/ Mongodb_log/mongodb.log--logappend&
We restart the computer to see if MongoDB is started, restart can be directly using the MONGO command login, the final discovery can be successful.
Also, we use the MONGO command to log in to MongoDB and go to the directory where the MONGO command is located and execute./mongo, is that a bit of a problem? Therefore, we can simplify this by copy the command file to/usr/bin so that the MONGO command can be used in any directory.
- [Root@localhost bin]# ls
- Bsondump dbbak MONGO Mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongost At
- [Root@localhost bin]# CP mongo/usr/bin/
Go to any directory try the MONGO command:
- [Root@localhost bin]# CD/
- [Root@localhost/]# MONGO
- MongoDB Shell version: 1.8. 1
- Connecting To:test
- >
You can see that the login was successful, which means we can use the MONGO command just like the LS command.
Original address: http://www.linuxidc.com/Linux/2011-05/36309.htm
Installation and startup under MongoDB Linux (RPM)