目录

Aspnetcore api 服务发布指南

一、 搭建nginx服务器

  1. 下载安装gcc编译库
  2. 下载安装pcre正则表达式库
  3. 下载安装openssl安全加密库
  4. 下载安装zlib解压库
  5. 下载解压并编译安装nginx
  6. 启动nginx
  7. 设置nginx开机启动
  8. 查看nginx状态
  9. 常用nginx命令

二、 安装.net5 runtime

  1. 设置下载源
  2. 安装运行时

三、 上传发布的项目文件并创建服务

  1. 安装工具WinSCP
  2. 使用WinSCP在linux服务器创建服务目录
  3. 将vs2019发布的项目使用WinSCP上传到指定目录
  4. 使用putty创建linux服务
  5. linux服务操作相关命令

四、 配置nginx代理和防火墙

  1. 查看防火墙状态
  2. 启动防火墙
  3. 添加指定的端口
  4. 查看网口
  5. 添加网口到公开区域中
  6. 添加nginx反向代理配置

五、 运行截图

  1. nginx运行截图
  2. Aspnetcore api运行截图

一、搭建nginx服务器

  1. 下载安装gcc编译库

gcc -v

yum -y install gcc

  1. 下载安装pcre正则表达式库

yum install -y pcre pcre-devel

  1. 下载安装openssl安全加密库

yum install -y openssl openssl-devel

  1. 下载安装zlib解压库

yum install -y zlib zlib-devel

  1. 下载解压并编译安装nginx

wget http://nginx.org/download/nginx-1.9.9.tar.gz

tar -zxvf nginx-1.9.9.tar.gz

cd nginx-1.9.9

./configure --prefix=/usr/local/nginx

make&&make install

  1. 启动nginx

cd /usr/local/nginx/sbin

./nginx

  1. 设置nginx开机启动

#在rc.local增加启动代码即可

vi /etc/rc.local

#增加一行 /usr/local/nginx/sbin/nginx,增加后保存

#设置执行权限

cd /etc

chmod 755 rc.local

  1. 查看nginx状态

通过端口查询: lsof -i:80 #nginx默认是80端口

通过进程查询: ps -ef | grep nginx

访问网页查询 curl 127.0.0.1

  1. 常用nginx命令

nginx -s stop :快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。

nginx -s quit :平稳关闭Nginx,保存相关信息,有安排的结束web服务。

nginx -s reload :因改变了Nginx相关配置,需要重新加载配置而重载。

nginx -s reopen :重新打开日志文件。

nginx -c filename :为 Nginx 指定一个配置文件,来代替缺省的。

nginx -t :不运行,而仅仅测试配置文件。nginx将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的 文件。

nginx -v:显示 nginx 的版本。

nginx -V:显示 nginx 的版本,编译器版本和配置参数

二、安装.net5 runtime

  1. 设置下载源

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

  1. 安装运行时

sudo yum install dotnet-runtime-5.0

sudo yum install aspnetcore-runtime-5.0

三、上传发布的项目文件并创建服务

  1. 安装工具WinSCP
  2. 使用WinSCP在linux服务器创建服务目录
  3. 将vs2019发布的项目使用WinSCP上传到指定目录
  4. 使用putty创建linux服务

cd /lib/systemd/system

sudo touch Oceania.ShopConfigService.service

sudo nano Oceania.ShopConfigService.service

配置ShopConfig.service服务文件

[Unit]

Description= ShopConfigService

[Service]

WorkingDirectory=/root/apiservices/Oceania.ShopConfigService/

ExecStart=/usr/bin/dotnet /root/apiservices/Oceania.ShopConfigService/Oceania.ShopConfigService.Api.Host.dll

Restart=always

RestartSec=10

SyslogIdentifier= ShopConfigService

User=root

Environment=ASPNETCORE_ENVIRONMENT=Production

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]

WantedBy=multi-user.target

然后输入

ctrl+x ->y 回车

  1. linux服务操作相关命令

systemctl  enable Oceania.ShopConfigService.service

systemctl  start Oceania.ShopConfigService.service

systemctl  status Oceania.ShopConfigService.service

systemctl [command] [unit]

command 主要有:

start:立刻启动后面接的 unit

stop:立刻关闭后面接的 unit。

restart:立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思。

reload:不关闭 unit 的情况下,重新载入配置文件,让设置生效。

enable:设置下次开机时,后面接的 unit 会被启动。

