{"id":149887,"date":"2019-07-09T10:19:11","date_gmt":"2019-07-09T02:19:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=149887"},"modified":"2019-07-02T16:22:57","modified_gmt":"2019-07-02T08:22:57","slug":"redhat-centos-mongodb","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redhat-centos-mongodb.html","title":{"rendered":"\u5728Red Hat\u548cCentos\u4e0a\u5b89\u88c5MongoDB"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6839\u636e\u672c\u5b89\u88c5\u6559\u7a0b\u5728Red Hat Linux\u548cCentOS Linux\u5b89\u88c5\u793e\u533a\u7248\u7684MongoDB\u3002\u672c\u5b89\u88c5\u6307\u5bfc\u53ea\u652f\u6301\u5b89\u88c564-bit\u7cfb\u7edf\u3002MongoDB\u53ea\u652f\u6301Oracle linux \u5728Red Hat Compatible Kernel\uff08RHCK\uff09\u3002MongoDB\u4e0d\u652f\u6301Unbreakable Enterprise Kernel\uff08UEK\uff09<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5b89\u88c5<\/strong><\/div>\n
\u4e00 \u4f7f\u7528yum\u5b89\u88c5<\/strong><\/span><\/div>\n

\u5b89\u88c5\u6b65\u9aa4<\/p>\n

1\u3001\u914d\u7f6eyum<\/p>\n

\u521b\u5efa\u6587\u4ef6 \/etc\/yum.repos.d\/mongodb-org-4.0.repo\uff0c\u7528\u4e8eyum\u6765\u5b89\u88c5MongoDB<\/p>\n

\u6587\u4ef6\u8be6\u7ec6\u5185\u5bb9<\/p>\n

[mongodb-org-4.0]\r\n\r\nname=MongoDB Repository\r\n\r\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/4.0\/x86_64\/\r\n\r\ngpgcheck=1\r\n\r\nenabled=1\r\n\r\ngpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-4.0.asc\r\n<\/pre>\n

2\u3001\u5b89\u88c5MongoDB<\/p>\n

\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684MongoDB\uff0c\u4f7f\u7528\u547d\u4ee4<\/p>\n

sudo yum install -y mongodb-org<\/pre>\n

\u5982\u679c\u60f3\u6307\u5b9a\u5b89\u88c5\u67d0\u4e2a\u7248\u672cMongoDB\uff0c\u9700\u8981\u4e3a\u6bcf\u4e2a\u90e8\u5206\u5355\u72ec\u6307\u5b9a\u7248\u672c\u5728\u5305\u7684\u540d\u5b57\u540e\u9762\uff0c\u5982\u4e0b\u9762\u5b9e\u4f8b\u6240\u793a<\/p>\n

sudo yum install -y mongodb-org-4.0.9 mongodb-org-server-4.0.9 mongodb-org-shell-4.0.9 mongodb-org-mongos-4.0.9 mongodb-org-tools-4.0.9\r\n<\/pre>\n
\u4e8c \u4f7f\u7528\u538b\u7f29\u5305\u5b89\u88c5<\/strong><\/span><\/div>\n

\u524d\u63d0\u6761\u4ef6<\/p>\n

MongoDB .tar.gz\u538b\u7f29\u5305\u4f7f\u7528\u5fc5\u987b\u5b89\u88c5\u4f9d\u8d56<\/p>\n

yum install libcurl openssl<\/pre>\n

\u6b65\u9aa4<\/p>\n

1\u3001\u4e0b\u8f7dMongoDB .tar.gz\u683c\u5f0f\u7684\u538b\u7f29\u5305<\/p>\n

\u4e0b\u8f7d\u5730\u5740\uff1aMongoDB Download Center.<\/p>\n

2\u3001\u89e3\u538b\u4e0b\u8f7d\u7684\u538b\u7f29\u5305\u6587\u4ef6<\/p>\n

tar -zxvf mongodb-linux-*-4.0.9.tgz<\/pre>\n

3\u3001\u589e\u52a0\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fdd\u53ef\u6267\u884c\u6587\u4ef6\u5728\u5217\u51fa\u7684\u76ee\u5f55\u4e2d<\/p>\n

MongoDB\u53ef\u6267\u884c\u6587\u4ef6\u5728 bin\/ \u538b\u7f29\u5305\u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u5efa\u8bae\u64cd\u4f5c<\/p>\n

\u590d\u5236\u8fd9\u4e9b\u53ef\u6267\u884c\u6587\u4ef6\u5230\u4f60\u7684\u73af\u5883\u53d8\u91cf\u76ee\u5f55\uff0c\u4f8b\u5982\/usr\/local\/bin<\/p>\n

\u521b\u5efa\u94fe\u63a5\u4e3a\u8fd9\u4e9b\u53ef\u6267\u884c\u6587\u4ef6\u4ece\u76ee\u5f55\u5728\u4f60\u7684\u73af\u5883\u53d8\u91cf\u6216\u4fee\u6539\u4f60\u7684\u73af\u5883\u53d8\u91cf\u5305\u62ec\u8fd9\u4e2a\u76ee\u5f55<\/p>\n

\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u5728\u4f60\u7684shell\u7684\u521d\u59cb\u5316\u811a\u672c(e.g. ~\/.bashrc)<\/p>\n

export PATH=<mongodb-install-directory>\/bin:$PATH<\/pre>\n

\u66ff\u6362<mongodb-install-directory>\u4e3a\u4f60\u7684MongoDB\u5b9e\u9645\u5b89\u88c5\u8def\u5f84<\/p>\n

\u4f7f\u7528<\/strong><\/div>\n

\u8bb8\u591a\u7c7bUni\u64cd\u4f5c\u7cfb\u7edf\u7cfb\u7edf\u9650\u5236\u7cfb\u7edf\u8d44\u6e90\u7c7b\u4f3csession\u7684\u4f7f\u7528\u3002\u8fd9\u4e9b\u9650\u5236\u4e5f\u8bb8\u4f1a\u5f71\u54cdMongoDB\u64cd\u4f5c\u3002\u67e5\u770b\u66f4\u591aUNIX ulimit Settings<\/p>\n

\u76ee\u5f55\u8def\u5f84<\/strong><\/span><\/div>\n

\u5e38\u7528\u9ed8\u8ba4\u8def\u5f84<\/p>\n

\u901a\u5e38MongoDB\u901a\u8fc7mongod\u7528\u6237\u8d26\u53f7\u548c\u4f7f\u7528\u8fd9\u4e9b\u9ed8\u8ba4\u76ee\u5f55<\/p>\n

\/var\/lib\/mongo (\u6570\u636e)\r\n\r\n\/var\/log\/mongodb (\u65e5\u5fd7)\r\n<\/pre>\n

\u5982\u679c\u4f60\u901a\u8fc7package\u5b89\u88c5<\/p>\n

\u9ed8\u8ba4\u76ee\u5f55\u4f1a\u88ab\u521b\u5efa\uff0c\u540c\u65f6\u8fd9\u4e2a\u76ee\u5f55\u7684\u6240\u6709\u4eba\u548c\u7ec4\u7ec7\u4f1a\u88ab\u8bbe\u7f6e\u4e3amongod<\/p>\n

\u5982\u679c\u4f60\u901a\u8fc7\u538b\u7f29\u5305\u4e0b\u8f7d<\/p>\n

\u9ed8\u8ba4\u76ee\u5f55\u9700\u8981\u624b\u52a8\u521b\u5efa<\/p>\n

\u63d0\u793a\uff1a\u53d6\u51b3\u4f60\u7684\u7528\u6237\u6743\u9650\uff0c\u4e5f\u8bb8\u9700\u8981\u4f7f\u7528\u8d85\u7ea7\u6743\u9650\u6765\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c<\/p>\n

mkdir -p \/var\/lib\/mongo\r\n\r\nmkdir -p \/var\/log\/mongodb\r\n<\/pre>\n

\u9ed8\u8ba4MongoDB\u8fd0\u884c\u4f7f\u7528mongod\u7528\u6237\u8d26\u53f7\u3002\u4e00\u6b21\u521b\u5efa\uff0c\u8bbe\u7f6e\u8fd9\u4e9b\u76ee\u5f55\u7684\u6240\u6709\u4eba\u548c\u7ec4\u7ec7\u4e3amongod<\/p>\n

chown -R mongod:mongod <directory><\/pre>\n

\u4e0d\u4f7f\u7528\u9ed8\u8ba4\u76ee\u5f55\uff0c\u521b\u5efa\u60f3\u7528\u7684\u76ee\u5f55\uff0c\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/etc\/mongod.conf\u7684\u76f8\u5173\u914d\u7f6e<\/p>\n

storage.dbPath to specify a new data directory path (e.g. \/some\/data\/directory)\r\n\r\nsystemLog.path to specify a new log file path (e.g. \/some\/log\/directory\/mongod.log)\r\n<\/pre>\n

\u786e\u8ba4\u8fd0\u884c\u7684MongoDB\u5df2\u7ecf\u8bbf\u95ee\u4f7f\u7528\u8fd9\u4e9b\u76ee\u5f55<\/p>\n

chown -R mongod:mongod <directory><\/pre>\n
\u542f\u52a8\u6b65\u9aa4<\/strong><\/span><\/div>\n

1\u3001\u5f00\u542fMongoDB<\/p>\n

\u4f7f\u7528\u547d\u4ee4\u542f\u52a8MongoDB<\/p>\n

sudo service mongod start<\/p>\n

\u68c0\u6d4bMongoDB\u662f\u5426\u5df2\u542f\u52a8\u6210\u529f<\/p>\n

\u68c0\u6d4b\u65e5\u5fd7\u5185\u5bb9 \/var\/log\/mongodb\/mongod.log<\/p>\n

[initandlisten] waiting for connections on port <port><\/pre>\n

port\u9ed8\u8ba4\u914d\u7f6e27017\uff0c\u914d\u7f6e\u4f4d\u7f6e \/etc\/mongod.conf<\/p>\n

\u4f60\u53ef\u4ee5\u786e\u8ba4MongoDB\u4f1a\u8ddf\u8e2areboot\u7cfb\u7edf\u901a\u8fc7\u8ddf\u8e2a\u547d\u4ee4<\/p>\n

sudo chkconfig mongod on<\/pre>\n

2\u3001\u505c\u6b62MongoDB<\/p>\n

sudo service mongod stop<\/pre>\n

3\u3001\u91cd\u542fMongoDB<\/p>\n

sudo service mongod restart<\/pre>\n

4\u3001\u5f00\u59cb\u4f7f\u7528MongoDB<\/p>\n

\u5728\u540c\u4e00\u4e2a\u4e3b\u673a\u6253\u5f00\u4e00\u4e2amongo shell\u3002\u4f60\u53ef\u4ee5\u5728\u6ca1\u6709\u4efb\u4f55\u547d\u4ee4\u884c\u9009\u9879\u7684\u60c5\u51b5\u4e0b\u8fd0\u884cmongo shell\u6765\u8fde\u63a5\u5230\u60a8\u672c\u5730\u5177\u6709\u9ed8\u8ba4\u7aef\u53e327017\u7684mongod\u5b9e\u4f8b\u3002<\/p>\n

5\u3001\u5378\u8f7dMongoDB<\/p>\n

\u5378\u8f7d\u4f1a\u6e05\u9664\u6570\u636e\uff0c\u5378\u8f7d\u524d\u8bf7\u5148\u786e\u8ba4<\/p>\n

\uff081\uff09\u505c\u6b62 MongoDB<\/p>\n

sudo service mongod stop<\/pre>\n

\uff082\uff09\u79fb\u9664\u5305<\/p>\n

sudo yum erase $(rpm -qa | grep mongodb-org)<\/pre>\n

\uff083\uff09\u79fb\u9664\u6570\u636e\u76ee\u5f55<\/p>\n

sudo rm -r \/var\/log\/mongodb\r\n\r\nsudo rm -r \/var\/lib\/mongo\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5b89\u88c5\u6b65\u9aa4 1\u3001\u914d\u7f6eyum \u521b\u5efa\u6587\u4ef6 \/etc\/yum.repos.d\/mongodb-org-4.0.repo […]<\/p>\n","protected":false},"author":362,"featured_media":149896,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-149887","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/149887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=149887"}],"version-history":[{"count":12,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/149887\/revisions"}],"predecessor-version":[{"id":150315,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/149887\/revisions\/150315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/149896"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=149887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=149887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=149887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}