tutorial on installing MongoDB and its start command Mongod in Ubuntu system _mongodb

Source: Internet
Author: User
Tags auth chmod install php install mongodb mongodb server php mongodb unix domain socket port number


Install MongoDB server on Ubuntu



Get the latest version


wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz


Unzip to perform


Tar zxvf mongodb-linux-x86_64-2.0.2.tgz
cd/usr/mongodb-linux-x86_64-2.0.2/bin


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/


Start MongoDB Server


./mongod-journal-maxconns=2400-rest


-journal represents the Write log,-maxconns=2400 represents MongoDB can accept 2,400 TCP connections, and-rest representatives can allow clients to access MONGDB server through the rest API.
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



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



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 server 
### END INIT INFO 
  
. /lib/lsb/init-functions 
  
PROGRAM=/usr/mongodb-linux-x86_64-2.0.2/bin/mongod 
MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'` 
  
test -x $PROGRAM || exit 0 
  
case "$1" in 
 start) 
   ulimit -n 3000 
   log_begin_msg "Starting 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


Perform


Db.foo.save ({1: "Hello World"})


And then find


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
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-linux-x86_64-2.0.2/bin, execute./mongo
See if you can log in



Install PHP MongoDB expansion


sudo apt-get install php5-dev php5-cli php-pear
sudo pecl install MONGO


Join in the php.ini


Extension=mongo.so


MongoDB Start Command mongod parameter description
The main parameters of Mongod are:


  • --quiet # Quiet Output
  • --port ARG # Specify the service port number, default port 27017
  • --BIND_IP ARG # Binding service IP, if binding 127.0.0.1, only native access, do not specify default local all IP
  • --logpath arg # Specifies MONGODB log file, note that the specified file is not a directory
  • --logappend # Use an Append method to write a log
  • The full path of the--pidfilepath ARG # PID file, and if not set, no PID files
  • The full path of the private key of the--keyfile arg # Cluster, valid only for the replica Set schema
  • --unixsocketprefix arg # UNIX domain socket alternate directory, (Default/TMP)
  • --fork # runs MongoDB as a daemon, creating a server process
  • --auth # Enable authentication
  • --CPU # Displays CPU utilization and iowait on a regular basis
  • --dbpath arg # Specify Database path
  • --diaglog arg # diaglog option 0=off 1=w 2=r 3=both 7=w+some reads
  • --DIRECTORYPERDB # Settings Each database will be saved in a separate directory
  • --journal # Enable logging options, MONGODB data operations will be written to files in the Journal folder
  • --journaloptions ARG # Enable logging diagnostics option
  • --ipv6 # Enable IPV6 option
  • --JSONP # allows JSONP to be accessed via HTTP (with security implications)
  • --maxconns ARG # Maximum simultaneous connection number default 2000
  • --noauth # does not enable validation
  • --nohttpinterface # Close HTTP interface, turn off 27018 port access by default
  • --noprealloc # Disables data file pre-allocation (often affecting performance)
  • --noscripting # Disable script engine
  • --notablescan # does not allow table scans
  • --nounixsocket # disables UNIX socket sniffing
  • --nssize Arg (=16) # Set letter database. ns file Size (MB)
  • --objcheck # in receipt of customer data, check the validity,
  • --profile arg # file Parameters 0=off 1=slow, 2=all
  • --quota # Limit the number of files per database, set defaults to 8
  • --quotafiles arg # Number of files Allower per db, requires--quota
  • --rest # Open a simple rest API
  • --repair # Repair All database run repair on all DBS
  • Directory of files generated by the--repairpath arg # Repair library, default to directory name DBPath
  • --slowms Arg (=100) # Value of slow for profile and console log
  • --smallfiles # Use a smaller default file
  • --syncdelay Arg (=60) # Number of seconds to write to disk (0=never, not recommended)
  • --sysinfo # Print Some diagnostic system Information
  • --upgrade # If you need to upgrade the database * Replicaton parameters
  • --fastsync # from a dbpath the Library Replication service is enabled, and the DBPath database is a snapshot of the main library that can be used to quickly enable synchronization
  • --autoresync # If you are synchronizing data from a library to the main library, automatically resynchronize,
  • --oplogsize ARG # Set the size of the Oplog (MB) * Main/from parameter
  • --master # Main Library mode
  • --slave # from Library mode
  • --source Arg # from library port number
  • --only ARG # Specifies a single database replication
  • --slavedelay ARG # Set delay time from library synchronization master Replica set (replica set) option:
  • --replset ARG # set replica set name * Sharding (fragment) option
  • --configsvr # declares that this is a cluster config service, default port 27019, default directory/data/configdb
  • --shardsvr # declares that this is a cluster of fragments, default port 27018
  • --nomoveparanoia # Off bigotry for movechunk data save


# All of the above parameters can be written to the mongod.conf configuration document for example:


DBPath =/data/mongodb
logpath =/data/mongodb/mongodb.log
Logappend = true
port = 27017 Fork
= True
Auth = True





e.g:


Copy Code code as follows:
./mongod-shardsvr-replset Shard1-port 16161-dbpath/data/mongodb/data/shard1a-oplogsize 100-logpath/data/mongodb/l Ogs/shard1a.log-logappend-fork-rest




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.