在CentOS 8 上 部署 .Net Core 应用程序
在Centos 8 上 部署 .Net Core 应用程序
—— 记录篇
1、更新dnf 源
1 dnf update
2、安装 Asp.Net Core 运行时
1 dnf install aspnetcore-runtime-3.1
2.1、验证是否安装成功
1 dotnet --info

出现如上图所示就说明安装成功
3、安装Nginx
dnf -y install nginx
3.1、查看nginx版本
nginx -v

3.2、设置开机自启动
1 systemctl enable nginx
3.3、启动 nginx 服务
service nginx start
3.4、其他 相关 指令
1 # 卸载
2 dnf remove nginx
3 # 停止 服务
4 service nginx stop
5 # 重启
6 service nginx restart
7 # 加载配置文件
8 service nginx reload
4、MySql 安装
4.1、下载
wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
4.2、使用rpm 安装 mysql
rpm -ivh mysql80-community-release-el8-1.noarch.rpm
4.3、dnf 安装 mysql 服务
dnf -y install mysql-server
4.4、设置开机自启动
systemctl enable mysqld.service
4.5、启动mysql
systemctl start mysqld.service
4.6、设置远程连接(可选)
因我时在某云上,所以需要设置我本地连接,如果是在自己虚拟器可跳过此步骤
4.6.1、进入 mysql 命令行

4.6.2、更新 系统表(user)
update mysql.user set host="%" where user="root";

4.6.3、设置 root 密码
-- 切换数据库
use mysql;
-- 执行语句
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
-- 刷新修改后的权限
flush privileges;
-- 退出
exit;
4.6.4、测试

5、将应用程序发布后的包上传
5.1、创建文件夹(用于存放应用程序包)
mkdir -p /var/www/web
5.2、ftp 上传应用程序文件到 上一步创建的文件夹(/var/www/web/)中
6、Redis 安装(可选)
如果项目中没有用到 Redis 可以跳过此步骤
6.1、下载、解压、编译
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
tar xzf redis-6.0.6.tar.gz
cd redis-6.0.6
dnf install tcl
make
6.2、编译测试
make test
6.3、迁移到指定的目录(可选)
1 mkdir -p /usr/local/soft/redis
2 cd /usr/local/soft/redis/
3 mkdir bin
4 mkdir conf
5 cd bin/
6 cp /redis-6.0.6/src/redis-cli ./
7 cp /redis-6.0.6/src/redis-server ./
8 cd ../conf/
9 cp /redis-6.0.6/redis.conf ./
10 # 配置 redis-server 的 配置文件为 /usr/local/soft/conf/redis.conf
11 /usr/local/soft/redis/bin/redis-server /usr/local/soft/redis/conf/redis.conf
12 # 检查端口是否在使用
13 netstat -anp | grep 6379
6.4、使用 systemd 方式守护 redis 进程
6.4.1、编辑 redis.service 文件
vim /lib/systemd/system/redis.service
6.4.2、设置redis.service 内容
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/soft/redis/bin/redis-server /usr/local/soft/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6.4.3、重载系统
systemctl daemon-reload
6.4.4、设置开机启动及其他指令
# 开机自启
systemctl enable redis
# 启动
systemctl start redis
# 查看状态
systemctl status redis
# 停止
systemctl stop redis
7、配置.Net Core 应用程序的守护进程
7.1、编辑 aspnetCore.service 文件
文件名 自定义,这里我起名为 aspnetCore.service
vim /lib/systemd/system/aspnetCore.service
7.2、编辑内容
[Unit]
Description=AspnetCoreDemo running on Centos8 [Service]
# 应用程序所在的文件目录
WorkingDirectory=/var/www/web/
ExecStart=/usr/bin/dotnet /var/www/web/Carefree.AspNetCoreDemo.dll
Restart=always
# 如果dotnet服务崩溃,10秒后重新启动服务
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=AspNetCoreDemo
User=root
#Production:生产环境 Development:开发环境
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install]
WantedBy=multi-user.target
7.3、重载系统及设置开机启动
# 重载系统
systemctl daemon-reload
# 开机自启动
systemctl enable aspnetCore.service
8、Nginx 代理
8.1、编辑配置文件
vim /etc/nginx/conf.d/web.conf
8.2、编辑内容
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;
proxy_set_header X-Forwarded-For
proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
8.3、编辑 nginx.conf 文件

