{"id":1110,"date":"2018-10-12T02:21:06","date_gmt":"2018-10-12T02:21:06","guid":{"rendered":"http:\/\/www.ipcpu.com\/?p=1110"},"modified":"2018-11-26T02:23:04","modified_gmt":"2018-11-26T02:23:04","slug":"mongodb-oplog","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2018\/10\/mongodb-oplog\/","title":{"rendered":"MongoDB\u5728\u7ebf\u4fee\u6539OPLog\u5927\u5c0f"},"content":{"rendered":"

MongoDB\u5728\u7ebf\u4fee\u6539OPLog\u5927\u5c0f.md
\nMongoDB\u7684OPlog\u662fMongoDB\u7684\u6838\u5fc3\u6570\u636e\uff0c\u526f\u672c\u96c6\u7684\u540c\u6b65\u4e3b\u8981\u9760\u5b83\uff0c\u5f53\u4e1a\u52a1\u7e41\u5fd9\u65f6\uff0cOplog\u7684\u65f6\u95f4\u7a97\u53e3\u53ef\u80fd\u4f1a\u6bd4\u8f83\u5c0f\uff0c\u6bd4\u598210\u5206\u949f\u3001\u534a\u5c0f\u65f6\uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u884c\u7684\uff0c\u81f3\u5c11\u5e94\u8be5\u4fdd\u6301\u57281\u5929\u4ee5\u4e0a\u3002\u8981\u4e0d\u7136\u4e00\u65e6SECONDARY\u51fa\u73b0\u95ee\u9898\uff0c\u60f3\u8981\u6062\u590d\u5c31\u53d8\u6210\u4e86\u4e00\u4ef6\u9ebb\u70e6\u4e8b\u3002<\/p>\n

<\/p>\n

MongoDB\u7684Oplog\u5927\u5c0f\u7684\u4fee\u6539\u4eceMongoDB3.6 \u5f00\u59cb\u5c31\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4fee\u6539\u547d\u4ee4<\/p>\n

\n
db.adminCommand({replSetResizeOplog: 1, size: 16000})<\/code><\/pre>\n<\/div>\n

\u4f46\u662f\uff0c\u5f88\u9057\u61be\uff0c\u6211\u53f8\u8fd8\u505c\u7559\u5728MongoDB3.4\u7684\u7248\u672c\uff0c\u6309\u7167\u5b98\u65b9\u6587\u6863\u53ea\u80fd\u6309\u7167\u5982\u4e0b\u64cd\u4f5c\u6b65\u9aa4\u6765\u4fee\u6539\u4e86\uff1a<\/p>\n

*1. \u5173\u95edmongod\u5b9e\u4f8b\uff1a<\/p>\n

\n
use admin\r\ndb.shutdownServer()<\/code><\/pre>\n<\/div>\n

*2. \u4fee\u6539MongoDB\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u65b0\u542f\u52a8MongoDB<\/p>\n

\n

\u7aef\u53e3\u4fee\u6539\u4e3a\u6ca1\u6709\u526f\u672c\u96c6\u8fde\u63a5\u7684\u7aef\u53e3\uff0c\u6bd4\u598229017
\n \u6ce8\u91ca\u6389replication\u548csharding\u7684\u6240\u6709\u9009\u9879<\/p>\n<\/blockquote>\n

*3.\u5907\u4efdoplog<\/p>\n

\n
mongodump --db local --collection 'oplog.rs' --port 29017 -o shard1<\/code><\/pre>\n<\/div>\n

*4. \u767b\u5f55\u5230\u65b0\u542f\u52a8\u7684MongoDB\u5f00\u59cb\u64cd\u4f5c<\/p>\n

\n
#\u5c06oplog\u6761\u76ee\u5b58\u50a8\u5230temp\r\nuse local\r\ndb.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )\r\ndb.temp.find()\r\n#\u79fb\u9664\u539f\u6709oplog\r\ndb.oplog.rs.drop()\r\n#\u65b0\u5efaoplog\u5e76\u5bfc\u5165\r\ndb.runCommand( { create: \"oplog.rs\", capped: true, size: (20 * 1024 * 1024 * 1024) } )\r\ndb.oplog.rs.save( db.temp.findOne() )\r\n<\/code><\/pre>\n<\/div>\n

*5. \u5173\u95edMongoDB\uff0c\u5e76\u6062\u590d\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542f<\/p>\n

*6. \u767b\u9646\u67e5\u770boplog\u662f\u5426\u6210\u529f\uff0c\u526f\u672c\u96c6\u662f\u5426\u8fde\u63a5\u6210\u529f\u3002<\/p>\n

\u5bf9\u4e8e\u526f\u672c\u96c6\uff0c\u5e94\u8be5\u5148\u64cd\u4f5cSECONDARY\u518d\u64cd\u4f5cPRIMARY\u3002\u6211\u7a0d\u5fae\u4f30\u7b97\u4e86\u4e0b\uff0c\u6211\u7684\u539f\u6709oplog\u5927\u5c0f\u662f1G\uff0c\u6bcf\u4e2aMongoDB\u5b9e\u4f8b\u7684\u4fee\u6539\u8fc7\u7a0b\u5927\u7ea63-5\u5206\u949f\u5c31\u53ef\u4ee5\u5b8c\u6210\u3002\u5982\u679c\u539f\u6709oplog\u6bd4\u8f83\u5927\uff0c\u9700\u8981\u8003\u8651dump\u7684\u65f6\u95f4\u3002<\/p>\n

\u53c2\u8003\u8d44\u6599<\/h2>\n

https:\/\/docs.mongodb.com\/v3.4\/tutorial\/change-oplog-size\/<\/a>
\n
https:\/\/docs.mongodb.com\/v3.6\/tutorial\/change-oplog-size\/<\/a><\/p>\n

<\/p>\n

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n

<\/wiz_tmp_tag><\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » MongoDB\u5728\u7ebf\u4fee\u6539OPLog\u5927\u5c0f<\/a><\/p>","protected":false},"excerpt":{"rendered":"

MongoDB\u5728\u7ebf\u4fee\u6539OPLog\u5927\u5c0f.md MongoDB\u7684OPlog\u662fMongoDB\u7684\u6838\u5fc3\u6570\u636e\uff0c\u526f\u672c\u96c6\u7684\u540c\u6b65\u4e3b\u8981\u9760\u5b83\uff0c\u5f53\u4e1a\u52a1\u7e41\u5fd9\u65f6\uff0cOplog\u7684\u65f6\u95f4\u7a97\u53e3\u53ef\u80fd\u4f1a\u6bd4\u8f83\u5c0f\uff0c\u6bd4\u598210\u5206\u949f\u3001\u534a\u5c0f\u65f6\uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u884c\u7684\uff0c\u81f3\u5c11\u5e94\u8be5\u4fdd\u6301\u57281\u5929\u4ee5\u4e0a\u3002\u8981\u4e0d\u7136\u4e00\u65e6SECONDARY\u51fa\u73b0\u95ee\u9898\uff0c\u60f3\u8981\u6062\u590d\u5c31\u53d8\u6210\u4e86\u4e00\u4ef6\u9ebb\u70e6\u4e8b\u3002 MongoDB\u7684Oplog\u5927\u5c0f\u7684\u4fee\u6539\u4eceMongoDB3.6 \u5f00\u59cb\u5c31\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4fee\u6539\u547d\u4ee4 db.adminCommand({replSetResizeOplog: 1, size: 16000}) \u4f46\u662f\uff0c\u5f88\u9057\u61be\uff0c\u6211\u53f8\u8fd8\u505c\u7559\u5728MongoDB3.4\u7684\u7248\u672c\uff0c\u6309\u7167\u5b98\u65b9\u6587\u6863\u53ea\u80fd\u6309\u7167\u5982\u4e0b\u64cd\u4f5c\u6b65\u9aa4\u6765\u4fee\u6539\u4e86\uff1a *1. \u5173\u95edmongod\u5b9e\u4f8b\uff1a use admin db.shutdownServer() *2. \u4fee\u6539MongoDB\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u65b0\u542f\u52a8MongoDB \u7aef\u53e3\u4fee\u6539\u4e3a\u6ca1\u6709\u526f\u672c\u96c6\u8fde\u63a5\u7684\u7aef\u53e3\uff0c\u6bd4\u598229017 \u6ce8\u91ca\u6389replication\u548csharding\u7684\u6240\u6709\u9009\u9879 *3.\u5907\u4efdoplog mongodump –db local –collection ‘oplog.rs’ –port 29017 -o shard1 *4. \u767b\u5f55\u5230\u65b0\u542f\u52a8\u7684MongoDB\u5f00\u59cb\u64cd\u4f5c #\u5c06oplog\u6761\u76ee\u5b58\u50a8\u5230temp use local db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() ) db.temp.find() #\u79fb\u9664\u539f\u6709oplog db.oplog.rs.drop() #\u65b0\u5efaoplog\u5e76\u5bfc\u5165 db.runCommand( { […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[130],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1110"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1110"}],"version-history":[{"count":3,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1110\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1110\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}