您好,登錄后才能下訂單哦!
部署環境
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。