欢迎光临
我们一直在努力

CentOS7.6 部署 NET5 程序 - NET5 Nginx Supervisor 形式

本站教程收集整理的这篇文章主要介绍了CentOS7.6 部署 NET5 程序 – NET5 Nginx Supervisor 形式,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。

1.关闭防火墙

查看防火墙状态

systemctl status firewalld.service

关闭运行的防火墙

systemctl stop firewalld.service 

禁止防火墙服务器,保证重新启动服务器之后防火墙还是关闭状态

systemctl disable firewalld.service

禁用 SELinux (SELinux 真的会给各种应用带来权限问题,导致部署可能出现各种奇怪及潜在的问题,个人建议关闭。)

vim /etc/selinux/config
#  将原本的 SELINUX=enforcing 改为 disbaled
SELINUX=disabled
然后重启服务器即可

2.安装.NET5 环境

运行如下命令,将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库。

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

安装 runtime 5.0

sudo dnf -y install aspnetcore-runtime-5.0

查看安装的dotnet 版本

dotnet --info


安装 SDK 5.0

sudo dnf -y install dotnet-sdk-5.0
dotnet --version
dotnet --list-runtimes

3.上传待部署的程序dll等文件到发布目录

程序dll上传目录:/root/DaineAn/NET5Demo,切换到程序dll所在目录

cd /root/DaineAn/NET5Demo

托管窗口启动程序

dotnet Net5PublishDemo.dll

验证网站是否正常运行(本机)

curl http://localhost:5000

4.Nginx 安装 依赖的组件/程序

查看gcc版本

gcc -v

安装gcc

yum -y install gcc

pcre、pcre-devel安装 ( pcre是一个perl库,包括perl兼容的正则表达式库,Nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。)

yum install -y pcre pcre-devel

zlib安装 (zlib库提供了很多种压缩和解压缩方式Nginx使用zlib对http包的内容进行gzip,所以需要安装)

yum install -y zlib zlib-devel

安装openssl

yum install -y openssl openssl-devel

5.Nginx 安装

切换到已经建好的目录 /usr/local/softpkg/ ,用户存放下载的Nginx安装包

cd /usr/local/softpkg/

下载Nginx压缩包

wget http://Nginx.org/download/Nginx-1.9.10.tar.gz

把压缩包解压到usr/local/Nginx

tar -zxvf  Nginx-1.9.10.tar.gz -C /usr/local/Nginx

切换到/usr/local/Nginx/Nginx-1.9.10下面:

cd /usr/local/Nginx/Nginx-1.9.10

编辑安装Nginx,执行3个命令:

./configure  #使用默认配置
make #编译安装
make install

查找安装路径:

whereis Nginx
结果:
  Nginx: /usr/local/Nginx

启动、停止Nginx,切换到安装目录

cd /usr/local/Nginx/sbin/
启动Nginx
./Nginx
./Nginx -s stop
./Nginx -s quit
./Nginx -s reload

查看Nginx 服务是否启动成功

ps -ef | grep Nginx

成功返回如下:
root     177725      1  0 14:22 ?        00:00:00 Nginx: master process ./Nginx
nobody   177726 177725  0 14:22 ?        00:00:00 Nginx: worker process
root     177728 177680  0 14:22 pts/1    00:00:00 grep --color=auto Nginx

重启 Nginx

1.先停止再启动(推荐):
对 Nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./Nginx -s quit
./Nginx

2.重新加载配置文件:
当 ngin x的配置文件 Nginx.conf 修改后,要想让配置生效需要重启 Nginx,使用-s reload不用先停止 ngin x再启动 Nginx 即可将配置信息在 Nginx 中生效,如下:
./Nginx -s reload
启动成功后,在浏览器可以看到这样的页面:welcome to Nginx !

开机自启动Nginx ,即在rc.local增加启动代码就可以了。

vi /etc/rc.local

在文件的最后增加一行

/usr/local/Nginx/sbin/Nginx

设置执行权限:

chmod 755 /etc/rc.local

截止目前,Nginx就安装完毕了,启动、停止、重启操作都已完成;当然,也可以添加为系统服务,这里就不再演示了。

6.配置Nginx 代理

切换到 Nginx 安装目录 /usr/local/Nginx/conf/

cd /usr/local/Nginx/conf/

编辑Nginx配置文件 (vi /usr/local/Nginx/conf/Nginx.conf)

vi /usr/local/Nginx/conf/Nginx.conf

[按键盘 i 进入编辑模式 ] 修改 server节点,放入以下配置:

server {
    listen 80;
    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;
    }
}

esc :wq 退出保存
附录:

Nginx常用命令:
切换到安装目录
cd /usr/local/Nginx/sbin/
/usr/local/Nginx/sbin/Nginx //启动Nginx
/usr/local/Nginx/sbin/Nginx -s reload   //重启Nginx
/usr/local/Nginx/sbin/Nginx -s stop    //停止Nginx

