使用 FileZilla 中的用户“ec2-user”将示例 dot net core web api 部署到 /var/www/hello-app 文件夹中的 EC2 实例
该文件夹包含所需的 dll 和其他 dotnet 文件
在 ec2 实例上安装 apache web 服务器并启动该 web 服务器
从命令行运行 dotnet 服务以确保其使用以下命令正常运行
cd /usr/lib64/dotnet
dotnet /var/www/helloapp/WebApi4.dll
- 我为 Dot net web api 创建了 systemd 服务,如下所示
sudo vim /etc/systemd/system/kestrel-helloapp.service
[Unit]
Description=Example .NET Web API App
[Service]
WorkingDirectory=/var/www/helloapp
ExecStart=/usr/lib64/dotnet /var/www/helloapp/WebApi4.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=apache
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://localhost:5000
[Install]
WantedBy=multi-user.target
When I run following commands
sudo systemctl enable kestrel-helloapp.service
sudo systemctl start kestrel-helloapp.service
sudo systemctl status kestrel-helloapp.service
I get following error (203/EXEC) for the third command
[ec2-user@ip-172-31-81-1 dotnet]$ sudo systemctl status kestrel-helloapp.service
● kestrel-helloapp.service - Example .NET Web API App running on CentOS 7
Loaded: loaded (/etc/systemd/system/kestrel-helloapp.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Tue 2022-01-11 15:40:30 UTC; 6s ago
Process: 71626 ExecStart=/usr/lib64/dotnet /var/www/helloapp/WebApi4.dll (code=exited, status=203/EXEC)
Main PID: 71626 (code=exited, status=203/EXEC)
Jan 11 15:40:30 ip-172-31-81-1.ec2.internal systemd[1]: kestrel-helloapp.service: Main process exited, code=exited, status=203/EXEC
Jan 11 15:40:30 ip-172-31-81-1.ec2.internal systemd[1]: kestrel-helloapp.service: Failed with result 'exit-code'.
- 使用以下方式打开端口 5000
sudo firewall-cmd --add-port=5000/tcp --permanent
- 使 apache 成为 /var/www 文件夹的所有者
sudo chown -R apache:apache /var/www
sudo chmod -R 550 /var/www
我查看了错误以及与错误相关的可能原因,发现以下内容。检查了我能想到的所有内容,但仍然一样
The error message (code=exited, status=203/EXEC) is often seen when the script itself or its interpreter cannot be executed.
It could have these reasons:
wrong path to script (e.g. /home/py/ReadPressure2AndPostToMqtt.py)
script not executable
no shebang (first line)
wrong path in shebang (e.g. /bin/python3)
internal files in your script might be missing access permissions.
SELinux may be preventing execution of the ExecStart parameter; check /var/log/audit/audit.log for messages of the form: type=AVC msg=audit([...]): avc: denied { execute } or in the output of ausearch -ts recent -m avc -i.
You have the wrong WorkingDirectory parameter