前置
服务器环境:Linux服务器
Ubuntu 20.04.5 LTS x86_64(Py3.7.9)
先查看一下服务器是否已安装donet:dotnet --version
一、安装donet3.1环境?
根据上方系统提示可以通过snap命令安装donet我们顺势而为(不同环境自行百度即可)。
执行命令:sudo snap install dotnet-sdk --classic --channel=3.1
等待下载完成再次使用命令查看donet是否安装成功及其版本:dotnet --version
发现donet版本为3.1.426
donet环境安装完成❀
二、前端部署
1.前端文件拷贝至宝塔(建议先压缩上传再解压)
我拷贝在 /home/www/alibaba/display目录下
2.通过宝塔实现前端站点部署
如下:在网站中添加站点将根目录设置为刚才传上来的前端代码目录再设个端口
ok前端部署成功。
三、后端部署
1.后端文件右键发布生成一个publish文件夹抛到服务器上
2.编写一个service文件
[Unit]
Description="homesafe.Service"
[Service]
Type=simple
GuessMainPID=true
WorkingDirectory=/home/www/zhangxinjie/power/publish
#StandardOutput=journal
#StandardError=journal
ExecStart=/usr/bin/dotnet PMSystem.WebApi.dll
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
将这个文件放在/etc/systemd/system文件夹下 执行systemctl enable xxxxx.service 命令开启自启动 ,执行systemctl start xxxxxx.service命令启动这个服务
坑点:先执行一下which dotnet命令看看dotnet的路径在哪,确保在服务文件中使用的路径与此相同,即:ExecStart=/usr/bin/dotnet中的:/usr/bin/dotnet要与which dotne所输出的路劲一致
3.查看服务运行状态
systemctl status xxxxxx.service
服务部署完成❀