MongoDB Basic installation and Management Command script summary _mongodb

Source: Internet
Author: User
Tags auth mongodb mongodb server server memory

Installation
1. Linux Installation MongoDB
1.1 Creating Data directories and log files:

Mkdir-p/data/node/
Touch/data/mongodb.log

1.2 Installation MongoDB:

Tar zxf mongodb-linux-x86_64-2.4.9.tgz 
mv Mongodb-linux-x86_64-2.4.9/opt/mongodb
echo "Export path= $PATH:/ Opt/mongodb/bin ">>/etc/profile
source/etc/profile

1.3 Create a new from node profile:

Cat >> ~/.mongodb.conf <<eof
Fork = ture
port = 11000
DBPath =/data/node LogPath
=/data/mongodb.log Logappend
= True
EOF

1.4 Start MongoDB

Mongod--config ~/.mongodb.conf

2. Windows installation MongoDB
2.1 Download and Unzip

Mongodb-win32-x86_64-2008plus-2.4.9.zip

2.2 Adding services

# mongod-f d:\mongodb\mongodb.cfg--servicename mongobd--install

2.3 Start Service

# net start MongoDB 

2.4 Delete Service

# Mongod--remove

2.5 MongoDB Boot configuration file

Mongodb.cfg-->
logpath=d:\data\mongo.log 
dbpath=d:\data
logappend=true
auth=true
# Fork=true

Management
Management MongoDB A fast way to backup or to a multi-node system with replication. The system will automatically complete a variety of configurations.
(1) MongoDB is a normal command-line program, called with Mongod.
(2) MongoDB provides the built-in management interface and monitoring function, easy to integrate with the third party monitoring package.
(3) MongoDB supports BASIC, database-level user authentication, including read-only users, as well as independent administrator privileges.
(4) Backup MongoDB in a variety of ways.

1. Start Stop MongoDB
1.1 Command line Start
command line startup, you can view all options Mongod--help.
(1)--dbpath default value is/data/db/. Each mongod process requires a separate data directory, with three Mongod instances and three separate data directories. When MongoDB starts, it loves to create mongod.lock files in the data directory, preventing other Mongod processes from using the data directory.
(2)--port
Specifies the listening port, defaults to 27017, runs multiple mongod processes, and needs to specify a different port number.
(3)--fork
Run MongoDB with the daemon to create the server process.
(4)--logpath
Specifies the log output path, rather than the output command line, which overwrites the existing file and clears the original journal record. If you want to keep it, you need to use the--logappend option.
(5)--config
Specifies a configuration file that loads various options not specified by the command line.
1.2 Configuration files
MONGOBD supports obtaining configuration information from a file. Specifies that the configuration file can be in the-F or--config option. For example:

# Mongod--config ~/.mongodb.conf
cat > ~/.mongodb.conf <<eof
Port = 10001
Fork = true
LogPath =/data/mongodb.log
dbpath =/data/node2 Logappend
= True
EOF

1.3 Stop MongoDB
Database Shutdown Method:
(1) Kill-2 sigterm or Kill-2 SIGINT, you can safely exit, will wait until the current operation or file pre-allocation, close all open connections, the cached data flushed to disk, and finally stopped.
Cannot kill-9 (SIGKILL), which can result in corrupted data files.
(2) Use admin command {"shutdown": 1}

> Use admin
> Db.shutdownserver (); 

2. Monitoring
2.1 Using the Admin interface
When you start MongoDB, a very basic HTTP server is started, and the server listens for a port 1000 larger than the primary server. The rendered information can be viewed through the shell or through a Web page.
To take advantage of the management interface, you need to turn on rest support with the--reset option. You can also use--nohttpinterface to close the management interface at startup.
2.2 Serverstatus
Serverstatus presents MongoDB internal details, such as the server version, elapsed time, and current number of connections.

MongoDB Shell version:2.4.9
connecting to:127.0.0.1:10001/test
> Db.runcommand ({serverstatus:1})

"GlobalLock" indicates how much time (in microseconds) the global write lock takes on the server. "Mem" contains the amount of data that the server memory maps, the virtual memory and resident memory footprint of the server process;
(1) "Indexcounters" indicates the number of B-trees in disk retrieval and memory retrieval;
(2) "backgroudflushing" means how many times the backstage did Fsync and how much time was spent;
(3) "Opcounters" contains the number of times each of the main operations.
2.3 Mongostat
Mongostat Output Serverstatus provides important information. Output a new row per second, better real-time than the static count you saw earlier. respectively, Insert/s,commands/s,vsize and%locked.
2.4 third-party Plug-ins
support for Nagios,munin,ganglia,cacti mongbdb Plug-ins.

3. Security
MongoDB supports authentication for a single connection.
3.1 Basic knowledge of certification
databases in each MongoDB instance can have many users. After the authentication is turned on, only the database authenticated user can perform the read and write operation.
After authentication, the administrator can read and write all the databases and execute specific management commands.
You need to have an administrator account before you can open a security certificate.

> Use admin
switched to DB admin
> Db.adduser ("Root", "root123");
{
  "user": "Root",
  "readOnly": false,
  "pwd": "81c5bca573e01b632d18a459c6cec418",
  "_id": ObjectId (" 530bd17622cceb4323a2b500 ")
}
> Use test
switched to DB Test
> Db.adduser (" Test_user "," Root123 ", true);
{
  "user": "Test_user",
  "readOnly": True,
  "pwd": "D436badec207e3821abbaf337fcbdd06",
  "_id": ObjectId ("530bd24322cceb4323a2b501")
}

Creating a read-only user in the shell sets the third argument of AddUser to true. Call AddUser () must have write access to the database.
AddUser can not only add new users, but also modify user passwords or read-only status.
Reboot the server, add the--auth option, and turn on the security check.

> Use admin
switched to DB admin
> Db.auth ("Root", "root123");
1

3.2 Working principle of authentication
A database user account is stored as a document in a System.users collection.

> Use admin
switched to DB admin
> Db.system.users.find ();
{"_id": ObjectId ("530bd17622cceb4323a2b500"), "user": "Root", "readOnly": false, "pwd": "81c5bca573e01b632d18a459c6ce c418 "}

can perform

Db.system.users.remove ({"User": "Root"});

Delete account number.
User authentication, the server will authenticate and connection binding to track authentication.
3.3 Other Installation considerations
In addition to the certification there are many options to lock the MongoDB instance. Even with authentication, the MongoDB transport protocol is unencrypted. For encryption, you need to use a SHH tunnel or similar encryption between the client and the server.
The MongoDB server is recommended for the firewall or intranet, but if you need to be externally accessible, use the--BINDIP option to specify Mongod bindings in the native IP address.
You can use--noscripting to completely disable server-side JavaScript execution.

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.