7.Supervisor安装和使用

安装Supervisor

yum -y install python-setuptools
easy_install supervisor

配置Supervisor (创建supervisor文件夹,通过echo_supervisord_conf初始化配置文件)

@H_405_11@mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf

修改新建的supervisord.conf配置信息,将最后面的

;[include]
;files = relative/directory/*.ini

调整为:

[include]
files = /etc/supervisor/conf.d/*.ini

8.为.net5 项目添加Supervisor进程配置文件

切换到/etc/supervisor 安装目录:

cd /etc/supervisor

创建文件夹

@H_405_11@mkdir /etc/supervisor/conf.d

切换到/etc/supervisor/conf.d/

cd /etc/supervisor/conf.d/

创建 Net5PublishDemo.ini

touch Net5PublishDemo.ini

编辑 Net5PublishDemo.ini

vi Net5PublishDemo.ini

[按 i 进入编辑模式 ] 在/etc/supervisor/目录下创建名字为conf.d文件夹,在conf.d文件夹中创建一个Net5PublishDemo.ini文件,在Net5PublishDemo.ini文件添加以下配置

[program:Net5PublishDemo]
#运行程序的命令
command=dotnet Net5PublishDemo.dll ; 
#命令执行的目录
directory=/root/DaineAn/NET5Demo/ ; 
#程序意外退出是否自动重启
autorestart=true ; 
#错误日志文件
stderr_logfile=/var/log/Net5PublishDemo.err.log ; 
#输出日志文件
stdout_logfile=/var/log/Net5PublishDemo.out.log ; 
#进程环境变量
environment=ASPNETCORE_ENVIRONMENT=Development 便宜美国vps ; 
#进程执行的用户身份
user=root ; 
stopsignal=INT

esc :wq 保存 退出;
启动Supervisor服务

supervisord -c /etc/supervisor/supervisord.conf

启动服务后可以通过命令查看是否配置成功

ps -ef | grep Net5PublishDemo.dll

结果返回如下代表成功:
root     178367 178366  2 16:37 ?        00:00:00 dotnet Net5PublishDemo.dll
root     178395 178342  0 16:38 pts/1    00:00:00 grep --color=auto Net5PublishDemo.dll

配置Supervisor开机启动,进入/usr/lib/systemd/system/目录,

cd /usr/lib/systemd/system/

并创建supervisord.service文件

touch supervisord.service

编辑 supervisord.service

vi supervisord.service

[按 i 进入编辑模式 ]添加内容

[Unit]
Description=Supervisor daemon
[service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
Killmode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target

使配置生效:

systemctl daemon-reload

设置服务开机启动:

systemctl enable supervisord

启动supervisor进程:

systemctl start supervisord

验证是否为开机启动:

systemctl is-enabled supervisord

Supervisor常用命令:

supervisorctl status    //查看所有任务状态
supervisorctl shutdown  //关闭所有任务

#控制所有进程
supervisorctl start all          
supervisorctl stop all          
supervisorctl restart all

#控制单个进程/程序
supervisorctl start Net5PublishDemo
supervisorctl stop Net5PublishDemo
supervisorctl restart Net5PublishDemo

附录

Execute: sudo dnf install aspnetcore-runtime-5.0
Q1:	sudo: dnf:找不到命令
A:安装 dnf
参照文章:
https://blog.csdn.net/zhongbEIDa_xue/article/details/79577766
https://www.cnblogs.com/jpfss/p/6628736.html

wget http://springDale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm
wget http://springDale.math.ias.edu/data/puias/unsupported/7/x86_64//dnf-0.6.4-2.sdl7.noarch.rpm
wget http://springDale.math.ias.edu/data/puias/unsupported/7/x86_64/python-dnf-0.6.4-2.sdl7.noarch.rpm
yum install python-dnf-0.6.4-2.sdl7.noarch.rpm  dnf-0.6.4-2.sdl7.noarch.rpm dnf-conf-0.6.4-2.sdl7.noarch.rpm
yum -y install dnf
dnf --version

Execute:wget http://springDale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm
Q2:-bash: wget: 未找到命令
A:安装:wget
yum -y install wget
wget --version

Nginx启动时报80端口被占用:
Nginx: [emerg] bind() to 0.0.0.0:80 Failed (98: Address already in usE)

解决办法:1、安装net-tool 包:yum -y install net-tools
./Nginx -s quit:此方式停止步骤是待Nginx进程处理任务完毕进行停止。
./Nginx -s stop:此方式相当于先查出Nginx进程id再使用kill命令强制杀掉进程。

解决办法:2
    先停止 Nginx 再启动Nginx

本站总结

以上是本站教程为你收集整理的CentOS7.6 部署 NET5 程序 – NET5 Nginx Supervisor 形式全部内容,希望文章能够帮你解决CentOS7.6 部署 NET5 程序 – NET5 Nginx Supervisor 形式所遇到的程序开发问题。

如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。