MongoDB installation Steps under Ubuntu

Source: Internet
Author: User
Tags install mongodb log log

one of the most foolish steps under Ubuntu ( below are the actions under the root user ):

MongoDB installation is very simple, no need to download the source files, can be installed directly with the Apt-get command.
Open terminal and enter the following command:

sudo apt-get install mongodb

2. You should automatically run the Mongod program after you install it, and see if the process has started with "pgrep mongo-l ".

3. Enter "MONGO"in terminal, then enter the database

(over)

Here's how to start your own MongoDB program.

Two. Restart the system after the MONGO program to manually restart itself, the steps are as follows:

1. Run the "locate MONGO" command to see where the system defaults to the MONGO, which focuses on three things.

(1) One is called "mongod" The location of the program (he is equivalent to the MONGO database server, need to always run in the background, my path:/usr/bin/mongod);

(2) One is the location of the log log file of the MONGO database (log log file to see the specific file name, the specific usage is described in the following, my path:/var/log/mongodb/mongodb.log);

(3) One is the location of the log log of the MONGO (my path:/var/log/mongodb/mongodb.log).

2. First enter the directory where the Mongod is located (/usr/bin/mongod), and then run "./mongod--dbpath/var/lib/mongodb/--logpath/var/log/mongodb /mongodb.log--logappend &"

--dbpath: Specifies which folder the MONGO database file is in

--logpath: Specify the log log of the MONGO, here log must be specified to the specific file name

--logappend: indicates that the log is written in an additional way, with the default overwrite of the previous file

&: indicates that the program is running in the background

Note: If the system is not properly shut down, so that the boot will be error, because MongoDB is automatically locked, it is necessary to enter the MongoDB database file directory (/var/lib/mongodb/), delete the directory Mongodb.lock file, and then do the above.

After installation, you can write a C + + program to do the corresponding database operations, write a simple connection MONGO C + + program and if the resolution of MONGO dynamic library link failure is described in another article.

Close/Start

sudo service MongoDB stop sudo service mongodb start

To set the database connection password:

Creating a folder with directory: data/db

  Close the existing service.

sudo service MongoDB stop

  Restart Service

$ mongod–auth

  Create a connected user

$ MONGO

>use Admin

Switched to DB admin

>db.adduser ("Root", "1983")

  Close the Service ( Command window launched directly in Mongod "CTRL + C")

Restart Service:

$: Mongod–auth

  To see if validation starts:,

$ MONGO

MongoDB Shell version:2.0.4

Connecting To:test

>use Admin

Switched to DB admin

>show Collections

Fri Mar 09:07:08 uncaught exception:error: {

"$err": "Unauthorized db:admin lock Type:-1 client:127.0.0.1",

"Code": 10057

}

  There is a hint link error.

for user authentication:

>db.auth ("Root", "1983")

1

  Re-view to view datasets

>show Collections

System.indexes

System.users

To set up a client connection:

The default installation allows only 127.0.0.1 IP connections.

  The following records need to be modified/etc/mongodb.conf comments:

Open File:

$ sudo gedit/etc/mongodb.conf

  Note Record:

#bind_ip = 0.0.0.0

MongoDB Remote Access configuration (Ubuntu)

1, first modify the MongoDB configuration file to listen to all the external network IP, if not, the connection will definitely have an exception
Edit file: vi/etc/mongodb.conf
The revised content is as follows:
Bind_ip = 0.0.0.0 or #bind_ip 127.0.0.1
Port = 27017
Auth=true (add account, password Authentication)
2,/etc/init.d/mongodb restart
3. Connection
#本地连接
/usr/local/mongodb/bin/mongo
#远程连接
/usr/local/mongodb/bin/mongo127.0.0.1/admin-u username-p Password
4. Add user access rights to a database
Db.adduser (' user ', ' pwd ')
Db.auth (' user ', ' pwd ')
5. Delete users
Db.removeuser (' username ')

MongoDB installation Steps under Ubuntu

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.