1.登录linux服务器,安装宝塔服务器工具,命令如下(万能安装脚本):
<span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token operator">-</span>f <span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>curl <span class="token punctuation">]</span><span class="token punctuation">;</span>then curl <span class="token operator">-</span><span class="token class-name">sSO</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>download<span class="token punctuation">.</span>bt<span class="token punctuation">.</span>cn<span class="token operator">/</span>install<span class="token operator">/</span>install_panel<span class="token punctuation">.</span>sh<span class="token punctuation">;</span><span class="token keyword">else</span> wget <span class="token operator">-</span>O <span class="token class-name">install_panel<span class="token punctuation">.</span>sh</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>download<span class="token punctuation">.</span>bt<span class="token punctuation">.</span>cn<span class="token operator">/</span>install<span class="token operator">/</span>install_panel<span class="token punctuation">.</span>sh<span class="token punctuation">;</span>fi<span class="token punctuation">;</span>bash install_panel<span class="token punctuation">.</span>sh ed8484bec<span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token operator">-</span>f <span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>curl <span class="token punctuation">]</span><span class="token punctuation">;</span>then curl <span class="token operator">-</span><span class="token class-name">sSO</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>download<span class="token punctuation">.</span>bt<span class="token punctuation">.</span>cn<span class="token operator">/</span>install<span class="token operator">/</span>install_panel<span class="token punctuation">.</span>sh<span class="token punctuation">;</span><span class="token keyword">else</span> wget <span class="token operator">-</span>O <span class="token class-name">install_panel<span class="token punctuation">.</span>sh</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>download<span class="token punctuation">.</span>bt<span class="token punctuation">.</span>cn<span class="token operator">/</span>install<span class="token operator">/</span>install_panel<span class="token punctuation">.</span>sh<span class="token punctuation">;</span>fi<span class="token punctuation">;</span>bash install_panel<span class="token punctuation">.</span>sh ed8484becif [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh ed8484bec
2.等待安装完成,期间可能要输入Y确认继续执行;安装完成后最后会出现一个网址和帐号密码;输入网址,登录成功后,安装推荐设置NGINX 1.6,mysql5.7,及其他默认
3.等待安装完成后,安装netcore2.2,命令如下:
sudo rpm <span class="token operator">--</span><span class="token class-name">import</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>packages<span class="token punctuation">.</span>microsoft<span class="token punctuation">.</span>com<span class="token operator">/</span>keys<span class="token operator">/</span>microsoft<span class="token punctuation">.</span>asc sudo sh <span class="token operator">-</span>c 'echo <span class="token operator">-</span>e <span class="token string">"[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc"</span><span class="token operator">></span><span class="token operator">/</span>etc<span class="token operator">/</span>yum<span class="token punctuation">.</span>repos<span class="token punctuation">.</span>d<span class="token operator">/</span>dotnetdev<span class="token punctuation">.</span>repo' sudo yum update sudo yum install libunwind libicu sudo yum install dotnet<span class="token operator">-</span>sdk<span class="token operator">-</span><span class="token number">2.2</span>sudo rpm <span class="token operator">--</span><span class="token class-name">import</span> https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>packages<span class="token punctuation">.</span>microsoft<span class="token punctuation">.</span>com<span class="token operator">/</span>keys<span class="token operator">/</span>microsoft<span class="token punctuation">.</span>asc sudo sh <span class="token operator">-</span>c 'echo <span class="token operator">-</span>e <span class="token string">"[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc"</span><span class="token operator">></span><span class="token operator">/</span>etc<span class="token operator">/</span>yum<span class="token punctuation">.</span>repos<span class="token punctuation">.</span>d<span class="token operator">/</span>dotnetdev<span class="token punctuation">.</span>repo' sudo yum update sudo yum install libunwind libicu sudo yum install dotnet<span class="token operator">-</span>sdk<span class="token operator">-</span><span class="token number">2.2</span>sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc">/etc/yum.repos.d/dotnetdev.repo' sudo yum update sudo yum install libunwind libicu sudo yum install dotnet-sdk-2.2
4.安装完成后,新建ftp及mysql上传到线上,然后找到网站文件路径,执行运行操作:
cd <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyicd <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyicd /www/wwwroot/gaoyi
dotnet Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dlldotnet Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dlldotnet Ctmon.Web.dll
5.运行完后新建执行持续执行工具,步骤如下:
5.1创建服务
vi <span class="token operator">/</span>etc<span class="token operator">/</span>systemd<span class="token operator">/</span>system<span class="token operator">/</span>gaoyi<span class="token punctuation">.</span>servicevi <span class="token operator">/</span>etc<span class="token operator">/</span>systemd<span class="token operator">/</span>system<span class="token operator">/</span>gaoyi<span class="token punctuation">.</span>servicevi /etc/systemd/system/gaoyi.service
5.2写入文件(下面<>部分是需要变更的)
<span class="token punctuation">[</span><span class="token attribute"><span class="token class-name">Unit</span></span><span class="token punctuation">]</span> Description<span class="token operator">=</span>Web API Application running <span class="token keyword">on</span> CentOS <span class="token punctuation">[</span>Service<span class="token punctuation">]</span> WorkingDirectory<span class="token operator">=</span> <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span><span class="token class-name">gaoyi</span> ExecStart<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>dotnet <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyi<span class="token operator">/</span><span class="token class-name">Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dll</span> Restart<span class="token operator">=</span><span class="token class-name">always</span> RestartSec<span class="token operator">=</span><span class="token number">10</span> # Restart service after <span class="token number">10</span> seconds <span class="token keyword">if</span> dotnet service <span class="token class-name">crashes</span> SyslogIdentifier<span class="token operator">=</span><span class="token class-name">gaoyi</span> User<span class="token operator">=</span><span class="token class-name">root</span> Environment<span class="token operator">=</span>ASPNETCORE_ENVIRONMENT<span class="token operator">=</span><span class="token class-name">Production</span> Environment<span class="token operator">=</span>DOTNET_PRINT_TELEMETRY_MESSAGE<span class="token operator">=</span><span class="token boolean">false</span> <span class="token punctuation">[</span>Install<span class="token punctuation">]</span> WantedBy<span class="token operator">=</span>multi<span class="token operator">-</span>user<span class="token punctuation">.</span>target<span class="token punctuation">[</span><span class="token attribute"><span class="token class-name">Unit</span></span><span class="token punctuation">]</span> Description<span class="token operator">=</span>Web API Application running <span class="token keyword">on</span> CentOS <span class="token punctuation">[</span>Service<span class="token punctuation">]</span> WorkingDirectory<span class="token operator">=</span> <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span><span class="token class-name">gaoyi</span> ExecStart<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>dotnet <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyi<span class="token operator">/</span><span class="token class-name">Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dll</span> Restart<span class="token operator">=</span><span class="token class-name">always</span> RestartSec<span class="token operator">=</span><span class="token number">10</span> # Restart service after <span class="token number">10</span> seconds <span class="token keyword">if</span> dotnet service <span class="token class-name">crashes</span> SyslogIdentifier<span class="token operator">=</span><span class="token class-name">gaoyi</span> User<span class="token operator">=</span><span class="token class-name">root</span> Environment<span class="token operator">=</span>ASPNETCORE_ENVIRONMENT<span class="token operator">=</span><span class="token class-name">Production</span> Environment<span class="token operator">=</span>DOTNET_PRINT_TELEMETRY_MESSAGE<span class="token operator">=</span><span class="token boolean">false</span> <span class="token punctuation">[</span>Install<span class="token punctuation">]</span> WantedBy<span class="token operator">=</span>multi<span class="token operator">-</span>user<span class="token punctuation">.</span>target[Unit] Description=Web API Application running on CentOS [Service] WorkingDirectory= /www/wwwroot/gaoyi ExecStart=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll Restart=always RestartSec=10 # Restart service after 10 seconds if dotnet service crashes SyslogIdentifier=gaoyi User=root Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
//<>内的内容按所部署位置编写
WorkingDirectory = /www/wwwroot/gaoyi //程序所在目录
ExecStar=/usr/bin/dotnet /www/wwwroot/gaoyi/Ctmon.Web.dll //程序运行DLL
SyslogIdentifier = gaoyi
5.3启动服务
systemctl start websitesystemctl start websitesystemctl start website
6.执行完上面后,需要到宝塔修改配置
配置文件内容(proxy_pass http:端口号不可重复)
server <span class="token punctuation">{<!-- --></span> listen <span class="token number">80</span><span class="token punctuation">;</span> server_nane gaoyi<span class="token punctuation">.</span>ctmon<span class="token punctuation">.</span>cn<span class="token punctuation">;</span> index index<span class="token punctuation">.</span>php index<span class="token punctuation">.</span>html index<span class="token punctuation">.</span>htm <span class="token keyword">default</span><span class="token punctuation">.</span>php <span class="token keyword">default</span><span class="token punctuation">.</span>htm <span class="token keyword">default</span><span class="token punctuation">.</span>html location <span class="token operator">/</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">proxy_pass</span> http<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>localhost<span class="token punctuation">:</span><span class="token number">5005</span><span class="token punctuation">;</span> proxy_http_version <span class="token number">1.1</span><span class="token punctuation">;</span> proxy_set_header Upgrade $http_upgrade<span class="token punctuation">;</span> proxy_set_header Connection keep<span class="token operator">-</span>alive<span class="token punctuation">;</span> proxy_set_header Host $host<span class="token punctuation">;</span> proxy_cache_bypass $http_upgrade<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>server <span class="token punctuation">{<!-- --></span> listen <span class="token number">80</span><span class="token punctuation">;</span> server_nane gaoyi<span class="token punctuation">.</span>ctmon<span class="token punctuation">.</span>cn<span class="token punctuation">;</span> index index<span class="token punctuation">.</span>php index<span class="token punctuation">.</span>html index<span class="token punctuation">.</span>htm <span class="token keyword">default</span><span class="token punctuation">.</span>php <span class="token keyword">default</span><span class="token punctuation">.</span>htm <span class="token keyword">default</span><span class="token punctuation">.</span>html location <span class="token operator">/</span> <span class="token punctuation">{<!-- --></span> <span class="token class-name">proxy_pass</span> http<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>localhost<span class="token punctuation">:</span><span class="token number">5005</span><span class="token punctuation">;</span> proxy_http_version <span class="token number">1.1</span><span class="token punctuation">;</span> proxy_set_header Upgrade $http_upgrade<span class="token punctuation">;</span> proxy_set_header Connection keep<span class="token operator">-</span>alive<span class="token punctuation">;</span> proxy_set_header Host $host<span class="token punctuation">;</span> proxy_cache_bypass $http_upgrade<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>server { listen 80; server_nane gaoyi.ctmon.cn; index index.php index.html index.htm default.php default.htm default.html location / { proxy_pass http://localhost:5005; 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; } }
7.保存后,需要重启nginx
到此网址配置完成
(以上就完成了,但下面会出现一种情况,就是我们修改文件后,需要上传dll到线上,所以需要执行以下步骤)
1.上传对应的dll
2.上传后需要执行以下命令
systemctl stop gaoyisystemctl stop gaoyisystemctl stop gaoyi
3.找到对应的网站文件路径,执行运行操作:
cd <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyicd <span class="token operator">/</span>www<span class="token operator">/</span>wwwroot<span class="token operator">/</span>gaoyicd /www/wwwroot/gaoyi
dotnet Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dlldotnet Ctmon<span class="token punctuation">.</span>Web<span class="token punctuation">.</span>dlldotnet Ctmon.Web.dll
4.执行完后需要执行以下命令
systemctl start gaoyisystemctl start gaoyisystemctl start gaoyi
systemctl enable gaoyi<span class="token punctuation">.</span>service #开机运行服务systemctl enable gaoyi<span class="token punctuation">.</span>service #开机运行服务systemctl enable gaoyi.service #开机运行服务
注释
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop qihang.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl –failed #显示启动失败的服务
服务器配置常用端口
80:HTTP端口
443:HTTPS端口
21:FTP端口
465:SMTP邮件发送端口
587:个人QQ邮箱发送端口
1433:SQLSERVER数据库端口
3306: MYSQL数据库端口
8888: 宝塔默认端口
原文链接:https://blog.csdn.net/qq_37290531/article/details/109503833