mongoDB因root啟動關閉資料庫導致mongo普通使用者無法啟動
最近,使用mongoDB資料庫時,偶然使用了root啟停資料庫,導致後來mongo使用者無法啟動資料庫,報許可權拒絕,但是root可以正常啟停mongoDB資料庫。
使用ROOT啟動資料庫
[root@mongo data]# mongod --dbpath=$MONGO_DATA --logpath=$MONGO_LOGS/mongodb.log --logappend&
[1] 3526
檢視mongoDB程式狀態
[root@mongo data]# ps -ef|grep mongo
root 3526 46565 17 18:32 pts/2 00:00:01 mongod --dbpath=/opt/mongo/data --logpath=/opt/mongo/logs/mongodb.log --logappend
root 3546 46565 0 18:32 pts/2 00:00:00 grep mongo
root 46639 46622 0 Jun26 pts/5 00:00:00 su - mongo
mongo 46640 46639
0 Jun26 pts/5 00:00:00 –bash
操作mongoDB資料庫
[root@mongo data]# mongo
MongoDB shell version: 3.2.7
connecting to: test
Server has startup warnings:
2016-06-27T18:32:12.881-0700 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-06-27T18:32:12.881-0700 I CONTROL [initandlisten]
> use zhul
switched to db zhul
> db.zhul.insert({"username":"test","id":123456});
WriteResult({ "nInserted" : 1 })
> db.zhul.findOne({"username":"test"});
{
"_id" : ObjectId("5771d3d3a3eb04b5a2150f87"),
"username" : "test",
"id" : 123456
}
> exit
bye
[root@mongo data]#
ROOT使用者關閉mongoDB資料庫
[root@mongo data]# mongo
MongoDB shell version: 3.2.7
connecting to: test
Server has startup warnings:
2016-06-27T18:32:12.881-0700 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-06-27T18:32:12.881-0700 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
2016-06-27T18:40:31.458-0700 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-06-27T18:40:31.459-0700 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-06-27T18:40:31.459-0700 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
>
切換至mongo使用者啟動資料庫,發現啟動後,程式立即退出
[mongo@mongo logs]$ mongod --dbpath=$MONGO_DATA --logpath=/opt/mongo/logs/mongodb.log --logappend&
[1] 3725
[mongo@mongo logs]$
[1]+ Exit 100 mongod --dbpath=$MONGO_DATA --logpath=/opt/mongo/logs/mongodb.log --logappend
[mongo@mongo logs]$
檢視mogodb.log,提示許可權拒絕
2016-06-27T18:41:32.979-0700 I CONTROL [initandlisten] distarch: x86_64
2016-06-27T18:41:32.979-0700 I CONTROL [initandlisten] target_arch: x86_64
2016-06-27T18:41:32.979-0700 I CONTROL [initandlisten] options: { storage: { dbPath: "/opt/mongo/data" }, systemLog: { destination: "file", logAppend: true, path: "/opt/mongo/logs/mongodb.log" } }
2016-06-27T18:41:32.999-0700 I - [initandlisten] Detected data files in /opt/mongo/data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-06-27T18:41:32.999-0700 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-06-27T18:41:33.024-0700 E STORAGE [initandlisten] WiredTiger (13) [1467078093:24444][3725:0x7fe458275c80], txn-recover: /opt/mongo/data/journal/WiredTigerLog.0000000021: handle-open: open: Permission denied
2016-06-27T18:41:33.024-0700 E STORAGE [initandlisten] WiredTiger (13) [1467078093:24486][3725:0x7fe458275c80], txn-recover: Recovery failed: Permission denied
2016-06-27T18:41:33.033-0700 I - [initandlisten] Assertion: 28595:13: Permission denied
2016-06-27T18:41:33.033-0700 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating
2016-06-27T18:41:33.033-0700 I CONTROL [initandlisten] dbexit: rc: 100
網上有人說,啟動資料庫,需要恢復時會在tmp目錄下生成一個mongodb-27017.sock檔案,刪除重新啟動即可,但是事實證明不是這個檔案導致的。
Tmp目錄下確實生成了.sock檔案
[root@mongo tmp]# ls -l mongodb-27017.sock
srwx------. 1 mongo mongo 0 Jun 27 18:41 mongodb-27017.sock
[root@mongo tmp]#
ROOT刪除之
[root@mongo tmp]# rm -rf mongodb-27017.sock
[root@mongo tmp]#
再次使用mongo使用者啟動mongoDB,發現問題依舊
[mongo@mongo logs]$ mongod --dbpath=$MONGO_DATA --logpath=/opt/mongo/logs/mongodb.log --logappend&
[1] 3835
[mongo@mongo logs]$
[1]+ Exit 100 mongod --dbpath=$MONGO_DATA --logpath=/opt/mongo/logs/mongodb.log --logappend
[mongo@mongo logs]$
根據日誌報錯提示WiredTiger許可權拒絕,是不是有關wiredtiger檔案許可權問題,檢視/opt/mongo/data、/opt/mongo/data/ journal檔案下檔案,發現確實有檔案許可權被改成了root:
[root@mongo data]# ls -l Wired*
-rw-rw-r--. 1 mongo mongo 46 Jun 11 01:31 WiredTiger
-rw-r--r--. 1 root root 4096 Jun 27 18:40 WiredTigerLAS.wt
-rw-rw-r--. 1 mongo mongo 21 Jun 11 01:31 WiredTiger.lock
-rw-r--r--. 1 root root 927 Jun 27 18:40 WiredTiger.turtle
-rw-rw-r--. 1 mongo mongo 94208 Jun 27 18:48 WiredTiger.wt
修改許可權:
[root@mongo data]# chown mongo:mongo WiredTigerLAS.wt
[root@mongo data]# chown mongo:mongo WiredTiger.turtle
[root@mongo data]# chmod 664 WiredTigerLAS.wt
[root@mongo data]# chmod 664 WiredTiger.turtle
[root@mongo data]# ls -l Wired*
-rw-rw-r--. 1 mongo mongo 46 Jun 11 01:31 WiredTiger
-rw-rw-r--. 1 mongo mongo 4096 Jun 27 18:40 WiredTigerLAS.wt
-rw-rw-r--. 1 mongo mongo 21 Jun 11 01:31 WiredTiger.lock
-rw-rw-r--. 1 mongo mongo 927 Jun 27 18:40 WiredTiger.turtle
-rw-rw-r--. 1 mongo mongo 94208 Jun 27 18:54 WiredTiger.wt
[root@mongo journal]# ls -l
total 409624
-rw-r--r--. 1 root root 6912 Jun 27 18:40 WiredTigerLog.0000000021
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:41 WiredTigerLog.0000000022
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:48 WiredTigerLog.0000000023
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:54 WiredTigerLog.0000000024
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:55 WiredTigerLog.0000000025
[root@mongo journal]# chown mongo:mongo WiredTigerLog.0000000021
[root@mongo journal]# chmod 664 WiredTigerLog.0000000021
[root@mongo journal]# ls -l
total 409624
-rw-rw-r--. 1 mongo mongo 6912 Jun 27 18:40 WiredTigerLog.0000000021
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:41 WiredTigerLog.0000000022
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:48 WiredTigerLog.0000000023
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:54 WiredTigerLog.0000000024
-rw-rw-r--. 1 mongo mongo 104857728 Jun 27 18:55 WiredTigerLog.0000000025
[root@mongo journal]#
再次使用mongo使用者啟動資料庫,成功!
[mongo@mongo logs]$ mongod --dbpath=$MONGO_DATA --logpath=/opt/mongo/logs/mongodb.log --logappend&
[1] 4073
[mongo@mongo logs]$
[mongo@mongo logs]$
[mongo@mongo logs]$
[mongo@mongo logs]$
[mongo@mongo logs]$
[mongo@mongo logs]$ tail -20 mongodb.log
2016-06-27T18:59:51.233-0700 I CONTROL [main] ***** SERVER RESTARTED *****
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] MongoDB starting : pid=4073 port=27017 dbpath=/opt/mongo/data 64-bit host=mongo
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] db version v3.2.7
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] modules: none
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] build environment:
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] distarch: x86_64
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] target_arch: x86_64
2016-06-27T18:59:51.241-0700 I CONTROL [initandlisten] options: { storage: { dbPath: "/opt/mongo/data" }, systemLog: { destination: "file", logAppend: true, path: "/opt/mongo/logs/mongodb.log" } }
2016-06-27T18:59:51.260-0700 I - [initandlisten] Detected data files in /opt/mongo/data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-06-27T18:59:51.261-0700 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-06-27T18:59:53.198-0700 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/opt/mongo/data/diagnostic.data'
2016-06-27T18:59:53.199-0700 I NETWORK [initandlisten] waiting for connections on port 27017
2016-06-27T18:59:53.199-0700 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
[mongo@mongo logs]$ ps -ef|grep mongo
mongo 4073 46640 6 18:59 pts/5 00:00:02 mongod --dbpath=/opt/mongo/data --logpath=/opt/mongo/logs/mongodb.log --logappend
mongo 4105 46640 0 19:00 pts/5 00:00:00 ps -ef
mongo 4106 46640 0 19:00 pts/5 00:00:00 grep mongo
root 46639 46622 0 Jun26 pts/5 00:00:00 su - mongo
mongo 46640 46639 0 Jun26 pts/5 00:00:00 -bash
[mongo@mongo logs]$ mongo
MongoDB shell version: 3.2.7
connecting to: test
>
問題成功解決!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29357786/viewspace-2121094/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 神奇的DEBUG:因為異常導致MongoDB容器無法啟動MongoDB
- 記一次ORA-01102導致資料庫例項無法啟動案例資料庫
- SQL Server 因設定最大記憶體過小導致無法啟動SQLServer記憶體
- 應用使用JNDI,資料庫無法連線,導致的程序無法啟動問題處理資料庫
- MySQL 5.6因為OOM導致資料庫重啟MySqlOOM資料庫
- MYSQL資料庫服務無法啟動MySql資料庫
- ORACLE DSG資料同步軟體程式導致資料庫無法正常關閉Oracle資料庫
- 【資料庫資料恢復】無法啟動MongoDB服務的資料恢復案例資料庫資料恢復MongoDB
- 資料庫資料恢復——Windows無法啟動MongoDB服務的資料恢復案例資料庫資料恢復WindowsMongoDB
- db2資料庫的啟動和關閉DB2資料庫
- Oracle RAC啟動因CTSS導致的異常Oracle
- Linux下的MongoDB安裝&啟動&關閉LinuxMongoDB
- Oracle sysman.mgmt_jobs導致資料庫自動重啟Oracle資料庫
- openguass 3.1.0 資料庫啟動,關閉,狀態檢查資料庫
- mac 啟動mongoMacGo
- Oracle日常問題-資料庫無法啟動(案例二)Oracle資料庫
- Oracle日常問題處理-資料庫無法啟動Oracle資料庫
- Oracle 12.2應用PSU後資料庫無法啟動Oracle資料庫
- 達夢資料庫dmap服務無法正常啟動資料庫
- asm磁碟組依賴導致資料庫自啟動報錯ASM資料庫
- oracle資料庫的啟動關閉與各種服務Oracle資料庫
- 【案例】Oracle報錯ORA-01194 ORA-01110 由於資料庫SCN不一致導致無法啟動Oracle資料庫
- 解決一次gitlab因異常關機導致啟動失敗Gitlab
- 【北亞資料恢復】異常斷電導致linux伺服器無法啟動,資料庫損壞的資料恢復資料恢復Linux伺服器資料庫
- MySQL無法啟動重啟竟是因為改了Linux主機名MySqlLinux
- MongoDB資料庫因安全漏洞,導致Family Locator洩露二十多萬名使用者資料MongoDB資料庫
- @Transactional開啟事務導致AbstractRoutingDataSource動態資料來源無法切換的解決方案
- 3 啟動和關閉
- 3.1.3 關於資料庫服務自動啟動資料庫
- centos下nginx啟動、重啟、關閉CentOSNginx
- 伺服器意外斷電導致無法重啟資料恢復伺服器資料恢復
- 關於XAMPP中Apache和Mysql因埠占用無法啟動的問題ApacheMySql
- 3.1.5.1 關於啟動資料庫例項資料庫
- mysql因為事務日誌問題無法啟動MySql
- 3.1.5.8 隨系統啟動自動啟動資料庫資料庫
- mongodb關閉資料庫例項MongoDB資料庫
- win10快速啟動關不掉bug怎麼解決_win10快速啟動無法關閉如何修復Win10
- 3.1 啟動資料庫資料庫
- 啟動MySql資料庫MySql資料庫