{"id":439,"date":"2019-06-20T12:49:19","date_gmt":"2019-06-20T04:49:19","guid":{"rendered":"http:\/\/www.yumefx.com\/?p=439"},"modified":"2021-03-04T17:18:30","modified_gmt":"2021-03-04T09:18:30","slug":"mongodb%e7%94%a8%e6%88%b7%e5%af%86%e7%a0%81%e8%ae%a4%e8%af%81","status":"publish","type":"post","link":"https:\/\/www.yumefx.com\/?p=439","title":{"rendered":"mongodb\u7528\u6237\u5bc6\u7801\u8ba4\u8bc1"},"content":{"rendered":"\n<p>\u672c\u7bc7\u6587\u7ae0\u5185\u5bb9\u4e3b\u8981\u662fmongodb\u6dfb\u52a0\u7528\u6237\u5bc6\u7801\uff0c\u4ee5\u53ca\u6dfb\u52a0\u540e\u4e00\u4e9b\u7ba1\u7406\u76f8\u5173\u7684\u64cd\u4f5c\u53d8\u5316\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u521b\u5efa\u7528\u6237<\/h1>\n\n\n\n<pre>\n<span>mongo localhost:27017    #\u8fde\u63a5\u6570\u636e\u5e93<\/span>\n<span>show dbs                 #\u663e\u793a\u6570\u636e\u5e93<\/span>\n<span>use admin                #\u5207\u6362\u5230admin\u6570\u636e\u5e93<\/span>\n<span>db.createUser({user:&quot;root&quot;,pwd:&quot;123456&quot;,roles:[{role:&quot;root&quot;,db:&quot;admin&quot;}]})<\/span>\n<span>use testdb               #\u5207\u6362\u5230testdb\u6570\u636e\u5e93<\/span>\n<span>db.createUser({user:&quot;testUser&quot;,pwd:&quot;123456&quot;,roles:[{role:&quot;readWrite&quot;,db:&quot;testdb&quot;}]}) <\/span>\n<span>db.auth(&quot;testUser&quot;,&quot;123456&quot;)<\/span>\n<span>1                              #\u9a8c\u8bc1\u8d26\u6237\u662f\u5426\u521b\u5efa\u6210\u529f<\/span>\n<\/pre>\n\n\n\n<p>role\u662f\u6307\u8be5\u7528\u6237\u7684\u89d2\u8272\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u6709\u54ea\u4e9b\u6743\u9650\uff0c\u5e38\u7528\u52a0\u7c97\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u5e93\u7528\u6237\u89d2\u8272\uff1a<strong>read\u3001readWrite<\/strong>\uff1b<\/li>\n<li>\u6570\u636e\u5e93\u7ba1\u7406\u89d2\u8272\uff1adbAdmin\u3001<strong>dbOwner<\/strong>\u3001userAdmin\uff1b<\/li>\n<li>\u96c6\u7fa4\u7ba1\u7406\u89d2\u8272\uff1aclusterAdmin\u3001clusterManager\u3001clusterMonitor\u3001hostManager\uff1b<\/li>\n<li>\u5907\u4efd\u6062\u590d\u89d2\u8272\uff1a<strong>backup\u3001restore<\/strong>\uff1b<\/li>\n<li>\u6240\u6709\u6570\u636e\u5e93\u89d2\u8272\uff1a<strong>readAnyDatabase\u3001readWriteAnyDatabase<\/strong>\u3001userAdminAnyDatabase\u3001dbAdminAnyDatabase<\/li>\n<li>\u8d85\u7ea7\u7528\u6237\u89d2\u8272\uff1a<strong>root<\/strong>\u00a0\u00a0\uff08<strong>\u53ea\u80fd\u5728admin\u6570\u636e\u5e93\u521b\u5efa\uff09<\/strong><\/li>\n<li>\u5185\u90e8\u89d2\u8272\uff1a__system<\/li>\n<\/ul>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4f7f\u7528\u8bbf\u95ee\u63a7\u5236\u91cd\u65b0\u542f\u52a8\u6570\u636e\u5e93<\/h1>\n<p>\u5f00\u542f\u8bbf\u95ee\u63a7\u5236\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u2013auth\u53c2\u6570\u91cd\u542fmongod\u670d\u52a1\u3002<\/p>\n\n\n\n<pre>\n<span>mongod --dbpath \u5b58\u653e\u6570\u636e\u5e93\u6587\u4ef6\u5939\u8def\u5f84 --auth<\/span>\n<\/pre>\n\n\n\n<p>\u53e6\u4e00\u79cd\u662f\u4fee\u6539\u6570\u636e\u5e93\u5b89\u88c5\u76ee\u5f55\u4e0b\u914d\u7f6e\u6587\u4ef6config.conf<\/p>\n\n\n\n<pre>\n<span>security:<\/span>\n<span>  authorization: enabled<\/span>\n<\/pre>\n\n\n\n<p>\u7136\u540e\u91cd\u65b0\u542f\u52a8mongodb\u670d\u52a1\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4f7f\u7528\u8d26\u6237\u5bc6\u7801\u767b\u5f55\u6570\u636e\u5e93<\/h1>\n\n\n\n<pre>\n<span>mongo localhost:27017\/testdb -u testUser -p 123456<\/span>\n<\/pre>\n\n\n\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4f7f\u7528\u8d26\u6237\u5bc6\u7801\u5907\u4efd\u6570\u636e\u5e93<\/h1>\n\n\n\n<pre>\n<span>mongodump \/h localhost:27017 \/u testUser \/p 123456 \/d testdb \/o &quot;C:\\backup&quot;<\/span>\n<\/pre>\n\n\n\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u8d26\u6237\u64cd\u4f5c\u76f8\u5173\u7684\u547d\u4ee4<\/h1>\n\n\n\n<pre>\n<span>db.getUser(&quot;testUser&quot;)                                #\u5c55\u793a\u7528\u6237\u4fe1\u606f<\/span>\n<span>db.changeUserPassword(&quot;render&quot;,&quot;lzy123456&quot;,)          #\u4fee\u6539\u7528\u6237\u5bc6\u7801<\/span>\n<span>db.dropUser(&quot;render&quot;,{w:&quot;majority&quot;,wtimeout:5000})    #\u5220\u9664\u7528\u6237<\/span>\n<\/pre>\n\n\n\n<p>\u6d89\u53ca\u5230\u8d26\u6237\u64cd\u4f5c\u7684\u547d\u4ee4\u5fc5\u987b\u5728<strong>\u5173\u95ed\u8bbf\u95ee\u63a7\u5236<\/strong>\u7684\u60c5\u51b5\u4e0b\u767b\u5f55\u6570\u636e\u5e93\u624d\u80fd\u4fee\u6539\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">mongodb\u7684\u8ba4\u8bc1\u65b9\u5f0f<\/h1>\n<p>mongodb\u4e2d\u6709\u4e24\u79cd\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u5206\u522b\u662f <code>MONGODB-CR<\/code> \u548c<code> (SCRAM)SHA-1<\/code> \u3002<\/p>\n<p>\u5176\u4e2d MONGODB-CR \u6bd4\u8f83\u65e7\uff0c\u5728\u65b0\u7248mongodb\u4e2d\u9ed8\u8ba4\u90fd\u662f (SCRAM)SHA-1 \u65b9\u5f0f\uff0c\u90a3\u4e48\u5047\u5982\u56e0\u4e3a\u517c\u5bb9\u6027\u7b49\u539f\u56e0\u5bfc\u81f4\u5fc5\u987b\u9009\u62e9 MONGODB-CR \u65b9\u5f0f\uff0c\u90a3\u4e48\u4e0b\u9762\u63d0\u4f9b\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre>\n<span>db.dropUser(&quot;testUser&quot;,{w:&quot;majority&quot;,wtimeout:5000})     #\u5220\u9664\u7528\u6237<\/span>\n<span>use admin                                                #\u4f7f\u7528admin\u6570\u636e\u5e93<\/span>\n<span>db.system.version.update({&#x27;_id&#x27;:&#x27;authSchema&#x27;},{$set:{&#x27;currentVersion&#x27;:3}}) <\/span>\n<span>#\u4fee\u6539system.version\u6587\u6863\u91cc\u9762\u7684authSchema\u7248\u672c\u4e3a3\uff08\u65e7\u7248\u672c\uff09 <\/span>\n<span>db.system.version.find()                                 #\u67e5\u770b\u662f\u5426\u4fee\u6539\u6210\u529f<\/span>\n<span>{ &quot;_id&quot; : &quot;authSchema&quot;, &quot;currentVersion&quot; : 3 } <\/span>\n<span>use testdb                                               #\u56de\u5230testdb\u6570\u636e\u5e93<\/span>\n<span>db.createUser({user:&#x27;testUser&#x27;,pwd:&#x27;123456&#x27;,roles\uff1a[{role:&#x27;dbOwner&#x27;,db:&#x27;testdb&#x27;}]})                         #\u91cd\u65b0\u521b\u5efa\u7528\u6237<\/span>\n<span>db.getUser(&quot;testUser&quot;,{showCredentials:true})            #\u67e5\u770b\u8ba4\u8bc1\u65b9\u5f0f<\/span>\n<\/pre>\n\n\n\n<p>\u53e6\u5916\u8bf4\u4e00\u4e0b\u5173\u4e8edeadline\u5982\u4f55\u4f7f\u7528\u52a0\u5bc6\u540e\u7684\u6570\u636e\u5e93\uff0c\u53c2\u8003<a href=\"https:\/\/docs.thinkboxsoftware.com\/products\/deadline\/10.0\/1_User%20Manual\/manual\/db-authentication.html\">\u8fd9\u91cc<\/a>\u3002<\/p>\n<p>\u4e3b\u8981\u5c31\u662f\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6 connection.ini \u9700\u8981\u4fee\u6539\u51e0\u4e2a\u53c2\u6570\u3002<\/p>\n\n\n\n<pre>\n<span>Authenticate=True<\/span>\n<span>Username=testUser<\/span>\n<\/pre>\n\n\n\n<p>\u8fd8\u6709\u9700\u8981\u6ce8\u610f\u7684\u6587\u6863\u4e2d\u6709\u4e00\u5904\u4e0e\u5b9e\u9645\u4e0d\u7b26\uff0c\u662f\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6connection.ini\u4e2d\u5e76\u6ca1\u6709Password\u8fd9\u4e00\u53c2\u6570\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u662fPasswordHash\u3002<\/p>\n<p>\u8fd9\u6837\u5176\u5b9e\u662f\u597d\u4e8b\uff0c\u907f\u514d\u5bc6\u7801\u76f4\u63a5\u5199\u5728\u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u88ab\u4eba\u8f7b\u677e\u83b7\u53d6\u3002<\/p>\n<p>\u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u8fd9\u4e2a PasswordHash \u4e0d\u662f\u62ff\u5bc6\u7801\u627e\u7f51\u7ad9\u5de5\u5177\u8f6c\u6362\u586b\u5199\u7684\uff0c\u4e5f\u548cmongodb\u4e2ddb.getUser(\u201crender\u201d,{showCredentials:true})\u547d\u4ee4\u5c55\u793a\u51fa\u7684hash password\u65e0\u5173\uff0c\u800c\u662fdeadline\u6839\u636e\u8f93\u5165\u7684\u5bc6\u7801\u8fdb\u884c\u52a0\u5bc6\u5b58\u50a8\u7684\u3002<\/p>\n<p>\u6b63\u786e\u7684\u586b\u5199\u59ff\u52bf\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre>\n<span>deadlinecommand UpdateDatabaseSettings C:\\DeadlineRepository10 MongoDB 10.10.10.10 deadline10db 27017 -1 False True testUser 123456 &quot;&quot; False<\/span>\n<\/pre>\n\n\n\n<p>CMD\u4e2d\u8fd0\u884c\u5b8c\u540e\uff0c\u5c31\u80fd\u770b\u5230connection.ini\u6587\u4ef6\u4e2d\u5df2\u7ecf\u6b63\u786e\u8f6c\u6362\u548c\u586b\u5199\u5b8c\u6210Passwordhash\u7b49\u53c2\u6570\u3002<\/p>\n<p>\u518d\u653e\u4e2awin\u5e73\u53f0\u7684\u6570\u636e\u5e93\u53ef\u89c6\u5316\u5de5\u5177<a href=\"https:\/\/www.yumefx.com\/files\/robomongo-0.9.0.rar\">robomongo<\/a>\u3002<\/p>\n<p>\u00a0<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u771f\u7231\u7684\u7b2c\u4e00\u4e2a\u5f81\u5146\uff0c<br \/>\u5728\u7537\u5b69\u8eab\u4e0a\u662f\u80c6\u602f\uff0c<br \/>\u5728\u5973\u5b69\u8eab\u4e0a\u662f\u5927\u80c6\u3002<\/p>\n<p style=\"text-align: right;\">\u300a\u60b2\u60e8\u4e16\u754c\u300b<br \/>\u2014\u2014\u96e8\u679c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u5185\u5bb9\u4e3b\u8981\u662fmongodb\u6dfb\u52a0\u7528\u6237\u5bc6\u7801\uff0c\u4ee5\u53ca\u6dfb\u52a0\u540e\u4e00\u4e9b\u7ba1\u7406\u76f8\u5173\u7684\u64cd\u4f5c\u53d8\u5316\u3002 \u00a0 \u521b\u5efa\u7528\u6237 mongo l [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1049,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,4],"tags":[14,55],"_links":{"self":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/439"}],"collection":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=439"}],"version-history":[{"count":0,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/439\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/media\/1049"}],"wp:attachment":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}