Install MongoDB on Ubuntu

Source: Internet
Author: User
Tags install mongodb mongodb server
Install MongoDB on Ubuntu

Get the latest version
Wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.2.0.tgz

Extract and execute

Tar zxvf mongodb-linux-x86_64-2.2.0.tgz
CD/usr/mongodb-linux-x86_64-2.2.0/bin

Create Link

Ln-S/usr/mongodb-linux-x86_64-2.2.0 MongoDB
Before running, you must create a directory for storing data and logs required by MongoDB:
Sudo mkdir-P/data/DB/Journal
Sudo chmod-r 777/data/DB/
Start MongoDB server.-journal indicates that logs are to be written.-maxconns = 2400 indicates that MongoDB can accept 2400 TCP connections.-Rest indicates that the client can access mongdb server through the rest API.
./Mongod-Journal-maxconns = 2400-rest
You can also use the parameter-quiet to start to specify the quiet mode to reduce the number of recorded items. Note that you must specify the Log Path when using this parameter, for example:
-Quiet-logpath/data/DB/Journal/mongdb. Log

Description
After the service program is started, the producer will display some information, such:
Wed Aug 31 16:40:03 [initandlisten] MongoDB starting: pid = 2410 Port = 27017 dbpath =/data/DB/64-bit
Wed Aug 31 16:40:03 [initandlisten] DB version v2.0.2, pdfile version 4.5
Wed Aug 31 16:40:03 [initandlisten] git version: c206d77e94bc3b65c76681df5a6b605f68a2de05
Wed Aug 31 16:40:03 [initandlisten] Build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2. ec2.v1.2. fc8xen #1 SMP Fri Nov 20 17:48:28 est 2009 x86_64 boost_lib_version = listen 41
Wed Aug 31 16:40:03 [initandlisten] journal dir =/data/DB/Journal
Wed Aug 31 16:40:03 [initandlisten] RECOVER: No journal files present, no recovery needed
Wed Aug 31 16:40:06 [initandlisten] preallocateisfaster = true 33.84
Wed Aug 31 16:40:08 [initandlisten] preallocateisfaster = true 36.84
Wed Aug 31 16:40:11 [initandlisten] preallocateisfaster = true 37.48
Wed Aug 31 16:40:11 [initandlisten] preallocating A Journal File/data/DB/Journal/prealloc.0
Wed Aug 31 16:41:03 [initandlisten] preallocating A Journal File/data/DB/Journal/prealloc.1
Wed Aug 31 16:41:55 [initandlisten] preallocating A Journal File/data/DB/Journal/prealloc.2
Wed Aug 31 16:42:48 [initandlisten] waiting for connections on port 27017
Wed Aug 31 16:42:48 [initandlisten]-maxconns too high, can only handle 819
Wed Aug 31 16:42:48 [websvr] Web Admin Interface listening on port 28017
Wed Aug 31 16:42:48 [dur] lsn set 0
Wed Aug 31 16:43:03 [dur] lsn set 14440
Wed Aug 31 16:44:03 [dur] lsn set 74050
Wed Aug 31 16:45:03 [dur] lsn set 133660
Wed Aug 31 16:46:03 [dur] lsn set 193270
Wed Aug 31 16:47:03 [dur] lsn set 252880
Wed Aug 31 16:48:03 [dur] lsn set 312490
Wed Aug 31 16:49:03 [dur] lsn set 372110
Wed Aug 31 16:50:03 [dur] lsn set 431720
Wed Aug 31 16:51:03 [dur] lsn set 491330
Wed Aug 31 16:52:03 [dur] lsn set 550940
Wed Aug 31 16:53:03 [dur] lsn set 610550

We can see the process ID, TCP port number of the listener, and Web Administrator port number. You can also see the directory where the data files and log files are located. The maximum number of connections cannot reach 2400.


Modify the maximum number of connections allowed by the System
The reason for the maximum number of connections above is that by default, the maximum number of files opened by a process in Linux is 1024. Run the ulimit-a command to check whether the following line is displayed:
Open File (-N) 1024


Modify the configuration file/etc/security/limits. conf.
Run sudo gedit/etc/security/limits. conf.
Add
* Soft nofile 3000
* Hard nofile 20000
Root soft nofile 3000
Root hard nofile 20000
* Indicates that the configuration is valid for all users. The root user must add two lines.
The hard limit is generally the maximum number of files that can be opened simultaneously by the system based on the system hardware resources (mainly the system memory). The soft limit is based on this limit. Therefore, the number of Soft limits must be lower than the hard limit.
Nofile indicates Max number of open files
Restart the computer and run the ulimit-a command to view the information:
Open File (-N) 3000
It has already taken effect. Start MongoDB server again now to solve the problem

Now there is a simpler method to set in the boot script. Refer to the next section.

Set startup
Create a script file MongoDB in the/etc/init. d/directory.

  1. #! /Bin/sh
  2. ### Begin init info
  3. # Provides: MongoDB
  4. # Required-start:
  5. # Required-stop:
  6. # Default-start: 2 3 4 5
  7. # Default-stop: 0 1 6
  8. # Short-Description: MongoDB
  9. # Description: Mongo DB Server
  10. ### End init info
  11. ./Lib/LSB/init-Functions
  12. Program =/usr/MongoDB/bin/mongod
  13. Mongopid = 'ps-Ef | grep '0000d' | grep-V grep | awk' {print $2 }''
  14. Test-x $ program | exit 0
  15. Case "$1" in
  16. Start)

 

  1. Ulimit-N 3000
  2. Log_begin_msg "Starting MongoDB server"
  3. $ Program -- fork -- quiet-Journal-maxconns = 2400-rest -- logpath/data/DB/Journal/mongdb. Log
  4. Log_end_msg 0
  5. ;;
  6. Stop)
  7. Log_begin_msg "Stopping MongoDB server"
  8. If [! -Z "$ mongopid"]; then
  9. Kill-15 $ mongopid
  10. Fi
  11. Log_end_msg 0
  12. ;;
  13. Status)
  14. ;;
  15. *)
  16. Log_success_msg "Usage:/etc/init. d/MongoDB {START | stop | status }"
  17. Exit 1
  18. Esac
  19. Exit 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.