环境说明

系统:CentOS Linux release 7.2.1511 (Core)

相关工具:VS2017  xftp

服务器软件:.net core2.0,nginx

准备.net core应用程序

.NET Core分为两种应用类型:Portable applications(便携应用)          Self-contained application(自宿主应用)

我们选择便携应用,这样发布的项目会小一点,也是微软推荐的发布方式。

.NET Core SDK 下载地址:https://www.microsoft.com/net/download  (还需要安装server host,是否安装成功 iis模块与处理程序映射中查看)

  • 确保这份发布应用可以在windows上运行,以减少后续的问题。

服务器安装CentOS7

这个不多说了,网上好多教程。

服务器安装.net sdk for .net core

sudo yum install libunwind libicu(安装libicu依赖)

curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131(下载sdk压缩包,1.0) 

curl -sSL -o dotnet.tar.gz https://download.microsoft.com/download/7/3/A/73A3E4DC-F019-47D1-9951-0453676E059B/dotnet-sdk-2.0.2-linux-x64.tar.gz  (2.0)

sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet(解压缩)

sudo ln -s /opt/dotnet/dotnet /usr/local/bin(创建链接)

官方教程:https://www.microsoft.com/net/download/linux-package-manager/centos/sdk-current

输入 dotnet –info 来查看是否安装成功

如果可以执行则表明.NET Core SDK安装成功

部署.net core应用程序到服务器

使用Xftp上传到服务器,需要注意一点,配置xftp时,协议选择sftp,不要选ftp,否则会出现连不上服务器的情况。

项目上传至服务 home/WebApp

检查项目是否能够运行

命令:dotnet /home/WebApp/WebApp.dll

  

可以看到端口号是5000:Now listening on: http://localhost:5000

安装Nginx

curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

rpm -ivh nginx.rpm

yum install nginx

输入:systemctl start nginx 来启动nginx。


输入:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。

配置Nginx对Asp .Net Core的转发

修改 /etc/nginx/conf.d/default.conf 文件。

将文本内容替换为上图:

server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://localhost:5000;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection keep-alive;
#proxy_set_header Host $host;
#proxy_cache_bypass $http_upgrade;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

:wq 覆盖保存。

执行:nginx –s reload 使其即时生效

可能出现的问题

CentOS 7.0默认使用的是firewall作为防火墙,我参考了一些资料,改为iptables防火墙:

1.关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

2.iptables防火墙安装

#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables
#安装iptables-services
yum install iptables-services

3.开启iptables  

#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service

4.配置iptables,开放端口,输入命令:# vi /etc/sysconfig/iptables

# Generated by iptables-save v1.4.21 on Wed Oct 18 11:53:01 2017
*mangle
:PREROUTING ACCEPT [135197:27080837]
:INPUT ACCEPT [63155:19657469]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [11793:12614289]
:POSTROUTING ACCEPT [11891:12626324]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Wed Oct 18 11:53:01 2017
# Generated by iptables-save v1.4.21 on Wed Oct 18 11:53:01 2017 *filter
:INPUT ACCEPT [62:5588]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [29:2860]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5900 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT #vnc远程桌面连接
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
# Completed on Wed Oct 18 11:53:01 2017

5.重启iptables

# systemctl restart iptables.service

后续出现的问题

配置好守护服务(supervisor)后,自己手贱,reboot了一下服务器,结果服务器再起来后,不知道是不是我重启了下nginx还是什么原因,项目跑不起来了,提示已运行,我就按网上说的kill了几个进程,kill完后,项目是起来了,可是所有静态文件加载不了css,js,后来又按网上说的,配置nginx访问js后仍不行,重装了下nginx后还不行,最后重新安装了dotnet core后问题解决了,所以感觉出现问题后,最快的方法就是重装以上软件!

后来又出过一次问题,我的数据库服务器IP地址变了,然后项目跑是能跑起来,只是涉及到连接数据的操作都挂了,我把项目更新后还是跑不起来,重启nginx、kill .net进程都不行,重装.net core还是不行,最后把supervisor停了再启动
( supervisord -c /etc/supervisor/supervisord.conf) 就好了。

卸载SDK命令

sudo yum remove dotnet-sdk-*
sudo yum remove libunwind libicu
sudo yum remove /etc/yum.repos.d/dotnetdev.repo

