【安装.Net框架】
安装 .NET 之前,请运行以下命令,将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库。 打开终端并运行以下命令:
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
安装 SDK
.NET SDK 使你可以通过 .NET 开发应用。 如果安装 .NET SDK,则无需安装相应的运行时。 若要安装 .NET SDK,请运行以下命令:
sudo yum install dotnet-sdk-6.0
======================================================================================
【安装验证码插件】
yum install autoconf automake libtool
yum install freetype-devel fontconfig libXft-devel
yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
yum install glib2-devel cairo-devel
git clone https://github.com/mono/libgdiplus
cd libgdiplus
./autogen.sh
make
make install
cd /usr/lib64/
ln -s /usr/local/lib/libgdiplus.so gdiplus.dll
yum install libgdiplus-devel
【运行API】
dotnet WebApi.dll
【测试验证码生成】
curl http://localhost/api/Sys_User/getVierificationCode
【以服务方式运行】
----新建服务文件-----------
vim /etc/systemd/system/webapi.service
------------------------------------
------把以下配置信息复制到配置文件中-------
[Service]
WorkingDirectory=/Web/API # 工作目录根据实际情况
ExecStart=/usr/bin/dotnet /Web/API/WebApi.dll # 启动程序根据实际情况
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
----------------------------------------------------
-----------重新加载-------------------------------
systemctl daemon-reload
---------------------------------------------------
----------启动服务------------------------------
systemctl start webapi.service
-------------------------------------------------
------------开机自启动-------------------------
systemctl enable webapi.service
------------------------------------------------