disable:设置下次开机时,后面接的 unit 不会被启动。

status:目前后面接的这个 unit 的状态,会列出有没有正在执行、开机时是否启动等信息。

is-active:目前有没有正在运行中。

is-enable:开机时有没有默认要启用这个 unit。

kill :不要被 kill 这个名字吓着了,它其实是向运行 unit 的进程发送信号。

show:列出 unit 的配置。

mask:注销 unit,注销后你就无法启动这个 unit 了。

unmask:取消对 unit 的注销。

四、配置nginx代理和防火墙

  1. 查看防火墙状态

firewall-cmd --state

  1. 启动防火墙

service firewalld start

  1. 添加指定的端口

firewall-cmd --zone=public --add-port=80/tcp

firewall-cmd --zone=public --add-port=5000/tcp

  1. 查看网口

ifconfig

  1. 添加网口到公开区域中

firewall-cmd --zone=public --add-interface=ens192

  1. 添加nginx反向代理配置

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

#                  '$status $body_bytes_sent "$http_referer" '

#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;

#tcp_nopush     on;

#keepalive_timeout  0;

keepalive_timeout  65;

#gzip  on;

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

location /shopconfigservice/ {

proxy_pass         http://localhost:5000;  #本地应用地址及端口,可以使用 curl 命令测试一下

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;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass   http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#    listen       8000;

#    listen       somename:8080;

#    server_name  somename  alias  another.alias;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

# HTTPS server

#

#server {

#    listen       443 ssl;

#    server_name  localhost;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;

#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#    ssl_prefer_server_ciphers  on;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

}

五、运行截图

  1. nginx运行截图
  1. Aspnetcore api运行截图

也可以输入:http://192.168.11.120/shopconfigservice/swagger/index.html 测试

六、发布更新

  1. 发布邮件接口服务

cd /usr/lib/systemd/system

sudo touch Oceania.MailApiService.service

sudo nano Oceania.MailApiService.service

[Unit]

Description= Oceania.MailApiService.service

[Service]

WorkingDirectory=/root/net5services/Oceania.MailService.Api.Host

ExecStart=/usr/bin/dotnet /root/net5services/Oceania.MailService.Api.Host/Oceania.MailService.Api.Host.dll urls=”http://*:5011”

Restart=always

RestartSec=10

SyslogIdentifier= Oceania.MailApiService.service

User=root

Environment=ASPNETCORE_ENVIRONMENT=Production

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]

WantedBy=multi-user.target

先Ctrl+x 再y

systemctl enable Oceania.MailApiService.service

systemctl start Oceania.MailApiService.service

systemctl status Oceania.MailApiService.service

查询端口

lsof -i tcp:80

curl http://127.0.0.1:5010/api/mail/getemailserverlist

或者

http://192.168.11.120/mailservice/swagger/index.html

  1. 发布邮件发送服务

使用winSCP上传文件

cd /usr/lib/systemd/system

sudo touch Oceania.MailService.service

sudo nano Oceania.MailService.service

[Unit]

Description= Oceania.MailService.service

[Service]

WorkingDirectory=/root/net5services/Oceania.MailService.Host

ExecStart=/usr/bin/dotnet /root/net5services/Oceania.MailService.Host/Oceania.MailService.Host.dll

Restart=always

RestartSec=10

SyslogIdentifier= Oceania.MailService.service

User=root

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]

WantedBy=multi-user.target

先Ctrl+x 再y

systemctl enable Oceania.MailService.service

systemctl start Oceania.MailService.service

systemctl status Oceania.MailService.service

