測(cè)試的時(shí)候在amin庫(kù)下面執(zhí)行了db.dropAllUsers()操作,然后所有管理員用戶都沒有了,執(zhí)行什么操作都提示Error: not authorized on admin to execute command...
下面來介紹一下出現(xiàn)這種情況要如何處理

克拉瑪依ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
先來看一下當(dāng)前mongo實(shí)例的配置文件:
cat /etc/mongo.cnf
systemLog:
destination: file
logAppend: true
path: /data/mongodata/log/mongo.log
logRotate: rename
timeStampFormat: ctime
quiet: true
storage:
dbPath: /data/mongodata/data
journal:
enabled: true
commitIntervalMs: 100
directoryPerDB: true
syncPeriodSecs: 60
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 20
journalCompressor: snappy
indexConfig:
prefixCompression: true
processManagement:
fork: true
pidFilePath: /data/mongodata/data/mongo.pid
net:
port: 27017
bindIp: 0.0.0.0
maxIncomingConnections: 3000
wireObjectCheck: true
ipv6: false
unixDomainSocket:
enabled: false
security:
keyFile: /data/mongodata/data/keyfile
authorization: enabled
operationProfiling:
slowOpThresholdMs: 100
mode: slowOp 嘗試1:改配置文件(失敗)
在網(wǎng)上搜索后得知啟動(dòng)mongod服務(wù)的時(shí)候不指定--auth參數(shù)就可以了,看了mongod的服務(wù)啟動(dòng)腳本是以mongod -f /etc/mongo.cnf的方式啟動(dòng)的,我在想是不是把配置文件認(rèn)證相關(guān)的配置禁掉就可以了,于是把a(bǔ)uthorization: enabled改成authorization: disabled,再重新啟動(dòng)mongod服務(wù),發(fā)現(xiàn)還是需要認(rèn)證
嘗試2:指定參數(shù)啟動(dòng)服務(wù)(成功)
改配置文件不行的話就只能指定參數(shù)啟動(dòng)mongod服務(wù)了,當(dāng)直接執(zhí)行mongod --port 27017 --dbpath /data/mongodata/data 時(shí)報(bào)錯(cuò):
Detected data files in /data/mongodata/data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
然后根據(jù)配置文件加上storage engine為wiredTiger的相關(guān)參數(shù),再次啟動(dòng)mongod --port 27017 --dbpath /data/mongodata/data --storageEngine wiredTiger --wiredTigerCacheSizeGB 20 --wiredTigerJournalCompressor snappy,發(fā)現(xiàn)還有報(bào)錯(cuò):
exception in initAndListen: 72 Requested option conflicts with current storage engine option for directoryPerDB; you requested false but the current server storage is already set to true and cannot be changed, terminating,
根據(jù)報(bào)錯(cuò)提示再加上directoryperdb的參數(shù)啟動(dòng):mongod --port 27017 --dbpath /data/mongodata/data --storageEngine wiredTiger --wiredTigerCacheSizeGB 20 --wiredTigerJournalCompressor snappy --wiredTigerIndexPrefixCompression 1 --directoryperdb,最后重啟成功,現(xiàn)在就可以在amdin庫(kù)授權(quán)root用戶了
提示:
1,具體要帶哪些參數(shù)要根據(jù)配置文件來調(diào)整,如果指定的參數(shù)和實(shí)例原先的參數(shù)有沖突的話會(huì)起不來,不過不要緊,MongoDB會(huì)有詳細(xì)的日志輸出,根據(jù)提示調(diào)整即可
2,如果mongod服務(wù)啟動(dòng)腳本不是用root用戶來啟的,則最好切到對(duì)應(yīng)的帳號(hào)再啟動(dòng),不然授權(quán)完后再次用腳本啟時(shí)會(huì)報(bào)Permission denied的錯(cuò)誤
!!注意:db.dropAllUsers()為高危操作,千萬不要在生產(chǎn)環(huán)境執(zhí)行
新聞標(biāo)題:MongoDB在admin庫(kù)下面執(zhí)行了db.dropAllUsers()導(dǎo)致沒有管理權(quán)限要如何處理
文章URL:http://chinadenli.net/article36/jpsdpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、App開發(fā)、網(wǎng)站維護(hù)、網(wǎng)站策劃、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)