这里我们先做一些准备工作
    下载代码(此处提供代码案例,地址如下)

    1. git clone https://code.aliyun.com/XuanServer/structure.git

    安装.net 开发包

    1. //将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库。
    2. sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
    3. //安装sdk .net 6
    4. sudo yum install dotnet-sdk-6.0
    5. //安装nuget
    6. yum install nuget
    7. //以下可选不安装,这里只是顺带提示
    8. //安装asp.net runtime
    9. sudo yum install aspnetcore-runtime-6.0
    10. //安装.net runtime
    11. sudo yum install dotnet-runtime-6.0

    编译

    1. //进入代码目录
    2. cd structure
    3. //包还原
    4. nuget restore SSO.sln
    5. //编译此处一共有两个站点,可更具自己情况更换
    6. dotnet build ~/structure/SSO/SSO.csproj -c Release -o ~/build/Release/SSO

    此时,我们已经成功编译了
    下一步将安装nginx

    1. //添加nginx源
    2. sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    3. //安装
    4. yum install -y nginx
    5. //启动
    6. systemctl start nginx.service
    7. //设置开机启动
    8. systemctl enable nginx.service

    因为部署需要runtime
    这里上面没安装的需要安装一下

    1. //安装asp.net runtime
    2. sudo yum install aspnetcore-runtime-6.0
    3. //.NET需要的组件
    4. sudo yum install libunwind libicu

    这里提一下nginx配置

    1. Nginx配置信息
    2. 网站文件存放默认目录
    3. /usr/share/nginx/html
    4. 网站默认站点配置
    5. /etc/nginx/conf.d/default.conf
    6. 自定义Nginx站点配置文件存放目录
    7. /etc/nginx/conf.d/
    8. Nginx全局配置
    9. /etc/nginx/nginx.conf
    10. Nginx启动
    11. nginx -c nginx.conf

    创建配置文件

    1. //创建配置文件
    2. vim /etc/nginx/conf.d/sso.conf
    3. //粘贴以下内容 保存
    4. server {
    5. listen 8089;
    6. server_name "";
    7. location / {
    8. proxy_pass http://localhost:5000;
    9. proxy_http_version 1.1;
    10. proxy_set_header Upgrade $http_upgrade;
    11. proxy_set_header Connection keep-alive;
    12. proxy_set_header Host $host;
    13. proxy_cache_bypass $http_upgrade;
    14. }
    15. }
    16. //重启
    17. nginx -s reload

    创建守护进程

    1. //创建服务
    2. cd /etc/systemd/system
    3. vim kestrel-sso.service
    4. //将以下内容粘贴
    5. [Unit]
    6. Description=SSOWebServer
    7. [Service]
    8. Type=simple
    9. WorkingDirectory=/root/build/Release/SSO
    10. ExecStart= /usr/local/bin/dotnet /root/build/Release/SSO/SSO.dll
    11. Restart=always
    12. # Restart service after 10 seconds if the dotnet service crashes:
    13. RestartSec=10
    14. [Install]
    15. WantedBy=multi-user.target
    16. //启动服务
    17. systemctl start kestrel-sso.service

    此时 已经可以正常访问站点 http://ip:8089
    站点将会输出Hello World
    image.png

    自此我们部署篇完成