一、发布项目
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