• asp.net core 2.1 部署 centos7


    asp.net core 2.1 部署 centos7

    Kestrel 非常适合从 ASP.NET Core 提供动态内容。 但是,Web 服务功能不像服务器(如 IIS、Apache 或 Nginx)那样功能丰富。 反向代理服务器可以从 HTTP 服务器卸载服务静态内容、缓存请求、压缩请求和 SSL 终端等工作。 反向代理服务器可能驻留在专用计算机上,也可能与 HTTP 服务器一起部署。
    鉴于此指南的目的,使用 Nginx 的单个实例。 它与 HTTP 服务器一起运行在同一服务器上。

    • 参考文档
    1. 官方文档
    • 64位安装SDK所需依赖
    1. yum update
    2. yum -y install libunwind
    3. yum -y install libicu
    • 注册微软产品密钥
    1. 执行 sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
    • 安装SDK/runtime
    1. yum -y install dotnet-sdk-2.1 或 yum -y install aspnetcore-runtime-2.1
    • 检测安装
    1. 执行 dotnet --info,验证安装结果,如下:

    .NET Core SDK (reflecting any global.json):

    Version: 2.1.401

    Commit: 91b1c13032

    Runtime Environment:

    OS Name: centos

    OS Version: 7

    OS Platform: Linux

    RID: centos.7-x64

    Base Path: /usr/share/dotnet/sdk/2.1.401/

    ...

    • 创建并允许实例
    1. 创建MVC应用程序 X:mvcApp2 dotnet new mvc
    2. 本地运行(win10) dotnet run
    3. 浏览器访问
    4. 发布linux程序 dotnet publish -c Release -o "XX:Web_IISmvcApp2" -r centos.7-x64

    .net core运行时标识符

    1. xftp上传文件到指定目录 /home/doetnetcore/mvcApp2
    2. 运行程序 cd /home/dotnetcore/mvcApp2 dotnet mvcApp2.dll 如图:默认启用5000端口
    3. centos7 外部计算机若无法访问,请检查网络防火墙(即使关闭防火墙端口默认只开放22)
    4. 检查站点运行情况 curl http://localhost:5000

    curl命令介绍

    1. 查看防火墙状态 firewall-cmd --state //running 表示运行

    附防火墙相关命令

    启动: systemctl start firewalld

    查看状态:systemctl status firewalld

    停止:systemctl disable firewalld

    禁用:systemctl stop firewalld

    启动服务:systemctl start firewalld.service

    关闭服务:systemctl stop firewalld.service

    重启服务:systemctl restart firewalld.service

    服务的状态:systemctl status firewalld.service

    在开机时启用一个服务:systemctl enable firewalld.service

    在开机时禁用一个服务:systemctl disable firewalld.service

    查看服务是否开机启动:systemctl is-enabled firewalld.service

    查看已启动的服务列表:systemctl list-unit-files|grep enabled

    查看启动失败的服务列表:systemctl --failed

    查看版本: firewall-cmd --version

    查看帮助: firewall-cmd --help

    显示状态: firewall-cmd --state

    查看所有打开的端口: firewall-cmd --zone=public --list-ports

    更新防火墙规则: firewall-cmd --reload

    查看区域信息: firewall-cmd --get-active-zones

    查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0

    拒绝所有包:firewall-cmd --panic-on

    取消拒绝状态: firewall-cmd --panic-off

    查看是否拒绝: firewall-cmd --query-panic

    • 配置Nginx转发
    1. 安装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

    1. 检查端口占用情况 yum install net-tools netstat -a //端口列表
    2. 启动 nginx

    命令:systemctl start nginx

    设置开机启动 systemctl enable nginx

    firewall-cmd --zone=public --add-port=80/tcp --permanent(永久启用80端口)

    重启防火墙 systemctl restart firewalld

    浏览器测试nginx能否正常访问

    1. 修改nginx配置文件

    yum -y install vim 可用默认vi替代

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

    通过 vim /etc/nginx/conf.d/default.conf 打开,编辑里面的内容,保存时按 Esc 再输入 :wq! 命令保存退出

    修改为如下脚本:

     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;
        }
      }
    
    
    1. 启动站点 浏览器正常访问asp.netcore 应用程序
    2. Nginx参考文献

    http://nginx.org/en/docs/

    http://tengine.taobao.org/book/index.html

    其他参考文档:https://yq.aliyun.com/articles/584510

    • 配置守护服务(Supervisor)

    • 配置Apache转发

    1. 参考文档
  • 相关阅读:
    数据库设计
    构建评价
    Schema xds文献
    架构设计评价
    需求分析评价
    获取script的链接参数并执行
    js获取封装对象/通过id tag className
    通过css/js来固定div的位置
    nginx日志分析工具goaccesss
    如何快速安装 allure
  • 原文地址:https://www.cnblogs.com/lenovo_tiger_love/p/9610140.html
Copyright © 2020-2023  润新知