.net5发布到Linux指南的更多相关文章

  1. 将 ASP.NET Core 1.0 应用作为 docker 镜像发布 (Linux版)

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  2. ASP.NET Core 发布至Linux生产环境 Ubuntu 系统

    ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而没有将整个系统串起来. 今天就跟大家综合的讲一下ASP.NET Core ...

  3. 发布《Linux工具快速教程》

    发布<Linux工具快速教程> 阶段性的完成了这本书开源书籍,发布出来给有需要的朋友,同时也欢迎更多的朋友加入进来,完善这本书: 本书Github地址:https://github.com ...

  4. SQLServer 2008 R2 发布订阅配置指南

    原以为配置SQLServer 2008 R2的发布订阅很简单,实际配置后才发现过程中有问题地方一直都没搞明白,最后经过几天的查找问题和实践,终于搞定了.现将过程记录如下. SQLServer 2008 ...

  5. Core 发布至Linux

    ASP.NET Core 发布至Linux生产环境 Ubuntu 系统 ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而 ...

  6. DS Scheduler 0.7 发布,Linux 调度系统 - 开源中国社区

    DS Scheduler 0.7 发布,Linux 调度系统 - 开源中国社区 DS Scheduler 0.7 发布,Linux 调度系统

  7. ASP.NET Core 网站发布到Linux服务器

    长期以来,使用.NET开发的应用只能运行在Windows平台上面,而目前国内蓬勃发展的互联网公司由于成本的考虑,大量使用免费的Linux平台,这就使得.NET空有一身绝技但无法得到广大的施展空间,.N ...

  8. ASP.NET Core 网站发布到Linux服务器(转)

    出处;ASP.NET Core 网站发布到Linux服务器 长期以来,使用.NET开发的应用只能运行在Windows平台上面,而目前国内蓬勃发展的互联网公司由于成本的考虑,大量使用免费的Linux平台 ...

  9. .netcoreapp 发布到 linux 的问题,vs靠不住

    .netcore 2.0 发布后,小版本更新速度惊人 截止目前:2.1.200 最新一个新项目,vs发布到linux@debian9一直报错,反复发布n次依然失败.把本地2.1.100更新到最新2.1 ...

  10. java项目发布到linux服务器,tomcat正常启动但没加载项目

    问题描述: java项目发布到linux服务器,一切操作正确,linux命令启动tomcat后,查看日志启动tomcat正常,上传的war包已经解压成功,但是tomcat没加载项目. 解决方法: 1. ...

随机推荐

  1. compilation.templatesPlugin is not a function

    ERROR Failed to compile with 1 error TypeError: compilation.templatesPlugin is not a function - SetV ...

  2. Hugging News #0609: 最新代码生成模型 StarCoder+ 和 StarChat Beta 重磅发布!

    每一周,我们的同事都会向社区的成员们发布一些关于 Hugging Face 相关的更新,包括我们的产品和平台更新.社区活动.学习资源和内容更新.开源库和模型更新等,我们将其称之为「Hugging Ne ...

  3. AtCoder Beginner Contest 218 A~D

    比赛链接:Here A - Weather Forecas 水题,判断 \(s[n - 1] = o\) 的话输出 YES B - qwerty 题意:给出 \((1,2,...,26)\) 的某个全 ...

  4. 【每日一题】23.Removal (计数DP)

    补题链接:Here 计数DP讲解:Here 这是一个计数类的dp dp[i][j]表示前i个数字中,删除j个元素的方案数 很容易得到转移方程:\(f[i][j] = f[i - 1][j - 1] + ...

  5. mysql 使用 trim去不掉空格 解决

    使用mysql8.0时 发现 有几个空字符串怎么也过滤不掉,使用 is not null.trim()<>''.length()>=1都不行,最后查了一些资料说 trim只能去除半角 ...

  6. 使用JSEncrypt加密解密

    最近项目中使用非对称加密JSEncrypt. uni-app中先安装第三方npm包jsencrypt util文件夹下新建一个jsencrypt.js文件 1 import JSEncrypt fro ...

  7. windows10测试时如何构造大图片(如超过8M+的图片)

    1.原图片(大小40k) 2. 选怎一个容量大的文件如视频文件8M+ 3.使用copy命令进行扩容(cmd命令行操作): copy test01.jpg /b + 8M.MP4 test01_8M.j ...

  8. java基础-反射-day15

    目录 1. 案例引入 2. Class 的理解 3. 反射的详细使用 4. Class 类都有哪些实例 5. 详细使用 6. 获取属性 7. 获取方法 8 获取类的 接口 注解 所在的包 9. 思考 ...

  9. 一文搞清楚Java中的方法、常量、变量、参数

    写在开头 在上一篇文章:一文搞清楚Java中的包.类.接口 中我们讲了Java中的包.类和接口,今天继续将剩下的方法.常量.变量以及参数梳理完. Java中的变量与常量 在JVM的运转中,承载的是数据 ...

  10. AI毕业设计生成器(基于AI大模型技术开发)

    这是一个辅助生成计算机毕业设计的工具,可以自动完成毕业设计的源码.它基于几百个github上面开源的java和python项目,运用tengsorflow技术,训练出了AI大模型.基本实现了计算机毕业 ...