• Linux-RedHat7.2 安装.net core2.0


    1、添加dotnet产品Feed

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo sh -c 'echo -e "[packages-microsoft-com-prod]
    name=packages-microsoft-com-prod 
    baseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod
    enabled=1
    gpgcheck=1
    gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'

    2、安装.NET Core SDK 2.0

    sudo yum update
    sudo yum install libunwind libicu
    sudo yum install dotnet-sdk-2.0.0

    3、查看安装状态

    dotnet --info

    4、新建一个console项目,运行

    dotnet new console -o myApp
    cd myApp
    dotnet run

    5、新建一个mvc项目、发布 、开机运行

     新建:

    cd ..
    dotnet new mvc -o mymvc

    修改Startup.cs 文件,nginx反向代理使用。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    
    //添加引用
    using Microsoft.AspNetCore.HttpOverrides;
    
    namespace mymvc
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
    
            }
    
            public IConfiguration Configuration { get; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }
                app.UseStaticFiles();
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
                //添加下面的代码
                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                });
                app.UseAuthentication();
            }
        }
    }

    发布

    cd mymvc
    dotnet publish -c Release

    运行

    cd bin/Release/netcoreapp2.0/publish
    dotnet mymvc.dll

    开机运行(/root 为实际文件目录)

    vim /etc/systemd/system/kestrel-mymvc.service 
    
    -- 内容如下:
    [Unit]
    Description=Example .NET Web MVC Application running on Centos7
    
    [Service]
    WorkingDirectory=/root/mymvc
    ExecStart=/usr/bin/dotnet /root/mymvc/bin/Release/netcoreapp2.0/publish/mymvc.dll
    Restart=always
    RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
    SyslogIdentifier=dotnet-example
    User=root
    Environment=ASPNETCORE_ENVIRONMENT=Production 
    
    [Install]
    WantedBy=multi-user.target
    --启动
    systemctl enable kestrel-mymvc.service 
    systemctl start kestrel-mymvc.service 
    systemctl status kestrel-mymvc.service 
    
    --修改,重启
    systemctl daemon-reload
    systemctl restart kestrel-mymvc.service 

  • 相关阅读:
    .net core3.1 abp动态菜单和动态权限(思路) (二)
    .net core3.1 abp学习开始(一)
    api.versioning 版本控制 自动识别最高版本
    .netcore 定制化项目开发的思考和实现
    netcore 非注入全局获取配置文件
    linux nginx搭建与使用
    linux docker .net core 从建立网站到预览
    linux 学习 mysql安装到连接
    linux 安装redis及问题收集
    为何说要多用组合少用继承?如何决定该用组合还是继承?
  • 原文地址:https://www.cnblogs.com/kuangxiangnice/p/9597445.html
Copyright © 2020-2023  润新知