[root@localhost, etc ]# cd /data/
[root@localhost data ]# ls
mongodb_data mongodb_log
Start MongoDB with MongoDB under the bin of MongoDB's installation directory.
. /mongod-dbpath =/data/MongoDB _ data/-log path =/data/MongoDB _ log/MongoDB . log-log append & amp;
After the startup is successful, you can check whether the startup is successful. The default port number is 270 17. Of course, other unused ports can also be specified at startup.
First, check the port number to see if MongoDB is started.
[root @ localhost data]# netstat-lanp | grep " 270 17 "
TCP 0000.0.00: 270170.0.0: * List EN 1573/mongod.
Unix 2 [ACC] stream monitoring 58741573/MongoD/tmp/MongoDB-27017.sock.
As you can see, it started successfully. Now use mongo client to access the database.
[root @ localhost bin]# CD/usr/local/MongoDB/bin/
[root@localhost bin]#。 /mongo
MongoDB shell version: 1.8. 1
Connect to: Test
& gt
At this point, the installation has been successful.
5. Extra work.
Note that we start MongoDB manually, so when the computer is turned off, it won't start again when it comes in next time, so we have to start it manually. So in order to avoid this tedious work, we can put MongoDB in the service startup item, so that the MongoDB service will be started as soon as the computer starts.
Edit /etc/rc.local, add the following code, and then save.
# Add mongonDB service
RM-RF/data/MongoDB _ data/* & amp; & amp/usr/local/MongoDB/bin/mongod-dbpath =/data/MongoDB _ data/-log path =/data/MongoDB _ log/MongoDB . log-log append & amp;
Let's restart the computer and see if mongoDB has started. After the restart, you can log in directly with the Mongo command, and finally you can find it successful.
In addition, we use the mongo command to log in to mongoDB, and we must go to the directory where the Mongo command is located before execution. /mongo。 Is this a little troublesome? Therefore, we can simplify this by copying the command file to /usr/bin, so that we can use the mongo command in any directory.
[root@localhost bin]# ls
bsondump db bak mongo mongod mongod dump mongo export mongofiles mongo import mongorestore mongos mongosniff mongostat
[root @ localhost bin]# CP mongo/usr/bin/
Go to any directory and try the mongo command:
[root@localhost bin]# cd /
[root@localhost /]# mongo
MongoDB shell version: 1.8. 1
Connect to: Test
& gt
You can see that the login is successful, which means that we can use the mongo command just like the ls command.
1, the Year of the Pig gives you five monkeys: smart and secretive as a macaque, healthy and happy as a horse mon