部署环境
OS:CentOS7
.NET Core SDK:2.2.402
yum install libunwind libicu
dotnet 的repo,需注册Microsoft签名密钥并添加Microsoft产品密钥
rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
1.2 安装dotnet SDK
yum update
yum install dotnet-sdk-2.2
1.3 验证查看
#dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.402
Commit: c7f2f96116
Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /usr/share/dotnet/sdk/2.2.402/
Host (useful for support):
Version: 2.2.8
Commit: b9aa1abc51
.NET Core SDKs installed:
2.2.402 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
1.4 为dotnet命令创建软链接:
/usr/bin/dotnet -> /usr/share/dotnet/dotnet
1.5 部署启动.NET Core项目应用
进入到项目应用:
cd /usr/soft/package/Web
启动dotnet应用
dotnet /usr/soft/package/Web/HiCore.PreventFraudAPI.Web.dll
这里存在一问题,以上方式启动的应用非后台启动,如果Ctrl+Z就退出了应用,所以这里需要一个Daemon守护进程,让应用独立的运行,这里引入Supervisor。
hosting.json
{
"server.urls": "http://*:8001"
}
Nginx配置的该虚拟主机文件配置如:
server {
listen 80;
location / {
proxy_pass http://localhost:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
文件保存后,执行命令nginx -s reload重启Nginx即可访问。
yum install python-setuptools
安装
easy_install supervisor
版本
supervisord --version
3.2 初始化supervisor配置
mkdir /etc/supervisor
mkdir -p /etc/supervisor/conf.d
echo_supervisord_conf > /etc/supervisor/supervisord.conf
打开supervisord.conf文件,修改默认[include]配置项,改为如下:
[include]
files = conf.d/*.conf
Supervisor会自动加载 /etc/supervisor/conf.d目录下.conf后缀的文件作为共同服务配置。Supervisor管理的每个进程单独写一个配置文件放在该目录下,/etc/supervisor/supervisord.conf配置文件中保留公共配置。
3.3 编写.NET Core项目应用配置
vim /etc/supervisor/conf.d/netcoreAPI.conf
[program:PreventFraudAPI.Web]
command=dotnet Web.dll #启动命令
directory=/usr/soft/package/FraudAPI.Web #启动应用目录
autostart=true #Supervisord启动时,程序是否启动
autorestart=true #程序退出后自动启动
startretries=5 #启动失败自动重试次数,默认是3
startsecs=1 #自动重启间隔
user=root #启动进程用户,默认root
priority=999 #默认999,值小优先启动
stderr_logfile=/var/log//PreventFraudAPI.err.log #error_log
stdout_logfile=/var/log//PreventFraudAPI.out.log #out_log
environment=ASPNETCORE_ENVIRONMENT=Production #进程环境变量
stopsignal=INT #请求停止时用来杀死程序的信号
启动Supervisor服务命令,这里可不启动,后面设置Supervisor开机启动。
supervisord -c /etc/supervisor/supervisord.conf
3.4 设置Supervisor开机启动
创建Supervisor启动服务脚本supervisor.service,目录/usr/lib/systemd/system/。
supervisor.service脚本内容:
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
设置开机启动
systemctl enable supervisor
3.5 Supervisorctl管理进程
Supervisor服务启动后,受其管理的进程会在后台运行。可以通过supervisorctl命令管理客户端进程。
#supervisorctl
PreventFraudAPI.Web RUNNING pid 15921, uptime 0:22:51
supervisor>
supervisor> help
default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。