{"id":42890,"date":"2024-10-04T08:06:39","date_gmt":"2024-10-04T00:06:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/42890\/"},"modified":"2024-10-04T08:06:40","modified_gmt":"2024-10-04T00:06:40","slug":"centos-7-1-%e4%b8%8b-node-jsnginxmongodb-%e7%9a%84%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/42890\/","title":{"rendered":"CentOS 7.1 \u4e0b Node.js+Nginx+MongoDB \u7684\u5b89\u88dd\u8207\u914d\u7f6e"},"content":{"rendered":"<h1 id=\"centos-7-1-%e4%b8%8b-node-jsnginxmongodb-%e7%9a%84%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae-pifYqkegdy\">CentOS 7.1 \u4e0b Node.js+Nginx+MongoDB \u7684\u5b89\u88dd\u8207\u914d\u7f6e<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u958b\u767c\u4e2d\uff0cNode.js\u3001Nginx \u548c MongoDB \u662f\u4e09\u500b\u975e\u5e38\u6d41\u884c\u7684\u6280\u8853\u7d44\u5408\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728 CentOS 7.1 \u4e0a\u5b89\u88dd\u548c\u914d\u7f6e\u9019\u4e09\u500b\u7d44\u4ef6\uff0c\u4ee5\u4fbf\u5efa\u7acb\u4e00\u500b\u9ad8\u6548\u7684\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-pifYqkegdy\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684 CentOS 7.1 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u57fa\u672c\u7684\u5de5\u5177\u548c\u4f9d\u8cf4\u9805\uff1a<\/p>\n<pre><code>sudo yum install -y epel-release<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-node-js-pifYqkegdy\">\u5b89\u88dd Node.js<\/h2>\n<p>Node.js \u662f\u4e00\u500b\u57fa\u65bc Chrome V8 \u5f15\u64ce\u7684 JavaScript \u57f7\u884c\u74b0\u5883\u3002\u8981\u5b89\u88dd Node.js\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 NodeSource \u7684\u4e8c\u9032\u5236\u5206\u767c\u5305\u3002\u9996\u5148\uff0c\u6dfb\u52a0 NodeSource \u7684\u5b58\u5132\u5eab\uff1a<\/p>\n<pre><code>curl -sL https:\/\/rpm.nodesource.com\/setup_14.x | sudo bash -<\/code><\/pre>\n<p>\u7136\u5f8c\u5b89\u88dd Node.js\uff1a<\/p>\n<pre><code>sudo yum install -y nodejs<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Node.js \u548c npm \u7684\u7248\u672c\uff1a<\/p>\n<pre><code>node -v\nnpm -v<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-nginx-pifYqkegdy\">\u5b89\u88dd Nginx<\/h2>\n<p>Nginx \u662f\u4e00\u500b\u9ad8\u6027\u80fd\u7684 HTTP \u548c\u53cd\u5411\u4ee3\u7406\u4f3a\u670d\u5668\u3002\u8981\u5b89\u88dd Nginx\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo yum install -y nginx<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u70ba\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\nsudo systemctl enable nginx<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\u4f86\u6aa2\u67e5 Nginx \u662f\u5426\u904b\u884c\u6b63\u5e38\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u80fd\u770b\u5230 Nginx \u7684\u6b61\u8fce\u9801\u9762\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mongodb-pifYqkegdy\">\u5b89\u88dd MongoDB<\/h2>\n<p>MongoDB \u662f\u4e00\u500b NoSQL \u6578\u64da\u5eab\uff0c\u9069\u5408\u7528\u65bc\u8655\u7406\u5927\u91cf\u7684\u6578\u64da\u3002\u8981\u5b89\u88dd MongoDB\uff0c\u9996\u5148\u9700\u8981\u6dfb\u52a0 MongoDB \u7684\u5b58\u5132\u5eab\uff1a<\/p>\n<pre><code>cat &lt;&lt;EOF | sudo tee \/etc\/yum.repos.d\/mongodb-org-4.4.repo\n[mongodb-org-4.4]\nname=MongoDB Repository\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/7\/mongodb-org\/4.4\/x86_64\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-4.4.asc\nEOF<\/code><\/pre>\n<p>\u7136\u5f8c\u5b89\u88dd MongoDB\uff1a<\/p>\n<pre><code>sudo yum install -y mongodb-org<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 MongoDB \u4e26\u8a2d\u7f6e\u70ba\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start mongod\nsudo systemctl enable mongod<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e4%bb%a5%e6%94%af%e6%8c%81-node-js-%e6%87%89%e7%94%a8-pifYqkegdy\">\u914d\u7f6e Nginx \u4ee5\u652f\u6301 Node.js \u61c9\u7528<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u914d\u7f6e Nginx \u4ee5\u53cd\u5411\u4ee3\u7406\u5230 Node.js \u61c9\u7528\u3002\u9996\u5148\uff0c\u5275\u5efa\u4e00\u500b\u65b0\u7684 Nginx \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/nginx\/conf.d\/nodeapp.conf<\/code><\/pre>\n<p>\u5728\u8a72\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name your_domain_or_IP;\n\n    location \/ {\n        proxy_pass http:\/\/localhost:3000; # Node.js \u61c9\u7528\u904b\u884c\u7684\u7aef\u53e3\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection 'upgrade';\n        proxy_set_header Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n}<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\uff0c\u7136\u5f8c\u6aa2\u67e5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u91cd\u65b0\u52a0\u8f09 Nginx \u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo systemctl reload nginx<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-pifYqkegdy\">\u7d50\u8ad6<\/h2>\n<p>\u81f3\u6b64\uff0c\u60a8\u5df2\u7d93\u6210\u529f\u5728 CentOS 7.1 \u4e0a\u5b89\u88dd\u4e26\u914d\u7f6e\u4e86 Node.js\u3001Nginx \u548c MongoDB\u3002\u9019\u4e09\u8005\u7684\u7d44\u5408\u80fd\u5920\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u5f37\u5927\u7684\u652f\u6301\uff0c\u7121\u8ad6\u662f\u8655\u7406\u9ad8\u4e26\u767c\u8acb\u6c42\u9084\u662f\u5b58\u5132\u5927\u91cf\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to install and configure Node.js, Nginx, and MongoDB on CentOS 7.1 for a robust web development environment.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-42890","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=42890"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42890\/revisions"}],"predecessor-version":[{"id":42891,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42890\/revisions\/42891"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=42890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=42890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=42890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}