.net6 core Worker Service项目发布部署到Linux,以守护进程服务的形式部署启动

一、发布项目

1、以文件夹形式
2、目标运行时选对应的平台(Linux-x64)
3、文件夹选项:在发布前删除所有现有文件
在这里插入图片描述
在这里插入图片描述

二、部署项目(安装.net6环境:参考Linux安装 dotnet sdk 6.0

(1)使用Xftp将项目发布文件上传到Linux服务器上的指定目录,如:/var/www
在这里插入图片描述
(2)为应用程序分配可执行权限

# chmod +x /var/www/chinahorn.mail.send.workerservice/Chinahorn.Mail.Send.WorkerService

在这里插入图片描述
(3)新建chinahorn.mail.send.service守护进程文件,移动至 /etc/systemd/system/

1、 ExecStart:设置项目路径
2、使用systemctl命令重新加载新的配置文件 # systemctl daemon-reload

[Unit]
Description=Running ASP.NET Core on Ubuntu 20.04 Webserver APACHE

[Service]
WorkingDirectory=/var/www/chinahorn.mail.send.workerservice/
ExecStart=/var/www/chinahorn.mail.send.workerservice/Chinahorn.Mail.Send.WorkerService
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=chinahornmailsend
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

在这里插入图片描述
(4)重新加载配置文件,启动服务、设置服务开机自启

1、使用systemctl命令重新加载新的配置文件
# systemctl daemon-reload
42、启动服务
# systemctl start chinahorn.mail.send
3、停止服务
# systemctl stop chinahorn.mail.send
4、重新查看服务状态
# systemctl status chinahorn.mail.send
5、重启服务
# systemctl restart chinahorn.mail.send
6、设置服务开机自启
# systemctl enable chinahorn.mail.send
7、禁用开机自启
# systemctl disable chinahorn.mail.send
三、查看服务状态

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: To publish a .NET Worker Service from a Windows system to a Linux system, you can follow these general steps: 1. Compile the .NET Worker Service for Linux: You can use the .NET Core CLI tool or Visual Studio to compile your Worker Service for Linux. Make sure you target the appropriate runtime, which can be Linux-x64, Linux-arm, or other Linux architectures. 2. Create a package: Create a package of your compiled Worker Service using the "dotnet publish" command. This will create a directory containing all the files required to run the Worker Service on a Linux system. 3. Transfer the package to the Linux system: You can use various methods to transfer the package to the Linux system, such as SCP, FTP, or Samba file sharing. 4. Install .NET runtime on the Linux system: If the Linux system does not have the .NET runtime installed, you need to install it before running the Worker Service. You can use the package manager of your Linux distribution to install the runtime. 5. Run the Worker Service: You can start the Worker Service by navigating to the directory containing the published files on the Linux system and running the command "dotnet YourWorkerService.dll". Note that some adjustments may be necessary to make the Worker Service compatible with the Linux environment, such as using appropriate file paths, handling differences in file systems, and configuring system services. Also, make sure that the Linux system meets the requirements of the .NET runtime version used to compile the Worker Service. ### 回答2: 要将Windows系统上的Worker Service发布Linux系统上,首先需要将Worker Service的代码从Windows环境迁移到Linux环境。这是因为Windows和Linux使用了不同的操作系统核心和硬件体系结构,所以代码需要相应的修改和调整。 在迁移代码之前,需确定Worker Service使用的是跨平台的编程语言和框架,例如.NET Core。如果Worker Service使用的是其他不支持跨平台的语言或框架,则需要将其重写为跨平台的版本。 在将代码迁移到Linux系统之后,还需要安装并配置Linux系统上的必要软件和依赖项,例如.NET Core运行时环境等。这些软件和依赖项可以通过包管理器或其他方式安装。 接下来,可以使用一种适合的部署工具,例如Docker,来将Worker Service打包为一个容器。容器化可以提供隔离和易于管理的好处。 最后,可以将打包好的容器部署Linux系统上,运行Worker Service。这可以通过命令行或图形化界面实现,具体取决于系统和个人偏好。 在部署过程中,可能会遇到一些问题和挑战,例如平台差异、依赖项冲突等。因此,建议事先做好充分的测试和调试工作,确保Worker ServiceLinux系统上能够正常运行。 总之,将Windows系统上的Worker Service发布Linux系统上需要进行代码迁移、环境配置和部署步骤。通过适当的准备和措施,可以成功实现这一目标。 ### 回答3: 要将Windows系统中的WorkerService发布Linux系统上,需要进行一些准备工作和配置步骤。 首先,需要将WorkerService的代码进行适配和调整,以确保其在Linux系统上能够正常运行。这可能涉及到修改文件路径、处理文件系统相关的差异、更改对操作系统的依赖等等。确保代码适配是成功迁移的关键。 接下来,需要在Linux系统上安装合适的启动脚本和依赖库,以确保WorkerService的正常运行。首先,需要安装mono运行时环境,它是在Linux系统上运行基于.NET框架的应用程序的重要组件。然后,可以编写启动脚本(如Shell脚本)来控制WorkerService启动和停止,并将该脚本添加到系统服务中使其在系统启动时自动启动。此外,可能还需要安装其他应用程序所需的依赖库。 在发布Linux系统之前,还需要进行一些测试工作,确保WorkerService在新环境中能够正常工作。测试期间,需要注意记录任何可能出现的错误、异常或兼容性问题,并进行相应的调整和修复。 最后,在发布Linux系统之前,需要选择合适的Linux发行版和版本,并确保系统上已经正确地安装了所需的操作系统和软件依赖。这可以通过在Linux系统上运行适配后的WorkerService的二进制文件来进行验证。 总体而言,发布WorkerServiceLinux系统涉及到代码适配、安装运行时环境和依赖库、编写启动脚本,并进行测试和验证等一系列步骤。只有确保这些步骤正确执行,才能顺利地将WorkerService从Windows系统发布Linux系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

下一秒_待续

如有帮到您,给个赞赏(^.^)

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值