查看防火墙状态
systemctl status firewalld.service
关闭运行的防火墙
systemctl stop firewalld.service
禁止防火墙服务器,保证重新启动服务器之后防火墙还是关闭状态
systemctl disable firewalld.service
禁用 SELinux (SELinux 真的会给各种应用带来权限问题,导致部署可能出现各种奇怪及潜在的问题,个人建议关闭。)
vim /etc/selinux/config # 将原本的 SELINUX=enforcing 改为 disbaled SELINUX=disabled 然后重启服务器即可
运行如下命令,将 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
程序dll上传目录:/root/DaineAn/NET5Demo,切换到程序dll所在目录
cd /root/DaineAn/NET5Demo
托管窗口启动程序
dotnet Net5PublishDemo.dll
验证网站是否正常运行(本机)
curl http://localhost:5000
查看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
切换到已经建好的目录 /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就安装完毕了,启动、停止、重启操作都已完成;当然,也可以添加为系统服务,这里就不再演示了。
切换到 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
安装Supervisor
yum -y install python-setuptools easy_install supervisor
配置Supervisor (创建supervisor文件夹,通过echo_supervisord_conf初始化配置文件)
mkdir /etc/supervisor echo_supervisord_conf > /etc/supervisor/supervisord.conf
修改新建的supervisord.conf配置信息,将最后面的
;[include] ;files = relative/directory/*.ini
调整为:
[include] files = /etc/supervisor/conf.d/*.ini
切换到/etc/supervisor 安装目录:
cd /etc/supervisor
创建文件夹
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 ; #进程执行的用户身份 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