Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ubuntu apt-get install Mongodb

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Recently, we are going to do a project with mongodb, and the environment is Ubuntu.

Switch to root user

Apt-get update update source, which uses Aliyun's source, which feels fast and easy to use.

Apt-get mongodb

Check to see if the process starts

Mongo View version

Where is mongodb installed?

[1] the main program directory of mongodb is mongod under / usr/bin/

[2] location of mongo's log log / var/log/mongodb/mongodb.log

[3] mongo profile location / etc/mongodb.conf

Need to create data/db under / var/lib/mongdb/

Dbpath location / var/lib/mongdb/data/db

Logpath location / var/log/mongdb/mongdb.log

Start mongdb

/ usr/bin/mongod-dbpath=/var/lib/mongodb/data/db-auth-port 27017

-logpath=/var/log/mongodb/mogodb.log-logappend

Cd / usr/bin

. / mongod-dbpath=/var/lib/mongodb/data/db-port=27017-auth-logpath=/var/log/mongodb/mogodb.log-logappend

Shut down and start the mongodb service

Sudo service mongodb stop

Sudo service mongodb start

After mongodb starts, you need to open a new window to operate.

Root@ubuntu-bug20114:/# pgrep mongo-l

1384 mongod

Root@ubuntu-bug20114:/# mongo

MongoDB shell version: 2.6.3

Connecting to: test

> show dbs

Admin (empty)

Local 0.078GB

> use admin

Switched to db admin

> db.system.user.find ()

> db.addUser ("super", "super")

WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead

Successfully added user: {"user": "super", "roles": ["root"]}

> db.system.users.find ()

Error: {"$err": "not authorized for query on admin.system.users", "code": 13}

> db.auth ("super", "super")

one

> db.system.users.find ()

{"_ id": "admin.super", "user": "super", "db": "admin", "credentials": {"MONGODB-CR": "9c93023a901c2adf9c7377076b8c963a"}, "roles": [{"role": "root", "db": "admin"}]}

> use test

Switched to db test

> db.addUser ("test", "test")

WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead

Successfully added user: {"user": "test", "roles": ["dbOwner"]}

> db.addUser ("readonly", "readonly", true)

WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead

Successfully added user: {"user": "readonly", "roles": ["read"]}

> use admin

Switched to db admin

> db.system.users.find ()

{"_ id": "admin.super", "user": "super", "db": "admin", "credentials": {"MONGODB-CR": "9c93023a901c2adf9c7377076b8c963a"}, "roles": [{"role": "root", "db": "admin"}]}

{"_ id": "test.test", "user": "test", "db": "test", "credentials": {"MONGODB-CR": "a6de521abefc2fed4f5876855a3484f5"}, "roles": [{"role": "dbOwner", "db": "test"}]}

{"_ id": "test.readonly", "user": "readonly", "db": "test", "credentials": {"MONGODB-CR": "68eda9b099ddb587da03a33273a9f4da"}, "roles": [{"role": "read", "db": "test"}]}

Exit exit

Revalidate user permissions

Error report, no authentication

Refer to this.

Http://blog.itpub.net/22664653/viewspace-715617/

Http://blog.csdn.net/weiwangsisoftstone/article/details/39269373

Http://www.cnblogs.com/zj1111184556/p/3599828.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report