CentOS7下让Asp.Net Core的网站自动运行
安装新版本的Nginx(vim /etc/yum.repos.d/nginx.repo)
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
yum-config-manager --enable nginx-mainline
一、安装Nginx
yum install nginx
二、配置Nginx
vi /etc/nginx/nginx.conf
location / { proxy_pass http://127.0.0.1:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_bypass $http_upgrade; }
如果启动Nginx失败,提示bind() to 0.0.0.0:8000 failed (13: Permission denied)则需要在SElinux中把自定义端口加入(默认SELinux只允许80, 81, 443, 488, 8008, 8009, 8443, 9000提供Http服务)
semanage port -l | grep http_port_t yum install policycoreutils-python.x86_64 semanage port -a -t http_port_t -p tcp 8088 #如果添加端口的时候提示 ValueError: 已定义端口,则使用下面的命令,覆盖配置 # semanage port -m -t http_port_t -p tcp 8000 //覆盖
# semanage port -d -t http_port_t -p tcp 6033 //删除
打开Nginx的Web链接状态查看
在nginx.conf配置中增加一个配置(务必注意access_log的配置文件夹是否存在)
location /Nginxstatus { stub_status on; access_log /usr/local/nginx/logs/status.log; auth_basic "NginxStatus"; }
查看结果说明:
Active connections //当前 Nginx 正处理的活动连接数
server accepts handledrequests //总共处理了n个连接,成功创建y次握手,总共处理了z个请求.
Reading //nginx 读取到客户端的 Header 信息数.
Writing //nginx 返回给客户端的 Header 信息数.
Waiting //开启 keep-alive 的情况下,这个值等于active-(reading+writing),意思就是Nginx已经处理完正在等候下一次请求指令的驻留连接.
三、设置Nginx开机启动
systemctl enable nginx.service
四、安装守护进程工具
方法一:
yum install python-setuptools wget https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz tar -zxvf supervisor-4.2.2.tar.gz cd supervisor-4.2.2 python setup.py install # 检查是否正常安装 supervisord -v 4.2.2 # 生成配置文件 mkdir -p /etc/supervisor/conf.d echo_supervisord_conf > /etc/supervisor/supervisord.conf
方法二:yum install supervisor
配置/etc/supervisor/supervisord.conf
[supervisord] logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 loglevel=info ; log level; default info; others: debug,warn,trace pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid nodaemon=false ; start in foreground if true; default false # 重要 minfds=655350 ; min. avail startup file descriptors; default 1024 minprocs=65535 ; min. avail process descriptors;default 200 [include] files = /etc/supervisor/conf.d/*.conf
五、配置守护进程信息
cd /etc/supervisord.d
vi videoserver.ini (注意program:后面的名字是唯一的)
[program:VideoServer.Site] command=dotnet VideoCheckServer.dll directory=/usr/bin/videoserver environment=ASPNETCORE__ENVIRONMENT=Production user=root stopsignal=INT autostart=true autorestart=true startsecs=3 stderr_logfile=/var/log/videoserver.err.log stdout_logfile=/var/log/videoserver.out.log
supervisord -c /etc/supervisord.conf
六、设置开机启动守护工具
systemctl enable supervisord.service
如果要显示验证码,需要安装libgdiplus:
sudo yum install libgdiplus yum install libtiff libtiff-devel libjpeg libjpeg-devel giflib giflib-devel libpng libpng-devel libX11 libX11-devel freetype rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install libgdiplus-devel
如果安装 libgidplus提示缺少glib-2.0 就先安装:
yum install glib2-devel cairo-devel -y
然后执行
./configure --prefix=/usr/local && make && install
Ubuntu在线安装.NET Core SDK流程:
1、将 Microsoft 包签名密钥添加到受信任密钥列表,并添加包存储库。
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb
2、安装 .NET Core SDK 6.0
sudo apt-get update; \ sudo apt-get install -y apt-transport-https && \ sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-6.0
如果只需要安装asp.netcore运行时,则上述最后一句换成
sudo apt-get install -y aspnetcore-runtime-6.0