这里我们先做一些准备工作
下载代码(此处提供代码案例,地址如下)
git clone https://code.aliyun.com/XuanServer/structure.git
安装.net 开发包
//将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库。
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
//安装sdk .net 6
sudo yum install dotnet-sdk-6.0
//安装nuget
yum install nuget
//以下可选不安装,这里只是顺带提示
//安装asp.net runtime
sudo yum install aspnetcore-runtime-6.0
//安装.net runtime
sudo yum install dotnet-runtime-6.0
编译
//进入代码目录
cd structure
//包还原
nuget restore SSO.sln
//编译此处一共有两个站点,可更具自己情况更换
dotnet build ~/structure/SSO/SSO.csproj -c Release -o ~/build/Release/SSO
此时,我们已经成功编译了
下一步将安装nginx
//添加nginx源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
//安装
yum install -y nginx
//启动
systemctl start nginx.service
//设置开机启动
systemctl enable nginx.service
因为部署需要runtime
这里上面没安装的需要安装一下
//安装asp.net runtime
sudo yum install aspnetcore-runtime-6.0
//.NET需要的组件
sudo yum install libunwind libicu
这里提一下nginx配置
Nginx配置信息
网站文件存放默认目录
/usr/share/nginx/html
网站默认站点配置
/etc/nginx/conf.d/default.conf
自定义Nginx站点配置文件存放目录
/etc/nginx/conf.d/
Nginx全局配置
/etc/nginx/nginx.conf
Nginx启动
nginx -c nginx.conf
创建配置文件
//创建配置文件
vim /etc/nginx/conf.d/sso.conf
//粘贴以下内容 保存
server {
listen 8089;
server_name "";
location / {
proxy_pass http://localhost:5000;
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
创建守护进程
//创建服务
cd /etc/systemd/system
vim kestrel-sso.service
//将以下内容粘贴
[Unit]
Description=SSOWebServer
[Service]
Type=simple
WorkingDirectory=/root/build/Release/SSO
ExecStart= /usr/local/bin/dotnet /root/build/Release/SSO/SSO.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
[Install]
WantedBy=multi-user.target
//启动服务
systemctl start kestrel-sso.service
此时 已经可以正常访问站点 http://ip:8089
站点将会输出Hello World
自此我们部署篇完成