派胜OA - 在 Linux 上使用 Systemd 托管 ExpressOA 3.x

重要

ExpressOA 3.x 使用全球最佳编程语言 C# 构建(.NET 跨平台、高性能、开源免费)。
ExpressOA 包含自托管 Kestrel Web 服务器,Kestrel 可以单独使用,也可以与反向代理服务器一起使用。
ExpressOA 应用程序 runroot 文件夹中包含应用程序目录结构。
ExpressOA 在 Linux 上从 runroot/ExpressOA.dll 文件启动。
本文教程演示命令适用于 Ubuntu 24.04, 22.04, 20.04Debian 12.x, 11.x

在 Linux 上安装 ASP.NET Core 8.0

适用于 Ubuntu 24.04, 22.04, 20.04Debian 12.x, 11.x
Linux 命令
sudo apt-get update
sudo apt-get install -y aspnetcore-runtime-8.0
适用于 openEuler 24.03 LTS, 22.03 LTS
Linux 命令
sudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm
sudo dnf -y install aspnetcore-runtime-8.0

(1)配置 Kestrel Web 服务器

1.1 配置 Kestrel 绑定本机端口。
打开 runroot/appsettings.json,可以看到 Kestrel 默认绑定本机地址和端口 localhost:5000。
localhost 等于 127.0.0.1,使用 Kestrel 绑定本机地址和端口,可以与反向代理(Nginx, Apache)一起使用。
你可以自定义 Kestrel 绑定的端口(建议端口范围 5000-60000),只要该端口没有占用。
"Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      }
    }
  }

1.2 在 Linux 命令行中启动 Kestrel Web 服务器。
Linux 命令
sudo dotnet /expressoa/runroot/ExpressOA.dll

1.3 验证 Kestrel 是否正常工作。
Linux 命令
curl http://localhost:5000

(2)使用 Systemd 托管 ExpressOA

2.1 配置 Linux 后台服务 expressoa.service。
Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数 Linux 发行版的标准配置。
拷贝 runroot/expressoa.service 到 /etc/systemd/system。
Linux 命令
sudo cp /expressoa/runroot/expressoa.service /etc/systemd/system

使用 vim 编辑 expressoa.service,把部署路径 /expressoa 修改为实际的部署路径。
Linux 命令
sudo vim /expressoa/runroot/expressoa.service
expressoa.service
[Unit]
Description=ExpressOA

[Service]
WorkingDirectory=/expressoa/runroot
ExecStart=/usr/bin/dotnet /expressoa/runroot/ExpressOA.dll

Restart=always
RestartSec=10
SyslogIdentifier=expressoa
User=root
Environment=DOTNET_ROOT=/usr/lib64/dotnet
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

2.2 启动服务 expressoa.service。
安装服务
Linux 命令
sudo systemctl enable /etc/systemd/system/expressoa.service

启动服务
Linux 命令
sudo systemctl start expressoa

重启服务
Linux 命令
sudo systemctl restart expressoa

停止服务
Linux 命令
sudo systemctl stop expressoa

查看服务状态
Linux 命令
sudo systemctl status expressoa

(3)配置 Kestrel 独立提供服务

本章节演示配置 Kestrel 绑定域名和 SSL 证书,独立提供服务。
在验证 HTTPS 访问成功后,启用 HttpsRedirection 跳转。

3.1 使用 vim 编辑 runroot/appsettings.json 配置 Kestrel Web 服务器。
Linux 命令
sudo vim /expressoa/runroot/appsettings.json

Kestrel 绑定主机和端口
http://localhost:5000(http 监听本机网卡回环地址:5000 端口,只能在本机访问)
http://*:5000(http 监听所有 IP 地址:5000 端口)
http://oa.paioffice.com(http 监听本机所有 IP 地址:80 端口)
https://oa.paioffice.com(https 监听本机所有 IP 地址:443 端口)
appsettings.json 配置如下:
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://oa.paioffice.com"
      },
      "Https": {
        "Url": "https://oa.paioffice.com",
        "Certificate": {
          "Path": "/expressoa/oa.paioffice.com.pfx",
          "Password": "Your Password"
        }
      }
    }
  },
 "HttpsRedirection": false,

3.2 在 Linux 命令行中启动 Kestrel Web 服务器。
Linux 命令
sudo dotnet /expressoa/runroot/ExpressOA.dll

3.3 验证测试 HTTP 和 HTTPS 配置成功。
Linux 命令
curl http://oa.paioffice.com

Linux 命令
curl -4 https://oa.paioffice.com

3.4 将 HTTP 重定向到 HTTPS
使用 vim 编辑 runroot/appsettings.json,修改为 "HttpsRedirection": true。 重启 expressoa 服务。
Linux 命令
sudo systemctl restart expressoa



© 2024 长春派胜科技有限公司 版权所有
吉公网安备22017202000417号