Mongod common operations on Linux

Source: Internet
Author: User
  1. Run the following command to view service startup parameters:
Mongod -- help or mongod-H
  1. Other Command Parameters
* Basic configuration
-- Quiet # Quiet output -- Port Arg # specify the service port number. The default port is 27017 -- bind_ip Arg # bind the service IP address. If 127.0.0.1 is bound, only local access is allowed, do not specify the default local IP -- logpath Arg # specify the MongoDB log file. Note that the specified file is not the directory -- logappend # Use the append method to write the log -- pidfilepath Arg # The complete path of the PID file, if this parameter is not set, the complete path of the private key of the PID file -- Keyfile Arg # cluster is not available. It is only valid for the replica set architecture -- unixsocketprefix Arg # directory replaced by UNIX domain socket, (/tmp by default) -- fork # Run MongoDB as a daemon, create a server process -- auth # enable verification -- CPU # periodically Display CPU utilization and iowait -- dbpath Arg # specify the database path -- diaglog Arg # diaglog option 0 = off 1 = W 2 = R 3 = both 7 = W + some reads -- directoryperdb # Set that each database will be saved in a separate directory -- journal # enable log options, mongoDB data operations will be written to the files in the journal folder -- journaloptions Arg # enable log diagnostic options -- IPv6 # enable IPv6 options -- jsonp # Allow access through HTTP in the form of jsonp (with security impact) -- maxconns Arg # maximum number of simultaneous connections default 2000 -- noauth # do not enable verification -- nohttpinterface # disable HTTP interface, disable access to port 27018 by default -- noprealloc # disable data file pre-allocation (often affecting performance) -- noscripting # disable the script engine -- notablescan # Do Not Allow table scanning -- nounixsocket # disable UNIX socket listening -- nssize Arg (= 16) # Set the database. NS file size (MB) -- objcheck # check the validity of the received customer data. -- profile Arg # file parameter 0 = off 1 = slow, 2 = all -- quota # limit the number of files in each database. The default value is 8 -- quotafiles Arg # number of files allower per dB, requires -- quota -- rest # enable simple rest API -- repair # Fix all databases run repair on all DBS -- repairpath Arg # Fix the directory of files generated by the database, the default directory name is dbpath -- slowms Arg (= 100) # value of slow for profile and console log -- smallfiles # use a small default file -- syncdelay Arg (= 60) # data written to the disk in seconds (0 = never, not recommended) -- sysinfo # print some diagnostic system information -- upgrade # If you need to upgrade the database
* Replicaton Parameters
-- Fastsync # enable the slave database replication service from a dbpath. The database in this dbpath is a snapshot of the master database and can be used to quickly enable synchronization -- autoresync # If the data synchronization between the slave database and the master database is much worse, automatic Re-synchronization, -- oplogsize Arg # Set the oplog size (MB)
* Master/Slave Parameters
-- Master # master database mode -- slave # slave database mode -- source Arg # slave database port number -- only Arg # specify a single database copy -- slavedelay Arg # Set the delay time for synchronizing the master database from the slave database * replica set) option:
-- Replset Arg # Set the replica Set Name
* Sharding Option
-- Configsvr # declare that this is the config service of a cluster, the default port is 27019, the default directory/data/configdb -- shardsvr # declare that this is a sharding of a cluster, default port 27018 -- nomoveparanoia # disable storage for movechunk data?

 

# The above parameters can all be written into the mongod. conf configuration file, for example:

Dbpath =/data/MongoDB

Logpath =/data/MongoDB. Log

Logappend = true

Port = 27017

Fork = true

Auth = true

 

Monitoring stat)

Use the specified stat utility to quickly View statistics on a running D instance.

RunUsing stat -- HelpFor help.

Fields:   insert       - # of inserts per second (* means replicated op)   query        - # of queries per second   update       - # of updates per second   delete       - # of deletes per second   getmore      - # of get mores (cursor batch) per second   command      - # of commands per second (on a slave, it's local|replicated)   flushes      - # of fsync flushes per second   mapped       - amount of data mmaped (total data size) megabytes   vsize        - virtual size of process in megabytes   res          - resident size of process in megabytes   faults       - # of pages faults/sec (linux only)   locked       - percent of time in global write lock   idx miss     - percent of btree page misses (sampled)   qr | qw      - queue lengths for clients waiting (read|write)   ar | aw      - active clients (read|write)   netIn        - network traffic in - bits    netOut       - network traffic out - bits   conn         - number of open connections   set          - replica set name    repl         - replication type                     M    - master                    SEC  - secondary                     REC  - recovering                    UNK  - unknown                    SLV  - slave

