1. 上傳文件
假設(shè)AspNet Core項目名為xxx
澜共,開發(fā)完成后發(fā)布到文件夾胰耗,然后把整個PublishOutput
文件夾的文件復(fù)制到Centos7的目錄/var/aspnetcore/xxx
。修改目錄的owner峰弹,因為后面使用nginx用戶自啟動,所以owner修改為nginx:
chown -R nginx:nginx /var/aspnetcore/xxx
2. 創(chuàng)建自啟動文件
新建文件
vi /etc/systemd/system/xxx.service
內(nèi)容如下:
[Unit]
Description=xxx program on centos7
[Service]
WorkingDirectory=/var/aspnetcore/xxx
ExecStart=/usr/bin/dotnet /var/aspnetcore/xxx/xxx.dll
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-xxx
User=nginx
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
3. 使自啟動生效
systemctl enable xxx.service
4. 立即啟動服務(wù)
systemctl start xxx.service
5. 查看服務(wù)狀態(tài)
systemctl status xxx.service