ASP.NET CORE部署到Linux
ASP.NET CORE部署到CentOS中
- 在Linux上安装.NET Core
- 配置Nginx
安装前准备
yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl--devel下载安装Nginx,执行如下命令
解压
tar -zxvf nginx-1.11.13.tar.gz
进入解压目录
cd nginx-1.11.13
配置
./configure --prefix=/usr/local/nginx
- 注意:这里可能会报错,提示“pcre.h No such file or directory”,需要安装
libprce3-dev:sudo apt-get install libpcre3-dev 注意:提示“./configure: error: C compiler cc is not found”,需要检查是否安转了
常用必备支持库,如没有,需要安装g++,gcc:yum install gcc-c++安装nginx
make
make install- systemctl start nginx 来启动nginx
systemctl enable nginx 来设置nginx的开机启动
配置防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口)
systemctl restart firewalld(重启防火墙以使配置即时生效)
systemctl stop firewalld.service(关闭防火墙)
systemctl disable firewalld.service(关闭开机启动)- 配置ASP.NET Core应用的转发
修改 /etc/nginx/conf.d/default.conf 文件
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 –s reload 使其即时生效若出现502错误;这个问题是由于SELinux保护机制所导致,我们需要将nginx添加至SELinux的白名单。
yum install policycoreutils-python
cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
semodule -i mynginx.pp
- 配置守护服务(Supervisor)
安装Supervisor
yum install python-setuptools
easy_install supervisor配置Supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf修改supervisord.conf文件,将文件尾部配置改为
[include]
files=conf.d/*.conf修改配置文件可用 supervisorctl reload 命令使其生效
- 配置ASP.NET Core应用的守护
创建一个WebDemo.conf文件,内容如下
[program:WebDemo]
command=dotnet WebDemo.dll (运行程序的命令)
directory=/root/code/WebDemo/ (命令执行的目录)
autorestart=true (程序意外退出是否自动重启)
stderr_logfile=/var/log/WebDemo.err.log (错误日志文件)
stdout_logfile=/var/log/WebDemo.out.log (输出日志文件)
environment=ASPNETCORE_ENVIRONMENT=Production (进程环境变量)
user=root (进程执行的用户身份)
stopsignal=INT将文件拷贝至:“/etc/supervisor/conf.d/”目录下
运行supervisord查看是否生效
supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep WebDemo- 可能出现的问题
- 运行supervisord -c /etc/supervisor/supervisord.conf报错
Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
解决办法
ps -ef |grep supervisord
kill -s SIGTERM 2503
- 配置Supervisor开机启动
新建一个supervisord.service文件
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target将文件拷贝至:“/usr/lib/systemd/system/”目录下
systemctl enable supervisord
systemctl is-enabled supervisord 验证是否为开机启动
ASP.NET CORE部署到Linux的更多相关文章
- Asp.Net Core部署到Linux服务器
从2016年7月, .NET Core1.0 正式发布开始,由于时间问题,我没怎么关注过.NET Core,最近刚抽出点时间研究了下,先讲下如何把ASP.NET Core部署到Linux上吧.这里我用 ...
- 从零开始,将ASP.NET Core部署到Linux生产环境
研究.NET Core已经一段时间了,一直都是在Windows上开发,这2天尝试着将公司一个很简单的内部Web项目改造成了ASP.NET Core,并且部署到Linux上.生产环境如下: Linux ...
- ASP.NET Core 实战:Linux 小白的 .NET Core 部署之路
一.前言 最近一段时间自己主要的学习计划还是按照毕业后设定的计划,自己一步步的搭建一个前后端分离的 ASP.NET Core 项目,目前也还在继续学习 Vue 中,虽然中间断了很长时间,好歹还是坚持 ...
- ASP.Net Core 运行在Linux(Ubuntu)
这段时间一直在研究asp.net core部署到linux,今天终于成功了,这里分享一下我的部署过程. Linux Disibutaion:Ubuntu 14.04 Web Server:nginx. ...
- ASP.NET Core MVC 在linux上的创建及发布
前言 ASP.NET core转眼都发布半月多了,社区最近也是非常活跃,虽然最近从事python工作,但也一直对.NET念念不忘,看过了园区大神们搭建的Asp.net core项目之后,自己也是跃跃欲 ...
- .NET Core部署到linux(CentOS)最全解决方案,常规篇
本文为大家介绍使用 .NET Core部署到Linux服务器的方法,通过本文你将了解到Linux在虚拟机下的安装.Xshell,Xftp的使用方法.git在linux下的交互使用以及.net core ...
- .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx)
在.NET Core部署到linux(CentOS)最全解决方案,常规篇一文,我们详细讲解了传统的.NET Core部署到Linux服务器的方法,学到了Linux在虚拟机下的安装.Xshell,Xft ...
- .NET Core部署到linux(CentOS)最全解决方案,高阶篇(Docker+Nginx 或 Jexus)
在前两篇: .NET Core部署到linux(CentOS)最全解决方案,常规篇 .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx) 我们对. ...
- ASP.NET Core 发布至Linux生产环境 Ubuntu 系统
ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而没有将整个系统串起来. 今天就跟大家综合的讲一下ASP.NET Core ...
随机推荐
- html、css、js实现手风琴图片滑动
手风琴图片滑动是我最近学的一个图片的效果,感觉不错,分享给大家. 最终效果见 :http://gjhnstxu.me/squeezebox/demo.html 详细代码如下: html代码: < ...
- 机器学习基石 2 Learning to Answer Yes/No
机器学习基石 2 Learning to Answer Yes/No Perceptron Hypothesis Set 对于一个线性可分的二分类问题,我们可以采用感知器 (Perceptron)这种 ...
- 对bootstrap不同版本的总结
之前以为bootstrap2和bootstrap3没啥区别,无非就是功能增加了,简直是误区啊 bootstrap3与bootstrap2版本语法都不同啦 栅格写法 col-md-3/span3 文本效 ...
- javascript解析机制、闭包详解
js解析机制: js代码解析之前会创建一个如下的词法环境对象(仓库):LexicalEnvironment{ } 在扫描js代码时会把: 1.用声明的方式创建的函数的名字: 2.用var定义的变量的名 ...
- Linux运行级别简介
init 0 : 关机 init 1 : 单用户模式 root init 2 : 多用户模式 不能使用 net file system init 3 : 完全多用户模式 init 4 : 多用户的安 ...
- Win10上编译CoreCLR的Windows和Linux版本
一.编译环境 首先,不管是Windows还是Linux版本CoreCLR的编译,都是在Windows10上进行的. 二.CoreCLR for Windows 在Windows上做编译怎么能少得了Vi ...
- oracle图形界面乱码
oracle界面乱码解决方案 在Linux的中文操作系统下使用xmanager进行Oracle进行安装的时候,可能出现乱码界面,可以通过以下方法进行解决 1 修改环境属性 vi /etc/sysco ...
- Build your own linino system 编译你自己的linino系统
懒癌犯了,先简单写过程,之后有时间再补上每一步的理由吧.对着来一遍,有bug请留言,我会尝试回答.(づ ̄ 3 ̄)づ ------------------------------------------ ...
- 实现类似MVC ViewBag类型的对象
public class ViewBag : DynamicObject { private readonly Dictionary<string,dynamic> dic=new Dic ...
- smm框架学习------smm框架整合实现登录功能(一)
一.准备所需的jar包 1.1所需jar包 1.Spring框架jar包 2.Mybatis框架jar包 3.Spring的AOP事务jar包 4.Mybatis整合Spring中间件jar包 5.a ...