{"id":1070,"date":"2022-03-31T14:54:22","date_gmt":"2022-03-31T06:54:22","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1070"},"modified":"2022-04-03T16:10:00","modified_gmt":"2022-04-03T08:10:00","slug":"1-nosql-mongodb%e5%ae%89%e8%a3%85%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1070","title":{"rendered":"1. NoSQL&#8211;MongoDB\u5b89\u88c5\u90e8\u7f72"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.\u903b\u8f91\u7ed3\u6784<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Mongodb \u903b\u8f91\u7ed3\u6784             \t\t\tMySQL\u903b\u8f91\u7ed3\u6784\r\n\u5e93database\t\t\t\t\t\t\t\t\u5e93\r\n\u96c6\u5408\uff08collection\uff09\t\t\t\t\t\t\t\u8868\r\n\u6587\u6863\uff08document\uff09\t\t\t\t\t\t\t\u6570\u636e\u884c\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.\u5b89\u88c5\u90e8\u7f72<\/h2>\n\n\n\n<p><strong><em>1.\u7cfb\u7edf\u51c6\u5907<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\uff081\uff09redhat\u6216centos6.2\u4ee5\u4e0a\u7cfb\u7edf\r\n\uff082\uff09\u7cfb\u7edf\u5f00\u53d1\u5305\u5b8c\u6574\r\n\uff083\uff09ip\u5730\u5740\u548chosts\u6587\u4ef6\u89e3\u6790\u6b63\u5e38\r\n\uff084\uff09iptables\u9632\u706b\u5899&amp;SElinux\u5173\u95ed\r\n\uff085\uff09\u5173\u95ed\u5927\u9875\u5185\u5b58\u673a\u5236\r\nroot\u7528\u6237\u4e0b\r\n\u5728vi \/etc\/rc.local\u6700\u540e\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\r\nif test -f \/sys\/kernel\/mm\/transparent_hugepage\/enabled; then\r\n  echo never > \/sys\/kernel\/mm\/transparent_hugepage\/enabled\r\nfi\r\nif test -f \/sys\/kernel\/mm\/transparent_hugepage\/defrag; then\r\n   echo never > \/sys\/kernel\/mm\/transparent_hugepage\/defrag\r\nfi\r\n\t\t\r\ncat  \/sys\/kernel\/mm\/transparent_hugepage\/enabled\r\ncat \/sys\/kernel\/mm\/transparent_hugepage\/defrag\r\n\u5176\u4ed6\u7cfb\u7edf\u5173\u95ed\u53c2\u7167\u5b98\u65b9\u6587\u6863\uff1a\t\r\n\r\nhttps:&#47;&#47;docs.mongodb.com\/manual\/tutorial\/transparent-huge-pages\/\r\n\u4e3a\u4ec0\u4e48\u8981\u5173\u95ed\uff1f\r\nTransparent Huge Pages (THP) is a Linux memory management system \r\nthat reduces the overhead of Translation Lookaside Buffer (TLB) \r\nlookups on machines with large amounts of memory by using larger memory pages.\r\nHowever, database workloads often perform poorly with THP, \r\nbecause they tend to have sparse rather than contiguous memory access patterns. \r\nYou should disable THP on Linux machines to ensure best performance with MongoDB.\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.mongodb\u5b89\u88c5<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## \u521b\u5efa\u6240\u9700\u7528\u6237\u548c\u7ec4\r\nuseradd mongod\r\npasswd mongod\r\n## \u521b\u5efamongodb\u6240\u9700\u76ee\u5f55\u7ed3\u6784\r\nmkdir -p \/mongodb\/conf\r\nmkdir -p \/mongodb\/log\r\nmkdir -p \/mongodb\/data\r\n## \u4e0a\u4f20\u5e76\u89e3\u538b\u8f6f\u4ef6\u5230\u6307\u5b9a\u4f4d\u7f6e\r\n&#91;root@db01 opt]# wget https:\/\/fastdl.mongodb.org\/linux\/mongodb-linux-x86_64-rhel70-4.2.8.tgz\r\n&#91;root@db01 opt]# tar xf mongodb-linux-x86_64-rhel70-4.2.8.tgz \r\n&#91;root@db01 opt]# ln -s \/opt\/mongodb-linux-x86_64-rhel70-4.2.8 \/usr\/local\/mongodb\r\n## \u8bbe\u7f6e\u76ee\u5f55\u7ed3\u6784\u6743\u9650\r\nchown -R mongod:mongod \/mongodb\r\n## \u8bbe\u7f6e\u7528\u6237\u73af\u5883\u53d8\u91cf\r\nsu - mongod\r\nvi .bash_profile\r\nexport PATH=\/usr\/local\/mongodb\/bin:$PATH\r\nsource .bash_profile\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u542f\u52a8mongodb<\/em><\/strong><\/p>\n\n\n\n<p>1.\u547d\u4ee4\u884c\u542f\u52a8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongod --dbpath=\/mongodb\/data --logpath=\/mongodb\/log\/mongodb.log --port=27017 --logappend --fork\r\n##  \u767b\u5f55mongodb\r<\/code><\/pre>\n\n\n\n<p>2.\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u542f\u52a8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>2.1YAML\u914d\u7f6e\u6587\u4ef6\u8be6\u89e3<\/strong>\r\n--\u7cfb\u7edf\u65e5\u5fd7\u6709\u5173\r\nsystemLog:\r\n   destination: file \r\n   path: \"\/mongodb\/log\/mongodb.log\"    --\u65e5\u5fd7\u4f4d\u7f6e\r\n   logAppend: true\t\t\t\t\t   --\u65e5\u5fd7\u4ee5\u8ffd\u52a0\u6a21\u5f0f\u8bb0\u5f55\r\n--\u6570\u636e\u5b58\u50a8\u6709\u5173   \r\nstorage:\r\n   journal:\r\n      enabled: true\r\n   dbPath: \"\/mongodb\/data\"            --\u6570\u636e\u8def\u5f84\u7684\u4f4d\u7f6e\r\n-- \u8fdb\u7a0b\u63a7\u5236  \r\nprocessManagement:\r\n   fork: true                         --\u540e\u53f0\u5b88\u62a4\u8fdb\u7a0b\r\n   pidFilePath: &lt;string>\t\t\t  --pid\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u4e00\u822c\u4e0d\u7528\u914d\u7f6e\uff0c\u53ef\u4ee5\u53bb\u6389\u8fd9\u884c\uff0c\u81ea\u52a8\u751f\u6210\u5230data\u4e2d\r\n--\u7f51\u7edc\u914d\u7f6e\u6709\u5173   \r\nnet:\r\n   bindIp: &lt;ip>                       -- \u76d1\u542c\u5730\u5740\r\n   port: &lt;port>\t\t\t\t\t\t  -- \u7aef\u53e3\u53f7,\u9ed8\u8ba4\u4e0d\u914d\u7f6e\u7aef\u53e3\u53f7\uff0c\u662f27017\r\n-- \u5b89\u5168\u9a8c\u8bc1\u6709\u5173\u914d\u7f6e      \r\nsecurity:\r\n  authorization: enabled              --\u662f\u5426\u6253\u5f00\u7528\u6237\u540d\u5bc6\u7801\u9a8c\u8bc1\r\n------------------\u4ee5\u4e0b\u662f\u590d\u5236\u96c6\u4e0e\u5206\u7247\u96c6\u7fa4\u6709\u5173--------------------- \r\nreplication:\r\n oplogSizeMB: &lt;NUM>\r\n replSetName: \"&lt;REPSETNAME>\"\r\n secondaryIndexPrefetch: \"all\"\r\n \r\nsharding:\r\n   clusterRole: &lt;string>\r\n   archiveMovedChunks: &lt;boolean>\r\n      \r\n---for mongos only\r\nreplication:\r\n   localPingThresholdMs: &lt;int>\r\n\r\nsharding:\r\n   configDB: &lt;string>\r\n<strong>2.2YAML\u914d\u7f6e\u6587\u4ef6\u793a\u4f8b<\/strong>\r\ncat >  \/mongodb\/conf\/mongo.conf &lt;&lt;EOF\r\nsystemLog:\r\n   destination: file\r\n   path: \"\/mongodb\/log\/mongodb.log\"\r\n   logAppend: true\r\nstorage:\r\n   journal:\r\n      enabled: true\r\n   dbPath: \"\/mongodb\/data\/\"\r\nprocessManagement:\r\n   fork: true\r\nnet:\r\n   port: 27017\r\n   bindIp: 10.0.0.51,127.0.0.1\r\nEOF\r\n<strong>2.3\u57fa\u4e8e\u914d\u7f6e\u6587\u4ef6\u91cd\u65b0\u542f\u52a8<\/strong>\r\nmongod -f \/mongodb\/conf\/mongo.conf --shutdown\r\nmongod -f \/mongodb\/conf\/mongo.conf   \r<\/code><\/pre>\n\n\n\n<p><strong><em>3.mongodb\u7684\u5173\u95ed\u65b9\u5f0f<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongod -f mongo.conf  --shutdown<\/code><\/pre>\n\n\n\n<p><strong><em>4.mongodb \u4f7f\u7528systemd\u7ba1\u7406\uff08\u4e0d\u63a8\u8350\uff09<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@db01 ~]# cat > \/etc\/systemd\/system\/mongod.service &lt;&lt;EOF\r\n&#91;Unit]\r\nDescription=mongodb \r\nAfter=network.target remote-fs.target nss-lookup.target\r\n&#91;Service]\r\nUser=mongod\r\nType=forking\r\nExecStart=\/mongodb\/bin\/mongod --config \/mongodb\/conf\/mongo.conf\r\nExecReload=\/bin\/kill -s HUP $MAINPID\r\nExecStop=\/mongodb\/bin\/mongod --config \/mongodb\/conf\/mongo.conf --shutdown\r\nPrivateTmp=true  \r\n&#91;Install]\r\nWantedBy=multi-user.target\r\nEOF\r<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1070"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1070"}],"version-history":[{"count":1,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions"}],"predecessor-version":[{"id":1071,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions\/1071"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}