• 记录成功配置 centos + nginx + .net core 2.0


    用到的软件如下

    • xshell
    • xftp
    • vs2017.3
    • centos 7.3 64位

    安装环境:

    .net core 2.0 可以在以下版本linux 下运行

    • Red Hat Enterprise Linux 7 x64
    • CentOS 7 x64
    • Oracle Linux 7 x64
    • Fedora 25, 26 x64
    • Debian 9, 8.7+ x64
    • Ubuntu 17.04, 16.04, 14.04 x64
    • Linux Mint 18, 17 x64
    • openSUSE 42.2+ x64
    • SUSE Enterprise Linux (SLES) 12 SP2+ x64

    实验用到的环境

    aliyun centos 7.3 64位

    安装.net core 2.0 依赖的组件

    • deltarpm
    • epel-release
    • unzip
    • libunwind
    • gettext
    • libcurl-devel
    • openssl-devel
    • zlib
    • libicu-devel

    直接yum安装这些组件

    yum install deltarpm epel-release unzip libunwind gettext libcurl-devel openssl-devel zlib libicu-devel
    

      

    安装.net core 2.0

    sudo dnf install libunwind libicu
    curl -sSL -o dotnet.tar.gz https://aka.ms/dotnet-sdk-2.0.0-linux-x64
    sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
    sudo ln -s /opt/dotnet/dotnet /usr/local/bin
    dotnet --help
    

      

    在命令 dotnet --help 看到下面信息就安装.net core 2.0成功了

    [root@iZ6r8lfyydxll0Z ~]# dotnet --help
    .NET Command Line Tools (2.0.0)
    Usage: dotnet [runtime-options] [path-to-application]
    Usage: dotnet [sdk-options] [command] [arguments] [command-options]
    
    path-to-application:
      The path to an application .dll file to execute.
    
    SDK commands:
      new              Initialize .NET projects.
      restore          Restore dependencies specified in the .NET project.
      run              Compiles and immediately executes a .NET project.
      build            Builds a .NET project.
      publish          Publishes a .NET project for deployment (including the runtime).
      test             Runs unit tests using the test runner specified in the project.
      pack             Creates a NuGet package.
      migrate          Migrates a project.json based project to a msbuild based project.
      clean            Clean build output(s).
      sln              Modify solution (SLN) files.
      add              Add reference to the project.
      remove           Remove reference from the project.
      list             List reference in the project.
      nuget            Provides additional NuGet commands.
      msbuild          Runs Microsoft Build Engine (MSBuild).
      vstest           Runs Microsoft Test Execution Command Line Tool.
    
    Common options:
      -v|--verbosity        Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
      -h|--help             Show help.
    
    Run 'dotnet COMMAND --help' for more information on a command.
    
    sdk-options:
      --version        Display .NET Core SDK version.
      --info           Display .NET Core information.
      -d|--diagnostics Enable diagnostic output.
    
    runtime-options:
      --additionalprobingpath <path>    Path containing probing policy and assemblies to probe for.
      --fx-version <version>            Version of the installed Shared Framework to use to run the application.
      --roll-forward-on-no-candidate-fx Roll forward on no candidate shared framework is enabled.
      --additional-deps <path>          Path to additonal deps.json file.
    

      

    使用VS2017.3  新建一个.net core 2.0 的测试代码

    可以从此地址下载:https://files.cnblogs.com/files/fun5/webcore.zip

    使用xftp 把生成好的程序 (webcorewebcoreinDebug etcoreapp2.0publish下的文件)上传到 /home/test 目录下

    执行命令

    cd /home/test
    dotnet webcore.dll & 

    可以看到 已经运行起来了,localhost:5000

    安装配置nginx

    yum install nginx

    配置nginx.conf

        server {
    
    		listen 80;
            server_name  test.fun5.cn;
    
    		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;
    		}
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
    

      

    执行 nginx -s reload
    

    访问 nginx 绑定的域名可以看到网站可以跑起来了 http://test.fun5.cn/

    配置守护进程

     

    安装Supervisor

    yum install supervisor
    

    Supervisor配置文件,创建一个ini 配置文件 webcore.ini

    [program:webcore]
    command=dotnet webcore.dll
    directory=/home/test 
    environment=ASPNETCORE__ENVIRONMENT=Production 
    user=root
    stopsignal=INT
    autostart=true
    autorestart=true
    startsecs=3 
    stderr_logfile=/var/log/webcore.err.log  
    stdout_logfile=/var/log/webcore.out.log
    

      

    创建好之后,使用 xftp 上次到 /etc/supervisord.d 目录下

    最后启动

    supervisord  -c /etc/supervisord.conf
    

      


    如果想要supervisord开机自启动

    # 编辑启动文件
    vi /etc/rc.local
    # 在新行添加要执行的命令
    supervisord  -c /etc/supervisord.conf
    常用命令
    # 查看所有action
    supervisorctl help

    # 控制所有进程
    supervisorctl start all
    supervisorctl stop all
    supervisorctl restart all

    # 控制目标进程
    supervisorctl stop shadowsocks
    supervisorctl start shadowsocks
    supervisorctl restart shadowsocks

    结束!

    参考资料

    https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction

    https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x

  • 相关阅读:
    Ubutun 安装oh-my-zsh
    归并算法
    3n+1问题
    插入排序
    二分查找
    rehl7配置本地yum仓库
    解决Anaconda3报错:AttributeError: '_NamespacePath' object has no attribute 'sort'
    深度学习情感分析(随机梯度下降代码实现)
    MySQL中创建数据库/表(外键约束),向表中插入数据
    python---利用unittestreport模块输出测试报告
  • 原文地址:https://www.cnblogs.com/fun5/p/7398836.html
Copyright © 2020-2023  润新知