<!-- Space: qifu -->
<!-- Parent: 后端技术&知识&规范 -->
<!-- Parent: 技术方案 -->
<!-- Parent: 基建 -->
<!-- Parent: 03-接入指南 -->
<!-- Title: 20250225-学习平台安装及SSO接入指南 -->

<!-- Macro: :anchor\((.*)\):
     Template: ac:anchor
     Anchor: ${1} -->
<!-- Macro: \!\[.*\]\((.+)\)\<\!\-\- width=(.*) \-\-\>
     Template: ac:image
     Url: ${1}
     Width: ${2} -->
<!-- Macro: \<\!\-\- :toc: \-\-\>
     Template: ac:toc
     Printable: 'false'
     MinLevel: 2 
     MaxLevel: 4 -->
<!-- Include: 杂项/声明文件.md -->

<!-- :toc: -->

# 学习平台安装及SSO接入指南
 
## 前置说明
- 平台根据 [在线培训系统](https://gitee.com/xblms/xblmls) 做二次开发定制
- 添加：学员端添加企微登录
- 修复：管理员无法删除问题
- 修复：非超级管理员及单位管理员资源无法上传问题

## 学习平台安装
### 源码编译

项目编译需要使用 Visual Studio 2022，你可以从这里下载：[Visual Studio Community 2022](https://www.visualstudio.com/downloads/)
DotNet SDK 可以从这里下载：[SDK 开发用](https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/sdk-8.0.403-windows-x64-installer)
DotNet 运行时可以从这里下载：[运行时 部署用](https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/runtime-aspnetcore-8.0.2-windows-hosting-bundle-installer)
NodeJs：v16.20.2
NPM：8.19.4

#### 获取源码
```shell
git clone ssh://git@git.keyfil.com:9922/qifu-gateway/xuexi.git

cd xuexi/
```

#### 发布跨平台版本

##### Window(x64)：

```
npm install
npm run build-win-x64
dotnet build ./build-win-x64/build.sln -c Release
dotnet publish ./build-win-x64/src/XBLMS.Web/XBLMS.Web.csproj -r win-x64 -c Release -o ./publish/xblms-win-x64
npm run copy-win-x64
```

> 进入文件夹 `./publish/xblms-win-x64` 获取部署文件

##### Window(x32)：

```
npm install
npm run build-win-x86
dotnet build ./build-win-x86/build.sln -c Release
dotnet publish ./build-win-x86/src/XBLMS.Web/XBLMS.Web.csproj -r win-x86 -c Release -o ./publish/xblms-win-x86
npm run copy-win-x86
```

> 进入文件夹 `./publish/xblms-win-x32` 获取部署文件

##### Linux(x64)：

```
npm install
npm run build-linux-x64
dotnet build ./build-linux-x64/build.sln -c Release
dotnet publish ./build-linux-x64/src/XBLMS.Web/XBLMS.Web.csproj -r linux-x64 -c Release -o ./publish/xblms-linux-x64
npm run copy-linux-x64
```

> 进入文件夹 `./publish/xblms-linux-x64` 获取部署文件

##### Linux(arm64)：

```
npm install
npm run build-linux-arm64
dotnet build ./build-linux-arm64/build.sln -c Release
dotnet publish ./build-linux-arm64/src/XBLMS.Web/XBLMS.Web.csproj -r linux-arm64 -c Release -o ./publish/xblms-linux-arm64
npm run copy-linux-arm64
```

> 进入文件夹 `./publish/xblms-linux-arm64` 获取部署文件

### 构建镜像及启动
> 工作目录: /home/xuexi/
#### 解压文件
```shell
cd /home/xuexi/

unzip xblms-linux-x64.zip
```
#### 编写启动脚本
> /home/xuexi/start.sh
```shell
#!/bin/sh

service nginx start

echo "Nginx started"

echo "$(service nginx status)"

dotnet /app/XBLMS.Web.dll
```
#### 创建Nginx配置文件
> /home/xuexi/nginx.conf
```
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;

        gzip on;
        keepalive_timeout 65;
        client_max_body_size 2048m;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
```
#### 编写培训平台Nginx配置文件
> /home/xuexi/xuexi.conf
```
server {
    listen        80;
    server_name   *.qifu.com;
    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;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
    }
}
```

#### Dockerfile文件
> /home/xuexi/Dockerfile
```dockerfile
FROM ubuntu/nginx:1.24-24.04_beta AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM base AS final
WORKDIR /app
RUN sed -i s:/archive.ubuntu.com:/mirrors.tuna.tsinghua.edu.cn/ubuntu:g /etc/apt/sources.list

RUN apt clean && apt update

#- 安装 .net 运行环境，
RUN apt install wget -y

RUN wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb

RUN apt update

RUN apt install -y apt-transport-https && apt install -y aspnetcore-runtime-8.0

RUN dotnet --info

COPY ./start.sh /app/start.sh
RUN chmod +x /app/start.sh
ENTRYPOINT ["/app/start.sh"]
```
#### 编写DockerCompose启动文件
> /home/xuexi/docker-compose.yaml

```yaml
services:
  xuexi:
    image: xuexi:2.0.0
    container_name: xuexi
    environment:
      ASPNETCORE_HTTP_PORTS: 5000
      # ASPNETCORE_URLS: http://localhost:5000
    ports:
      - "10000:80"
    volumes:
      - "./xblms-linux-x64:/app"
      - "./nginx.conf:/etc/nginx/nginx.conf"
      - "./xblms.conf:/etc/nginx/conf.d/xblms.conf"
    command: service nginx restart
    restart: always
```
#### 配置启动文件权限
```shell
cp /home/xuexi/start.sh /home/xuexi/xblms-linux-x64/start.sh

chmod +x /home/xuexi/xblms-linux-x64/start.sh
```

#### 构建镜像
```shell
docker build -t xuexi:2.0.0 .
```

#### 启动服务
```shell
docker compose up -d
```

### 配置
访问 `http://xxx.qifu.com/admin/install` 

## 参考
- [在线培训系统](https://gitee.com/xblms/xblmls)
- [发布和部署手册](https://gitee.com/xblms/xblmes/tree/master/src/XBLMS.Web/wwwroot/sitefiles/assets/uploadtemplates/doc)
