Skip to content
IGeekFan 开发者文档IGeekFan 开发者文档
CMS
.NET指南
FreeKit
Docker
关于
博客
github icon
    • Lin CMS By .NET
      • 后端准备
        • Server 端必备环境
          • 获取工程项目
            • 数据库配置
              • 数据迁移
                • visual studio 2022 运行项目
                  • 部署
                    • 部署前准备
                      • 使用 OpenSSL 生成证书
                      • 参考
                      • 后端快速上手
                        • 相关技术
                          • 前端准备
                            • 开源介绍
                              • 功能模块的设计
                                • 产品设计
                                  • GitHub Actions
                                    • LinCms如何切换成SQL server

                                    后端准备

                                    calendar icon2020年2月28日timer icon大约 3 分钟word icon约 972 字

                                    此页内容
                                    • Server 端必备环境
                                    • 获取工程项目
                                    • 数据库配置
                                    • 数据迁移
                                    • visual studio 2022 运行项目
                                    • 部署
                                    • 部署前准备
                                      • 使用 OpenSSL 生成证书
                                    • 参考

                                    # 后端准备

                                    # Server 端必备环境

                                    • 安装软件开发包 .NET SDK 6.0open in new window
                                    • 安装开发工具 Visual Studio 2022open in new window 或 Rideropen in new window
                                    • 安装 MySQL(version 5.7+)
                                    • Redis 4.0.14.2 for Windows https://github.com/tporadowski/redis/releasesopen in new window

                                    # 获取工程项目

                                    git clone https://github.com/luoyunchong/lin-cms-dotnetcore.git
                                    
                                    1

                                    # 数据库配置

                                    文件位置src/LinCms.Web/appsettings.json,当数据库中存储表情包是,Charset为utf8mb4

                                    请务必根据自己的实际情况修改此配置项,DefaultDB为 0 时,代表使用MySQL,DefaultDB为 1 时,代表使用SqlServer,以此类推。

                                     "ConnectionStrings": {
                                        "DefaultDB": "0",
                                        "DataType": {
                                          "MySql": 0,
                                          "SqlServer": 1,
                                          "PostgreSQL": 2,
                                          "Oracle": 3,
                                          "Sqlite": 4
                                        },
                                        "MySql": "Data Source=localhost;Port=3306;User ID=root;Password=root;Initial Catalog=lincms;Charset=utf8mb4;SslMode=none;Max pool size=1;Connection LifeTime=20",
                                        "SqlServer": "Data Source=.;User ID=sa;Password=123456;Integrated Security=True;Initial Catalog=LinCMS;Pooling=true;Min Pool Size=1",
                                        "PostgreSQL": "Host=localhost;Port=5432;Username=postgres;Password=123456; Database=lincms;Pooling=true;Minimum Pool Size=1",
                                        "Oracle": null,
                                        "Sqlite": "Data Source=|DataDirectory|\\lincms.db; Attachs=lincms.db; Pooling=true;Min Pool Size=1",
                                        "CsRedis": "127.0.0.1:6379,password=,defaultDatabase=0"
                                      },
                                    
                                    1
                                    2
                                    3
                                    4
                                    5
                                    6
                                    7
                                    8
                                    9
                                    10
                                    11
                                    12
                                    13
                                    14
                                    15
                                    16

                                    LinCms.IdentityServer4 项目不是必须的,需要需要运行,需要修改数据库配置项

                                    identityserver4/LinCms.IdentityServer4/appsettings.json 数据库配置、同LinCms.Web中的配置项相同

                                      "ConnectionStrings": {
                                        "DefaultDB": "0",
                                        "DataType": {
                                          "MySql": 0,
                                          "SqlServer": 1,
                                          "PostgreSQL": 2,
                                          "Oracle": 3,
                                          "Sqlite": 4
                                        },
                                        "MySql": "Data Source=localhost;Port=3308;User ID=root;Password=root;Initial Catalog=lincms;Charset=utf8mb4;SslMode=none;Max pool size=1;Connection LifeTime=20",
                                        "SqlServer": "Data Source=.;User ID=sa;Password=123456;Integrated Security=True;Initial Catalog=LinCMS;Pooling=true;Min Pool Size=1",
                                        "Sqlite": "Data Source=|DataDirectory|\\lincms.db; Attachs=lincms.db; Pooling=true;Min Pool Size=1"
                                      },
                                    
                                    1
                                    2
                                    3
                                    4
                                    5
                                    6
                                    7
                                    8
                                    9
                                    10
                                    11
                                    12
                                    13

                                    其中 MariaDB(看做 MySql),通过Serilog记录日志,需要配置相应的链接串。

                                    {
                                            "Name": "MariaDB",
                                            "Args": {
                                              "connectionString": "Data Source=localhost;Port=3306;User ID=root;Password=root;Initial Catalog=lincms;Charset=utf8mb4;SslMode=none;Max pool size=1;Connection LifeTime=20",
                                            }
                                    
                                    1
                                    2
                                    3
                                    4
                                    5

                                    # 数据迁移

                                    该项目使用FreeSqlopen in new window,默认自动迁移数据表结构,会自动根据配置项创建数据库,初始化种子数据

                                    默认会创建用户admin,密码123qwe

                                    # visual studio 2022 运行项目

                                    双击 lin-cms-dotnetcore.sln,使用 vs2022 打开项目。右键解决方案,点击生成解决方案。

                                    由于将 identityserver4 单独拆成了一个项目,所以需要同时启动二个项目,右键解决方案,属性。,选择多个启动项目,勾选二个项目同时启动。如下图所示。

                                    这时候会打开二个网页 https://localhost:5001/swagger/index.html,即可看到 swagger 页面。

                                    会打开浏览器,访问https://localhosst:5001/swagger/index.htmlopen in new window,会看到 swagger 的文档。 访问https://localhosst:5003/swagger/index.htmlopen in new window 是 ids4 的接口文档,什么也看不到。

                                    LinCms.Web 运行效果:

                                    # 部署

                                    • 部署至 Linux(Ubuntu16.06)open in new window
                                    • 部署至 Linux(Ubuntu16.06)下的 Dockeropen in new window

                                    # 部署前准备

                                    因为该项目基于 IdentityServer4,实现的授权认证服务,

                                    开发阶段使用AddDeveloperSigningCredential()方法即可完成签名认证,但是在生产环境,我们必须使用AddSigningCredential()方法并且使用 OpenSSL 生成自己的签名证书

                                    Startup.cs

                                                services.AddIdentityServer()
                                    #if  DEBUG
                                                    .AddDeveloperSigningCredential()
                                    #endif
                                    #if !DEBUG
                                                    .AddSigningCredential(new X509Certificate2(Path.Combine(AppContext.BaseDirectory,
                                                            Configuration["Certificates:Path"]),
                                                        Configuration["Certificates:Password"]))
                                    #endif
                                                    .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources())
                                                    .AddInMemoryApiResources(InMemoryConfiguration.GetApis())
                                                    .AddInMemoryClients(InMemoryConfiguration.GetClients())
                                                    .AddProfileService<LinCmsProfileService>()
                                                    .AddResourceOwnerValidator<LinCmsResourceOwnerPasswordValidator>();
                                    
                                    1
                                    2
                                    3
                                    4
                                    5
                                    6
                                    7
                                    8
                                    9
                                    10
                                    11
                                    12
                                    13
                                    14

                                    appsettings.Production.json

                                    {
                                        "Certificates":
                                        {
                                            "Path":"ids4.pfx",
                                            "Password":"123qwe"
                                        }
                                    }
                                    
                                    1
                                    2
                                    3
                                    4
                                    5
                                    6
                                    7

                                    # 使用 OpenSSL 生成证书

                                    官网下载并安装 OpenSSL OpenSSL 官网open in new window

                                    下载 Win64 OpenSSL v1.1.1b 版本

                                    在 OpenSSL 的 bin 文件夹,以管理员身份打开 CMD 执行以下命令:

                                    openssl req -newkey rsa:2048 -nodes -keyout ids4.key -x509 -days 365 -out ids4.cer
                                    
                                    1

                                    下面将生成的证书和 Key 封装成一个文件,以便 IdentityServer 可以使用它们去正确地签名 tokens

                                    openssl pkcs12 -export -in ids4.cer -inkey ids4.key -out ids4.pfx
                                    
                                    1
                                    # (注:在生成的过程中会让我们输入 Export Password)

                                    这个 密码与 appsettings.Production.json 配置项相同。

                                    发布时,把 ids4.pfx,放到项目根目录

                                    # 参考

                                    • IdentityServer4 之 JWT 签名(RSA 加密证书)及验签open in new window
                                    edit icon在 GitHub 上编辑此页open in new window
                                    上次编辑于: 2022/6/3 14:30:48
                                    贡献者: luoyunchong,igeekfan
                                    上一页
                                    Lin CMS By .NET
                                    下一页
                                    后端快速上手
                                    MIT Licensed | Copyright © 2021-present luoyunchong
                                    苏ICP备16046457号-1

                                    该应用可以安装在你的 PC 或移动设备上。这将使该 Web 应用程序外观和行为与其他应用程序相同。它将在出现在应用程序列表中,并可以固定到主屏幕,开始菜单或任务栏。此 Web 应用程序还将能够与其他应用程序和你的操作系统安全地进行交互。

                                    详情