【asp.net Core 2.0 初步探索】

首先下载 对应的SDK 和runtime

https://www.microsoft.com/net/core#linuxubuntu           ---------当前为 1.1 稳定版本

2.0 预览版本下载地址:

https://www.microsoft.com/net/core/preview#linuxubuntu

---安装vs 2017的用户 除外

然后 下载 vscode

然后下载 yeoman 这个模板生成工具 进行项目的架子生成
https://docs.microsoft.com/en-us/aspnet/core/client-side/yeoman

安装node.js
C: odejs

在 powershell 中执行下面的命令 安装 bower ,一个js css 脚本管理工具 Bower — a package manager for the web
npm install -g yo bower

然后安装 asp.net core 模板
npm install -g generator-aspnet

The –g flag installs the generator globally, so that it can be used from any path.

--------------使用yoman 的模板生成 或者使用自带的模板生成项目---------
yo 生成: yo aspnet 比较的全面 但是比较旧 跟不上版本变化
或者自带命令:
dotnet new mvc --推荐使用,毕竟自家的东西,版本能及时跟随 sdk -runtime 版本

Creates a new project, configuration file, or solution based on the specified template.
dotnet new <TEMPLATE> [-lang|--language] [-n|--name] [-o|--output] [-all|--show-all] [-h|--help] [Template options]
dotnet new <TEMPLATE> [-l|--list]
dotnet new [-all|--show-all]
dotnet new [-h|--help]
https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new

---------将程序 部署在 Linux  Ubuntu 上----------------------


dotnet build 编译
dotnet run 运行调试
dotnet publish 发布

查看进程:
1,ps -e 命令
用 kill -9 pid 命令,来绝杀

kill $(ps aux | grep 'MySite.dll' | awk '{print $2}') --指定的站点
kill $(ps aux | grep 'dotnet' | awk '{print $2}')--全部asp.net core


最好的方式是使用进程守护工具
supervisor
sudo apt-get install supervisor


I have decided to use supervisor to monitor and manage the process. Here is an excellent article on getting it set up.

It allows simple control over specific dotnet apps like this:
-----------重启站点----------
supervisorctl stop MyWebsiteName
supervisorctl start MyWebsiteName

-----------为进程守护 写配置文件----------
/etc/supervisor/conf.d/bookManage.conf

[program:bookManage]
command=/usr/bin/dotnet /home/chen/webroot/BookManage1.1/bin/Debug/netcoreapp2.0/publish/BookManage.dll
directory=/home/chen/webroot/BookManage1.1/bin/Debug/netcoreapp2.0/publish/
autostart=true
autorestart=true
stderr_logfile=/var/log/BookManage.err.log
stdout_logfile=/var/log/BookManage.out.log
environment=HOME=/var/www/,ASPNETCORE_ENVIRONMENT=Production
user=www-data
stopsignal=INT
stopasgroup=true
killasgroup=true

-----------------------关于进程守护 Supervisor的介绍-----------
重启进程守护 加载新建的配置
sudo service supervisor stop
sudo service supervisor start

Viewing logs

Supervisord logs messages about its own health and its subprocess' state changes to the activity log. The path to the activity log is configured via the logfile parameter in the configuration file.

sudo tail -f /var/log/supervisor/supervisord.log
You can redirect application logs (STDOUT and STERR) in the program section of your configuration file.

tail -f /var/log/hellomvc.out.log


https://serversforhackers.com/monitoring-processes-with-supervisord

------使用nginx 反向 实现 web 服务器上 端口映射------------
sudo apt-get install nginx

sudo service nginx start
server {
listen 80;
location / {
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;
}
}

-----------上面是基本的nginx 配置,实际应用中nginx 有很多可以配置的地方--------------


参考文献:
https://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx
https://github.com/aspnet/Docs/blob/e9c1419175c4dd7e152df3746ba1df5935aaafd5/aspnetcore/publishing/linuxproduction.md

使用Visual Studio Code创建第一个ASP.NET Core应用程序
http://www.cnblogs.com/mengnan/p/5574593.html
https://docs.microsoft.com/en-us/aspnet/core/client-side/yeoman

原文地址:https://www.cnblogs.com/micro-chen/p/7026478.html