Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue in run mongostat for auth enabled mongodb

I just implemented auth for mongodb, There is a user ‘admin’ in db ‘admin’ and ‘appadmin’ in db ‘mydb’ all working fine. below are my db auth settings:

use admin
db.auth(‘’, ‘’)
db.getUsers()
[
    {
        "_id" : "admin.admin",
        "user" : "admin",
        "db" : "admin",
        "roles" : [
            {
                "role" : "userAdminAnyDatabase",
                "db" : "admin"
            },
            {
                "role" : "clusterMonitor",
                "db" : "admin"
            }
        ]
    }
]


use mydb
db.auth()
db.getUsers()

    {
        "_id" : "mydb.appadmin",
        "user" : "mydb",
        "db" : "mydb",
        "roles" : [
            {
                "role" : "readWrite",
                "db" : "mydb"
            },
            {
                "role" : "userAdmin",
                "db" : "mydb"
            }
        ]
    }
].

If I run the following,

mongostat --username=admin --password=mypassword  --authenticationDatabase=admin
insert query update delete getmore command flushes mapped  vsize   res faults qr|qw ar|aw netIn netOut conn     time
    *0    *0     *0     *0       0     1|0       0 240.0M 678.0M 91.0M      0   0|0   0|0   79b    10k    1 11:49:18
    *0    *0     *0     *0       0     1|0       0 240.0M 678.0M 91.0M      0   0|0   0|0   79b    10k    1 11:49:19
    *0    *0     *0     *0       0     1|0       0 240.0M 678.0M 91.0M      0   0|0   0|0   79b    10k    1 11:49:20

But when I run

* mongostat --username=appadmin --password=mypassword  --authenticationDatabase=mydb

        Failed: not authorized on admin to execute command { serverStatus: 1, recordStats: 0 },

So I tried to add role ‘clusterMonitor’ in mydb.

db.updateUser(“appadmin”, {roles: [{role: "readWrite", db: “mydb”}, {role: "userAdmin", db: “mydb”}, {role: "clusterMonitor", db: “mydb”}]})
E QUERY    Error: Updating user failed: No role named clusterMonitor@mydb.

What is the best way to do mongostat in a auth enabled mongoldb? Please help me to fix the issue or suggest best auth settings. Note: my mongodb version 3.0.6

like image 969
Jisson Avatar asked Oct 07 '15 12:10

Jisson


People also ask

How do I use Mongostat?

To use mongostat , keep your current MongoDB shell connection, and open another terminal window to access your server shell. In the second server shell, run the mongostat command: mongostat -u AdminSammy --authenticationDatabase admin.

Which of the following is use of Mongostat in MongoDB deployment?

mongostat. This command checks the status of all running mongod instances and return counters of database operations. These counters include inserts, queries, updates, deletes, and cursors.

What is Mongotop?

mongotop provides a method to track the amount of time a MongoDB instance mongod spends reading and writing data. mongotop provides statistics on a per-collection level. By default, mongotop returns values every second. Run mongotop from the system command line, not the mongo shell.

Which of the following command can be used to check the size of a collection named posts?

To view the statistics for a collection, including the data size, use the db. collection. stats() method from the mongo shell. Q 22 - Which of the following commands can cause the database to be locked?


1 Answers

finally I got the solution, I add more roles to admin db,

use admin
db.getUsers()

    {
        "_id" : "admin.admin",
        "user" : "admin",
        "db" : "admin",
        "roles" : [
            {
                "role" : "userAdminAnyDatabase",
                "db" : "admin"
            },
            {
                "role" : "readWriteAnyDatabase",
                "db" : "admin"
            },
            {
                "role" : "dbAdminAnyDatabase",
                "db" : "admin"
            },
            {
                "role" : "clusterAdmin",
                "db" : "admin"
            },
            {
                "role" : "clusterMonitor",
                "db" : "admin"
            }
        ]
    }
]

and run mongostat --username=admin --password=mypassword --authenticationDatabase=admin, fix the issues

like image 85
Jisson Avatar answered Nov 15 '22 05:11

Jisson