MongoDB 營運常用操作

來源:互聯網
上載者:User

標籤:dba   ops   mongodb   

MongoDB 營運常用操作  
 
分析方法:    
1. 通過top、free、iostat、iftop等工具查看Linux伺服器平均負載、CPU利用率、IO、記憶體、swap、網路流量等,先定位到壓力源頭。

2. 通過mongostat、mongotop等分析MongoDB讀寫壓力。觀察Page Faults、Connections、Queues等效能指標。

3. 日誌中預設記錄超過100ms的請求,過濾出Overflow查詢,再使用Mtools跟蹤分析MongoDB記錄檔中的慢查詢語句。若是語句問題,可從日誌定位到出現效能問題時刻的源頭語句。

 

常用操作:  
1. 重啟服務    

#service mongod restart

 
2. 追蹤記錄檔分析查詢    

$tail -f /var/log/mongodb/mongod.log

  
3. 分析當前讀寫狀態    

$mongostat -uxucy -p

 
4. 查看資料庫狀態    

>db.serverStatus()

  
5. 查看資料庫連接數    

>db.serverStatus().connections

  
6. 查看複製集狀態    

>rs.status()

 
7. 手動降級執行個體    

>rs.stepDown(30)


8. 查看當前執行活躍查詢    

>db.currentOp();

  
9. 殺掉正在執行的操作    

>db.killOp("shard3:466404288");

  
10. 分析查詢語句的執行計畫    

>db.Product.find({"_id": 10086}).explain().pretty();

 
11. 在後台建立索引    

>db.Product.ensureIndex({ "Category": 1, "Status": 1}, { background: 1 });

 
12. 資料匯出    

$ mongoexport -u xucy -p --authenticationDatabase admin -d DBName -c Product -q ‘{"AddDate":{"$gte":new Date(1445558400000),"$lte":new Date(1445731200000)}}‘ -f "_id,AddDate,Status" -o Product_20151026.json

 
13. 資料匯入    

$mongoimport -h 192.168.1.101 -u xucy -p -d DBName --authenticationDatabase admin -c datacontent datacontent_bak.json

 
14. 資料庫/表備份    

$ mongodump --authenticationDatabase admin -uxucy -p --db DBName -o /disk1/mongobackup/DBName_fullbackup_20150917

  
15. 資料庫/表恢複    

$ mongorestore --authenticationDatabase admin -uxucy -p --db DBName --drop Temp_20150909/DBName/

  
16. 資料庫授權    

>use dbname    >db.createUser(        {          user: "peter",          pwd: "xxxxxxxx",          roles: [             { role: "readWrite", db: "dbname" }          ]        }    )


本文出自 “SQL Server Deep Dives” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1712499

MongoDB 營運常用操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.