{"id":43308,"date":"2024-10-05T01:32:19","date_gmt":"2024-10-04T17:32:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43308\/"},"modified":"2024-10-05T01:32:19","modified_gmt":"2024-10-04T17:32:19","slug":"centos-7-%e4%b8%8b%e9%83%a8%e7%bd%b2-net-core-2-0nginxsupervisormysql-%e7%92%b0%e5%a2%83","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43308\/","title":{"rendered":"CentOS 7 \u4e0b\u90e8\u7f72 .NET Core 2.0+Nginx+Supervisor+MySQL \u74b0\u5883"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%8b%e9%83%a8%e7%bd%b2-net-core-2-0-nginx-supervisor-mysql-%e7%92%b0%e5%a2%83-EiLLnVgusE\">CentOS 7 \u4e0b\u90e8\u7f72 .NET Core 2.0 + Nginx + Supervisor + MySQL \u74b0\u5883<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u958b\u767c\u4e2d\uff0c.NET Core \u4f5c\u70ba\u4e00\u500b\u8de8\u5e73\u53f0\u7684\u958b\u767c\u6846\u67b6\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u74b0\u5883\u4e0b\u90e8\u7f72 .NET Core 2.0\uff0c\u4e26\u7d50\u5408 Nginx\u3001Supervisor \u548c MySQL\uff0c\u69cb\u5efa\u4e00\u500b\u7a69\u5b9a\u7684\u61c9\u7528\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-EiLLnVgusE\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684 CentOS 7 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd\u4e00\u4e9b\u5fc5\u8981\u7684\u5de5\u5177\u548c\u5eab\uff1a<\/p>\n<pre><code>sudo yum install -y wget curl<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-net-core-2-0-EiLLnVgusE\">\u5b89\u88dd .NET Core 2.0<\/h2>\n<p>\u9996\u5148\uff0c\u6dfb\u52a0 Microsoft \u7684\u5305\u5b58\u5132\u5eab\uff1a<\/p>\n<pre><code>sudo rpm -Uvh https:\/\/packages.microsoft.com\/config\/rhel\/7\/prod.repo<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u5b89\u88dd .NET Core SDK \u548c\u904b\u884c\u6642\uff1a<\/p>\n<pre><code>sudo yum install -y dotnet-sdk-2.0.0<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 .NET Core \u662f\u5426\u5b89\u88dd\u6210\u529f\uff1a<\/p>\n<pre><code>dotnet --version<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mysql-EiLLnVgusE\">\u5b89\u88dd MySQL<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd MySQL \u6578\u64da\u5eab\u3002\u9996\u5148\uff0c\u6dfb\u52a0 MySQL \u7684 Yum \u5b58\u5132\u5eab\uff1a<\/p>\n<pre><code>sudo wget https:\/\/dev.mysql.com\/get\/mysql57-community-release-el7-11.noarch.rpm<\/code><\/pre>\n<pre><code>sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u5b89\u88dd MySQL\uff1a<\/p>\n<pre><code>sudo yum install -y mysql-community-server<\/code><\/pre>\n<p>\u555f\u52d5 MySQL \u670d\u52d9\u4e26\u8a2d\u7f6e\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start mysqld<\/code><\/pre>\n<pre><code>sudo systemctl enable mysqld<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7372\u53d6\u81e8\u6642\u5bc6\u78bc\uff1a<\/p>\n<pre><code>sudo grep 'temporary password' \/var\/log\/mysqld.log<\/code><\/pre>\n<p>\u4f7f\u7528\u8a72\u5bc6\u78bc\u767b\u9304 MySQL \u4e26\u8a2d\u7f6e\u65b0\u7684\u5bc6\u78bc\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-nginx-EiLLnVgusE\">\u5b89\u88dd Nginx<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd Nginx \u4f5c\u70ba\u53cd\u5411\u4ee3\u7406\u670d\u52d9\u5668\uff1a<\/p>\n<pre><code>sudo yum install -y epel-release<\/code><\/pre>\n<pre><code>sudo yum install -y nginx<\/code><\/pre>\n<p>\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start nginx<\/code><\/pre>\n<pre><code>sudo systemctl enable nginx<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-supervisor-EiLLnVgusE\">\u914d\u7f6e Supervisor<\/h2>\n<p>Supervisor \u662f\u4e00\u500b\u9032\u7a0b\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u7ba1\u7406 .NET Core \u61c9\u7528\u7684\u904b\u884c\u3002\u9996\u5148\uff0c\u5b89\u88dd Supervisor\uff1a<\/p>\n<pre><code>sudo yum install -y supervisor<\/code><\/pre>\n<p>\u555f\u52d5 Supervisor \u4e26\u8a2d\u7f6e\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start supervisord<\/code><\/pre>\n<pre><code>sudo systemctl enable supervisord<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5275\u5efa\u4e00\u500b Supervisor \u914d\u7f6e\u6587\u4ef6\u4f86\u7ba1\u7406\u4f60\u7684 .NET Core \u61c9\u7528\uff1a<\/p>\n<pre><code>[program:myapp]\ncommand=\/usr\/bin\/dotnet \/path\/to\/your\/app.dll\nautostart=true\nautorestart=true\nstderr_logfile=\/var\/log\/myapp.err.log\nstdout_logfile=\/var\/log\/myapp.out.log<\/code><\/pre>\n<p>\u4fdd\u5b58\u914d\u7f6e\u5f8c\uff0c\u66f4\u65b0 Supervisor \u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo supervisorctl reread\nsudo supervisorctl update<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86-EiLLnVgusE\">\u914d\u7f6e Nginx \u53cd\u5411\u4ee3\u7406<\/h2>\n<p>\u6700\u5f8c\uff0c\u914d\u7f6e Nginx \u4ee5\u53cd\u5411\u4ee3\u7406\u5230\u4f60\u7684 .NET Core \u61c9\u7528\u3002\u7de8\u8f2f Nginx \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/nginx\/conf.d\/myapp.conf<\/code><\/pre>\n<p>\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name your_domain.com;\n\n    location \/ {\n        proxy_pass http:\/\/localhost:5000;\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\u5f8c\uff0c\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\u555f\u52d5 Nginx\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EiLLnVgusE\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u6211\u5011\u6210\u529f\u5728 CentOS 7 \u4e0a\u90e8\u7f72\u4e86 .NET Core 2.0 \u74b0\u5883\uff0c\u4e26\u914d\u7f6e\u4e86 Nginx\u3001Supervisor \u548c MySQL\u3002\u9019\u6a23\u7684\u67b6\u69cb\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u61c9\u7528\u7684\u7a69\u5b9a\u6027\uff0c\u9084\u80fd\u5920\u6709\u6548\u5730\u7ba1\u7406\u548c\u64f4\u5c55\u61c9\u7528\u3002\u5982\u679c\u4f60\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 deploy a .NET Core 2.0 application on CentOS 7 using Nginx, Supervisor, and MySQL for a robust web 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-43308","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43308","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=43308"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43308\/revisions"}],"predecessor-version":[{"id":43309,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43308\/revisions\/43309"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}