8.4、验证配置文件是否正确及加载配置文件
# 验证配置文件
nginx -t
# 加载配置文件
nginx -s reload
至此我们的应用程序可正常访问了。如有何问题可与我联系,共同学习。
在CentOS 8 上 部署 .Net Core 应用程序的更多相关文章
- So Easy - 在Linux服务器上部署 .NET Core App
.NET Core 是微软提供的免费.跨平台和开源的开发框架,可以构建桌面应用程序.移动端应用程序.网络应用程序.物联网应用程序和游戏应用程序等.如果你是 Windows 平台下的 dotnet 开发 ...
- 如何在CentOS 7上部署Google BBR【搬运、机翻】
如何在CentOS 7上部署Google BBR 本文章搬运自 https://www.vultr.com/docs/how-to-deploy-google-bbr-on-centos-7 [注:文 ...
- 在CentOS 7上安装.NET Core R2跑Hello World
前言 在上个月.NET Core出了最新版本预览版,只是在Window系统上试验了一下.原本想等发布正式版的时候在linux系统上试试,可能还需要一段时间,刚好有空可以折腾一下. 由于之前安装的Ubu ...
- IIS上部署Net.Core
部署: 1.安装vc_redist.x64vc_redist.x64 2.安装DotNetCore.1.0.0.RC2-WindowsHosting 3.安装DotNetCore.1.0.0-SDK. ...
- 如何在centos操作系统上发布.net core的项目
环境:操作系统: centos 7.net core: 2.1.101 官方网站的示例地址: https://docs.microsoft.com/zh-cn/dotnet/core/linux-pr ...
- 在CentOS 7上部署Ghost博客
作者:waringid 一.简介 跟静态博客不同的是,Ghost 这种轻量级的动态博客,有一个管理后台,可以直接写作和管理博客.本质上,跟 WordPress 是相通的,只是 Ghost 搭建在 No ...
- 在IIS上部署 .Net Core 3.0 项目踩坑实录
在IIS上部署 .Net Core 3.0 项目的主要流程有: 安装并启用IIS 安装AspNetCoreModuleV2 添加.配置网站 设置应用程序池 通过VS发布 一.安装并启用IIS: 安装了 ...
- Centos7安装.Net Core 2.2环境以及部署.Net Core MVC程序(Apache+Jexus环境)
原文:Centos7安装.Net Core 2.2环境以及部署.Net Core MVC程序(Apache+Jexus环境) 1.双11抢购***VPS.配置如下: CPU:2 核 内存:2048 M ...
- [翻译]第三天- 在 Mac 上运行 .NET Core 应用程序
原文: http://michaelcrump.net/part3-aspnetcore/ *** 简介 该系列文章的完整列表如下: 第一天 - 在 Windows 下安装和运行 .NET Core ...
随机推荐
- selenium初探
先看看官方给的小demo from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = ...
- Git裸仓库的分支(Active Branch)切换
Git裸仓库的Active Branch切换方法 在服务器上通过init --bare创建了一个裸仓库作为远程仓库使用,并且存在三个分支(master/kid/develop),但在使用中发现代码虽然 ...
- Win10 搭建FTP环境,并使用Java实现上传,下载,删除
测试的环境一般都是在自己电脑上面装的,现在一般都使用Win10开发 搭建FTP: 第一步:打开控制面板:点击程序 第二步: 第三步: 然后点击确认后等待完成 完成后在启动中找到IIS管理器 打开 在网 ...
- NodeJS沙箱逃逸&&vm
NodeJS沙箱逃逸 关于nodejs的沙箱 使用场景 在线代码编辑器 第三方js代码 jsonp,like百度搜索框 https://www.baidu.com/s?wd=nodejs&mi ...
- get 跟post的区别
get参数通过url传递,post放在request body中 :get请求在url中传递的参数是有长度限制的,而post没有.
- Python-IndexError: list index out of range
Error:IndexError: list index out of range Where? 对Python中有序序列进行按索引取值的时候,出现这个异常 Why? 对于有序序列: 字符串 str ...
- 朴素贝叶斯分类器Naive Bayes
优点Naive Bayes classifiers tend to perform especially well in one of the following situations: When t ...
- Linux学习笔记-vi(一)
vim编辑命令 vim命令的三种模式: 1.命令模式: vi file.txt 进入vi模式,默认为命令模式,命令模式移动光标. 2.插入模式 i (insert):在光标前插入内容 a(appen ...
- Mysql中 int(3) 类型的含义
注意:这里的(3)代表的并不是存储在数据库中的具体的长度,以前总是会误以为int(3)只能存储3个长度的数字,int(11)就会存储11个长度的数字,这是大错特错的. 其实当我们在选择使用int的类型 ...
- The Python Tutorial 和 documentation和安装库lib步骤
链接: The Python Tutorial : https://docs.python.org/3.6/tutorial/index.html Documentation: https://doc ...