Ubuntu installation MongoDB (non-apt-get mode)

Source: Internet
Author: User
Tags chmod mongodb mongodb server
Download MongoDB's latest Linux release and put it in any directory (for example, in the/usr directory)
Unzip to perform


Tar zxvf mongodb-linux-x86_64-2.x.x.tgz
Cd/usr/mongodb-linux-x86_64-2.x.x/bin

Create a link

Ln-s/usr/mongodb-linux-x86_64-2.x.x MongoDB
However, before running, you need to create a directory of data and logs that MongoDB needs:
sudo mkdir-p/data/db/journal
sudo chmod-r 777/data/db/
The MongoDB server,-journal represents the Write log,-maxconns=2400 represents MongoDB can accept 2,400 TCP connections, and the-rest representative can allow clients to access MONGDB server through the rest API.
./mongod-journal-maxconns=2400-rest
You can also use parameter-quiet to start the number of items that can specify quiet mode to reduce records, and note that you must specify log paths at the same time, such as:
-quiet-logpath/data/db/journal/mongdb.log
Related Instructions

When the service program starts, the terminal displays some information, such as:
Wed Aug 16:40:03 [Initandlisten] MongoDB starting:pid=2410 port=27017 dbpath=/data/db/64-bit
Wed Aug 16:40:03 [initandlisten] db version v2.4.9, pdfile version 4.5
Wed Aug 16:40:03 [Initandlisten] git version:c206d77e94bc3b65c76681df5a6b605f68a2de05
Wed Aug 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=1_41
Wed Aug 16:40:03 [Initandlisten] Journal Dir=/data/db/journal
Wed Aug 16:40:03 [Initandlisten] recover:no journal files present, no recovery needed
Wed Aug 16:40:06 [Initandlisten] preallocateisfaster=true 33.84
Wed Aug 16:40:08 [Initandlisten] preallocateisfaster=true 36.84
Wed Aug 16:40:11 [Initandlisten] preallocateisfaster=true 37.48
Wed Aug 16:40:11 [Initandlisten] preallocating a journal file/data/db/journal/prealloc.0
Wed Aug 16:41:03 [Initandlisten] preallocating a journal file/data/db/journal/prealloc.1
Wed Aug 16:41:55 [Initandlisten] preallocating a journal File/data/db/journal/prealloc.2
Wed Aug 16:42:48 [Initandlisten] waiting for connections on port 27017
Wed Aug 16:42:48 [Initandlisten]-maxconns too high, can only handle 819
Wed Aug 16:42:48 [websvr] Web admin interface listening on port 28017
Wed Aug 16:42:48 [dur] LSN set 0
Wed Aug 16:43:03 [dur] LSN set 14440
Wed Aug 16:44:03 [dur] LSN set 74050
Wed Aug 16:45:03 [dur] LSN set 133660
Wed Aug 16:46:03 [dur] LSN set 193270
Wed Aug 16:47:03 [dur] LSN set 252880
Wed Aug 16:48:03 [dur] LSN set 312490
Wed Aug 16:49:03 [dur] LSN set 372110
Wed Aug 16:50:03 [dur] LSN set 431720
Wed Aug 16:51:03 [dur] LSN set 491330
Wed Aug 16:52:03 [dur] LSN set 550940
Wed Aug 16:53:03 [dur] LSN set 610550

We can see the process ID, the TCP port number listening to, and the Web Administrator port number. You can also see the directory where the data files and log files are located. And it is suggested that the maximum number of connections is not up to 2400.
to modify the maximum number of connections allowed by the system

The maximum number of connections above is due to the Linux system default one process maximum file open number 1024, with the ulimit-a command check, you can see the following line:
Open files (-N) 1024


Modify the/etc/security/limits.conf configuration file.
Using commands: sudo gedit/etc/security/limits.conf
Add in File
* Soft Nofile 3000
* Hard Nofile 20000
Root Soft Nofile 3000
Root Hard Nofile 20000
* Indicates that the configuration is valid for all users and that the root user has two extra lines.
Hard limits are usually the number of files that can be opened at the same time based on system hardware resource conditions (primarily system memory), and soft limits are further restricted on this basis. The number of soft limits is therefore lower than the hard limit.
Nofile represents max number of open files
Restart your computer, and then use the ULIMIT-A command to view:
Open files (-N) 3000
has been in force. Start MongoDB server now, problem solving


Now there's a simpler way to set it up in the boot script and refer to the next section. Setting up boot

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


#!/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 ser Ver  
### End INIT INFO  
   
./lib/lsb/init-functions  
   
program=/usr/mongodb/bin/mongod  
mongopid= ' PS- EF | grep ' Mongod ' | Grep-v grep | awk ' {print $} '  
   
Test-x $PROGRAM | | Exit 0 Case  
   
"  
  ulimit-n" 
     3000  
     log_begin_msg "St arting MongoDB Server "   
     $PROGRAM--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


Please note that the sudo chmod +x/etc/init.d/mongodb command allows the script to be executed
Then run the following command to register the boot script:
UPDATE-RC.D MongoDB Defaults
Adding system startup For/etc/init.d/mongodb ...
/etc/rc0.d/k20mongodb->. /init.d/mongodb
/etc/rc1.d/k20mongodb->. /init.d/mongodb
/etc/rc6.d/k20mongodb->. /init.d/mongodb
/etc/rc2.d/s20mongodb->. /init.d/mongodb
/etc/rc3.d/s20mongodb->. /init.d/mongodb
/etc/rc4.d/s20mongodb->. /init.d/mongodb
/etc/rc5.d/s20mongodb->. /init.d/mongodb

You can also use Update-rc.d-f MongoDB remove
Reboot, through Ps-def | The grep mongod can view the service process from the start, and then you can turn the service off/start with the following command

sudo service MongoDB stop
sudo service MongoDB start
Client Logon Server

Boot log as above, server-side startup as above, now we are testing the servers in another terminal for normal.
Enter/usr/local/mongodb-linux-x86_64-2.0.2/bin, execute./mongo
Appear
MongoDB Shell version:2.0.2
Connecting To:test
Execute Db.foo.save ({1: "Hello World"})
Then look for Db.foo.find ();
See {"_id": ObjectId ("4e4b395986738efa2d0718b9"), "1": "Hello World"}
Execute here Congratulations, successfully installed the MongoDB

You can also connect to a remote MongoDB server in this way, with a default port of 27017, such as
./mongo 192.168.30.25
Creating a database

If you do not have a mydb database, use the command in the client:
Use MyDB
The MyDB database is created and the current database is switched to MyDB.
The show DBS does not display the database name at this time. Use the Db.stats () command to check the current database state. Standard inspection Process

1. First check ulimit-a
To see if open files (-N) are a set value

If you are setting up in a boot script, you should check it with the following 4 steps. This step can be ignored.


2.ps-def | grep Mongod
To see if the service starts
3.cd/data/db/journal/
Cat Mongdb.log
To see if the server is correct
4. Enter http://192.168.1.199:28017
See if the server is starting up properly
5. Enter/usr/mongodb/bin, execute./mongo
See if you can log in

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.