Multiple servers:

mongostat --host a,b,c

Find all connected servers (added in 1.7.2 ):

mongostat --discover (--host optional)

 

 

Backup (Mongodump
)

Usage:

[Root @ web3 3] # mongodump -- Help

Options:

-- Help produce help message

-V [-- verbose] Be more verbose (include multiple times for more

Verbosity e.g.-vvvvv)

-H [-- Host] Arg Mongo host to connect to ("Left, right" for pairs)

-D [-- dB] Arg database to use

-C [-- collection] Arg collection to use (some commands)

-U [-- username] Arg Username

-P [-- Password] Arg Password

-- Dbpath Arg directly access your D data files in the given path,

Instead of connecting to a challenge D instance-needs

To lock the data directory, so cannot be used if

Your D is currently accessing the same path

-- Directoryperdb if dbpath specified, each dB is in a separate

Directory

-O [-- Out] Arg (= dump) output directory

 

Example:

[Root @ web3 ~] # Mongodump-H 192.168.1.103-D citys-o/backup/mongobak/3

Connected to: 192.168.1.103

Database: citys to/backup/baibak/3/citys

Citys. Building to/backup/baibak/3/citys/building. bson

13650 objects

Citys. system. indexes to/backup/baibak/3/citys/system. Indexes. bson

1 objects

 

The backed up data is binary and has been compressed.

 

Restore (Mongorestore
)

[Root @ web3 3] # mongorestore -- Help

Usage: mongorestore [Options] [directory or filename to restore from]

Options:

-- Help produce help message

-V [-- verbose] Be more verbose (include multiple times for more

Verbosity e.g.-vvvvv)

-H [-- Host] Arg Mongo host to connect to ("Left, right" for pairs)

-D [-- dB] Arg database to use

-C [-- collection] Arg collection to use (some commands)

-U [-- username] Arg Username

-P [-- Password] Arg Password

-- Dbpath Arg directly access your D data files in the given path,

Instead of connecting to a writable D instance-needs

Lock the data directory, so cannot be used if

Your D is currently accessing the same path

-- Directoryperdb if dbpath specified, each dB is in a separate

Directory

-- Drop each collection before import

-- Objcheck validate object before inserting

 

The -- drop parameter can be deleted before the import.

Example:

[Root @ web3 3] # mongorestore-H 127.0.0.1 -- directoryperdb/backup/mongobak/3/

Connected to: 127.0.0.1

/Backup/mongobak/3/citys/building. bson

Going into namespace [Citys. Building]

13667 objects

/Backup/mongobak/3/citys/system. Indexes. bson

Going into namespace [Citys. system. indexes]

1 objects

 

In addition, MongoDB provides the export and Export Import commands to export or import data. The exported data is in JSON format. You can also back up and restore data.

Example:

Export export-D mixi_top_city_prod-C building_45-Q '{"uid": "10832545"}'> pai_10832545.bson

Export Import-D mixi_top_city-C building_45 -- file pai_10832545.bson

 

Close

Kill-9 May cause paralysis

Killall recommended d

 

Repair
First, stop the mongod service, delete MongoDB. log, and back up it.
# Rm-RF/data/MongoDB. Log

Delete MongoDB process files
# Rm-RF/MongoDB/mongod. Lock

Repair
# Mongod -- repair -- dbpath/data/MongoDB -- repairpath/data/mongodb_repair -- Port = 27017

At this time, the MongoDB process will store temporary repair database files in the/MongoDB/repair/directory. The file directory is "$ tmp_repairdatabase_0", so the directory space should be large enough.
The database in the production environment is 100 GB, and the repair takes about three and a half hours. A temporary database file of nearly 30 GB is generated in the "/MongoDB/repair/$ tmp_repairdatabase_0" directory, after the repair is completed, the temporary database files are automatically cleared.

Master-slave Synchronization

Start the master server (192.168.61.200)

./Mongod-dbpath/data/jobcnresume-port 5555-Master

 

Start slave server

./Mongod-slave-source = 192.168.61.200: 5555-dbpath =/data/DB2-port 6666-slavedelay 5

./Mongod-slave-source = 192.168.61.200: 5555-dbpath =/data/db3-port 7777-slavedelay 5

Parameters:

-- Source master server IP address and port

-- Autoresync when the slave server data is not the latest, the master server requests data synchronization.

-- Slavedelay synchronization delay, in seconds

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.