1. Get the latest version https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
2. Unzip and enter the bin directory
Tar zxvf mongodb-linux-x86_64-2.6.1.tgz
Cd/opt/database/mongodb-linux-x86_64-2.6.1/bin
3. Create a directory in which MongoDB needs to hold data and logs before running:
sudo mkdir-p/data/db/
sudo chmod-r 777/data/db/
4.: Start MongoDB Server
./mongod-journal-maxconns=2400-rest
Parameter description:
-journal represents to write a log
-maxconns=2400 on behalf of MongoDB can accept 2,400 TCP connections
-rest delegates can allow clients to access MONGDB server through the rest API
-quiet start can specify quiet mode to reduce the number of items logged, note that using this parameter must specify the log path at the same time, for example:-quiet-logpath/data/db/journal/mongdb.log
5. Modify the maximum number of system open files
ULIMIT-A View current system configuration, default is 1024
Vi/etc/security/limits.conf
Add * Soft nofile 3000* hard Nofile 20000*
Parameter description:
Soft the number of configurations that the soft limit can exceed
Rigid hard limit maximum number of configurations that cannot be exceeded
Nofile represents max number of open files
Ulimit-a after rebooting the system, displayed as 3000
6. Production service startup script
vi/etc/init.d/b Add the following content:
==================================================================================
#!/bin/sh
# # # BEGIN INIT INFO
# Provides:mongodb
# Required-start:
# Required-stop:
# Default-start:2 3 4 5
# default-stop:0 1 6
# Short-description:mongodb
# Description:mongo DB Server
# # # END INIT INFO
. /lib/lsb/init-functions
Program=/opt/database/mongodb-linux-x86_64-2.6.1/bin/mongod
Mongopid= ' Ps-ef | grep ' Mongod ' | Grep-v grep | awk ' {print $} '
Test-x $PROGRAM | | Exit 0
Case "$" in
Start
Log_begin_msg "Starting MongoDB server"
#/usr/bin/mongod--fork--quiet--dbpath/data/db--logpath/var/log/mongodb.log
/opt/database/mongodb-linux-x86_64-2.6.1/bin/mongod--fork--quiet-journal-maxconns=2400-rest--logpath/data/ Db/journal/mongdb.log
Log_end_msg 0
;;
Stop
Log_begin_msg "Stopping MongoDB server"
if [!-Z "$MONGOPID"]; Then
Kill-15 $MONGOPID
Fi
Log_end_msg 0
;;
Status
;;
*)
Log_success_msg "Usage:/etc/init.d/mongodb {start|stop|status}"
Exit 1
Esac
Exit 0
====================================================================================
Edit save complete Change file execution permissions
chmod +x MongoDB
Perform the following command to verify
Service MongoDB Start
Service MongoDB Stop
Landing the Web console http://localhost:28017/
7. Start the login client
Cd/opt/database/mongodb-linux-x86_64-2.6.1/bin
The. MONGO system prompts you to use the test library to enter interactive mode
MongoDB Shell version:2.6.1
Connecting To:test
Welcome to the MongoDB shell.
Execute the following command to save the record
Db.foo.save ({1: "Hello World"})
Execute the following command to view the record
Db.foo.find ();
Display {"_id": ObjectId ("536dd8b41fcff880d315101f"), "1": "Hello World"}
8. Client connection to remote service
./mongo Remoteserverip
9. Create a Database
Use MyDB
The command finishes executing the prompt
Switched to DB MyDB
The installation configuration and basic verification are complete
Resources:
Http://database.51cto.com/art/201109/288576.htm