或者

rm -rf /usr/share/dotnet​ 删除旧版cli
1、配置dotnet产品Feed
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl= https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo' 2、安装SDK,注意版本!!!
sudo yum update
sudo yum -y install libunwind libicu
sudo yum install dotnet-sdk-2.1.4

*****************************************end**********************************************

感谢博客园的大牛园友的无私奉献!!

参考:http://www.cnblogs.com/ants/p/5732337.html

DotNet跨平台 - .net core项目部署到centos7的更多相关文章

  1. .NET Core跨平台:.NET Core项目部署到linux(Centos7)

    1.开篇说明 a 上篇博客简单的说明了一下 使用.NET Core开发的一个总结,地址是:(http://www.cnblogs.com/hanyinglong/p/6442148.html),那么这 ...

  2. NET Core项目部署

    NET Core项目部署到linux(Centos7) 阅读目录 1.开篇说明 2.Jexus简单说明 3.Visual Studio 2015本地发布并且测试 4.配置Jexus并且部署.NET C ...

  3. .Net Core 项目部署IIS简单步骤

    1.新建一个解决方案: 我习惯会把运行文件移至一级目录 然后清除CoreTest 文件夹里面的文件 2.在解决方案中新建一个项目 点击确认有,这里有几种选择类型,我一般选择空类型(这里需要注意一下,空 ...

  4. .NET Core项目部署到Linux(Centos7)(六)发布.NET Core 项目到Linux

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  5. .NET Core项目部署到Linux(Centos7)(一)前言

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  6. .NET Core项目部署到Linux(Centos7)(十)总结

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  7. .NET Core项目部署到Linux(Centos7)(七)启动和停止.NET Core项目

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  8. .NET Core项目部署到Linux(Centos7)(八)为.NET Core项目创建Supervisor进程守护监控

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  9. .NET Core项目部署到Linux(Centos7)(五)Centos 7安装.NET Core环境

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

随机推荐

  1. 阿里前端实习生面试总结(两轮技术面+一轮hr面)

    投的蚂蚁金服: 一面(只有13分钟): 1.angular里双向绑定的实现原理: 巴拉巴拉巴拉,这个问题很常见,我提到了$scope.$apply()和$scope.$digest(),面试官问app ...

  2. ccf 201803-3 URL映射(python)

    使用正则表达式 import re import collections n, m = list(map(int, input().split())) arr = ['']*(m+n) for i i ...

  3. Web前端学习笔记——Canvas

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  4. Linux与linux之间传递文件、

    1.从linux本机文件上传到另一台linux格式:scp 要传的文件 root@目标ip:路径scp –r 要传的目录 root@目标ip:路径 例子: scp  /root/1.txt   roo ...

  5. VBA 格式化excel数据表 (数据分列)

    Sub ImportData() ' ' Copy Data from one workbook to the Current Workbook ' Place the macro file in t ...

  6. 西湖论剑2019部分writeup

    做了一天水了几道题发现自己比较菜,mfc最后也没怼出来,被自己菜哭 easycpp c++的stl算法,先读入一个数组,再产生一个斐波拉契数列数组 main::{lambda(int)#1}::ope ...

  7. xdebug调试的原理

    转自 https://segmentfault.com/a/1190000002528341 使用PhpStorm+xdebug单步调试程序可以快速帮助自己熟悉项目代码! 运行原理 在实际使用前,我们 ...

  8. js 基本类型与引用类型的存储

    js的变量类型分为基本数据类型和引用数据类型 7种基本数据类型:null, undefined, number, boolean, string(大多数语言中string属于引用数据类型,而在js中它 ...

  9. Flutter的闪屏动画案例AnimationController

    打开一个APP,经常会看到精美的启动页,这种启动页也称为闪屏动画.它是从无到有有一个透明度的渐变动画的.图像展示完事后,才跳转到用户可操作的页面. AnimationController Animat ...

  10. 解决mosh: Nothing received from server on UDP port 60001 环境: centos7.1

    主要问题在于有的教程使用iptables命令来开启对应端口, 但是centos7.1中虽然iptables仍然存在, 但是没有默认安装相关服务, 而是使用firewalld来管理防火墙. 所以我开始以 ...