Nginx连接超时怎么办,进程管理优化助您化解
发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,下文给大家带来Nginx连接超时怎么办,进程管理优化助您化解,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用在行业内累计的经验来做一个解答
千家信息网最后更新 2025年02月05日Nginx连接超时怎么办,进程管理优化助您化解
下文给大家带来Nginx连接超时怎么办,进程管理优化助您化解,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用在行业内累计的经验来做一个解答。
Nginx之连接超时
在企业网站中,为了避免同一个客户长时间占用连接,造成资源浪费
可设置相应的连接超时参数,实现控制连接访问时间
配置nginx
[root@localhost ~]# yum install pcre-devel zlib-devel gcc gcc-c++ -y ##安装环境包[root@localhost ~]# useradd -M -s /sbin/nologin nginx ##创建程序性用户[root@localhost ~]# mkdir /chen ##创建挂载点[root@localhost ~]# mount.cifs //192.168.100.23/LNMP /chen ##挂载Password for root@//192.168.100.23/LNMP: [root@localhost chen]# tar zxvf nginx-1.12.2.tar.gz -C /opt/ ##解压[root@localhost chen]# cd /opt/[root@localhost opt]# lsnginx-1.12.2 rh[root@localhost opt]# cd nginx-1.12.2/[root@localhost nginx-1.12.2]# lsauto CHANGES.ru configure html man srcCHANGES conf contrib LICENSE README./configure \ ##安装nginx组件--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_module[root@localhost nginx-1.12.2]# make && make install ##编译[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ##做软链接让系统能识别nginx的所有人命令[root@localhost nginx-1.12.2]# nginx -t ##检查语法错误nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
写nginx脚本放在系统启动脚本中方便service管理器管理
[root@localhost nginx-1.12.2]# cd /etc/init.d/ ##到系统启动脚本[root@localhost init.d]# vim nginx ##写一个nginx脚本#!/bin/bash#chkconfig: - 99 20 #注释信息#description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx" #这个变量,指向我的命令文件PIDF="/usr/local/nginx/logs/nginx.pid" #这个变量,指向nginx的进程号case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1esacexit 0[root@localhost init.d]# chmod +x nginx ##给Nginx提升权限[root@localhost init.d]# chkconfig --add nginx ##添加nginx[root@localhost init.d]# service nginx start [root@localhost init.d]# netstat -ntap | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17544/nginx: master [root@localhost init.d]# systemctl stop firewalld.service[root@localhost init.d]# setenforce 0
配置连接超时
修改nginx配置文件
[root@localhost ~]# cd /usr/local/nginx/conf/[root@localhost conf]# vim nginx.conf
在http协议级别区域中添加
31 keepalive_timeout 65 180; ##65是云服务器超时时间,180是客户端超时时间 32 client_header_timeout 80; ##80是网页中的头部超时时间 33 client_body_timeout 80; ##80是网页中身体的超时时间[root@localhost conf]# service nginx stop[root@localhost conf]# service nginx start
nginx进程管理优化
查看进程
[root@localhost conf]# ps aux | grep nginxroot 51524 0.0 0.0 20544 600 ? Ss 20:05 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 51525 0.0 0.0 23072 1388 ? S 20:05 0:00 nginx: worker processroot 51531 0.0 0.0 112728 972 pts/3 S+ 20:06 0:00 grep --color=auto nginx
master只是起到一个监督的作用,不会去处理请求
worker才是工作进程,处理请求
这边我们只有一工作进程,所有的请求都会交给它
如果我们想优化就要去扩展,我们在虚拟机中,直接扩展如果我们这个nginx是在阿里云上面,即可以手动扩,也可以自动扩,自动扩就要写一个自动编排的工具,我们需要触发到比如CPU不足,这个时候就需要zbbix监控。
cpu 内存 硬盘 网络带宽 这些叫做垂直扩展
服务器实例的数量 叫做水平扩展
[root@localhost conf]# init 0 ##关闭服务器才能扩展
回到服务器中修改配置文件
[root@localhost ~]# cd /proc/ ##查看你的cpu,内存信息[root@localhost proc]# ls1 1536 1790 305 40 526 626 717 devices mtrr10 1542 18 306 41 53 628 72 diskstats net100 1545 189 307 416 54 63 723 dma pagetypeinfo1082 1557 19 31 417 55 630 724 driver partitions1084 1562 2 319 418 558 651 73 execdomains sched_debug1085 1565 20 32 42 560 652 732 fb schedstat1089 1581 21 320 43 575 654 733 filesystems scsi1096 1594 22 33 433 576 666 74 fs self11 16 23 333 44 577 667 75 interrupts slabinfo1106 1613 24 334 443 578 668 76 iomem softirqs1107 1629 25 335 45 579 669 763 ioports stat12 1633 26 336 450 580 671 77 irq swaps1228 1637 27 337 451 581 674 78 kallsyms sys126 1640 28 338 456 582 675 79 kcore sysrq-trigger13 1648 288 339 47 583 679 8 keys sysvipc131 1651 289 34 48 584 685 80 key-users timer_list1335 1660 29 340 486 585 686 888 kmsg timer_stats1337 1668 290 341 49 586 687 9 kpagecount tty1338 1680 298 342 5 587 690 99 kpageflags uptime136 1687 299 343 50 588 697 acpi loadavg version14 1689 3 35 51 589 698 buddyinfo locks vmallocinfo1438 1696 30 36 516 590 7 bus mdstat vmstat1449 17 300 360 52 593 700 cgroups meminfo zoneinfo1478 1739 301 37 522 6 701 cmdline misc1479 1741 302 38 523 60 703 consoles modules15 1749 303 39 524 61 71 cpuinfo mounts1532 1768 304 4 525 62 716 crypto mpt
[root@localhost proc]# cat cpuinfo ##查看CPU,有8个核心数processor : 7vendor_id : GenuineIntelcpu family : 6model : 94model name : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHzstepping : 3microcode : 0xcccpu MHz : 2591.567cache size : 6144 KBphysical id : 1siblings : 4core id : 3cpu cores : 4apicid : 7initial apicid : 7fpu : yesfpu_exception : yescpuid level : 22wp : yes
修改nginx配置文件
[root@localhost proc]# cd /usr/local/nginx/conf/[root@localhost conf]# vim nginx.conf 3 worker_processes 8; ##第三行修改原来只有一个核心数,现在我们改成8个每个核心数默认处理1024个请求
让所有的请求分摊给这8个核心数去处理,做负载均衡
4 worker_cpu_affinity 01 10 [root@localhost conf]# service nginx stop[root@localhost conf]# service nginx start[root@localhost conf]# ps aux | grep nginx ##查看进程root 1951 0.0 0.0 20544 660 ? Ss 23:24 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 1952 0.0 0.0 23072 1396 ? S 23:24 0:00 nginx: worker processnginx 1953 0.0 0.0 23072 1384 ? S 23:24 0:00 nginx: worker processnginx 1954 0.0 0.0 23072 1388 ? S 23:24 0:00 nginx: worker processnginx 1955 0.0 0.0 23072 1396 ? S 23:24 0:00 nginx: worker processnginx 1956 0.0 0.0 23072 1388 ? S 23:24 0:00 nginx: worker processnginx 1957 0.0 0.0 23072 1396 ? S 23:24 0:00 nginx: worker processnginx 1958 0.0 0.0 23072 1396 ? S 23:24 0:00 nginx: worker processnginx 1959 0.0 0.0 23072 1396 ? S 23:24 0:00 nginx: worker process
root 1984 0.0 0.0 112728 972 pts/0 S+ 23:25 0:00 grep --color=auto nginx
看了以上关于Nginx连接超时怎么办,进程管理优化助您化解,如果大家还有什么地方需要了解的可以在行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,技术工程师在行业内拥有十几年的经验了。
进程
管理
时间
配置
文件
服务器
核心
脚本
处理
服务
系统
怎么办
在行
均衡
业内
信息
内存
变量
只有
命令
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发中的最佳实践
服务器装多少个win系统
软件开发周期单位
pde文件导入数据库
浙江勇启互联网科技有限公司
网络安全法承担义务
万方数据库为什么以万方命名
戴尔服务器关机了开不了
sql数据库英文版导入和导出
软件开发中间件免费版
数据库中空值如何标识
灵月服务器生存开场动画
图片数据库怎么存入mysql
oracle12备份数据库
避免数据库直接操作
服务器域名备案如何转让给个人
电脑服务器有哪些服务
计算机网络技术所属什么意思
数据库关闭安全模式
数据库压缩教程
中国电科网络安全信息周
监利启明电脑网络技术
pcm 数据库
网络安全预防咋骗
百度云服务器安全组设置
怎么看服务器磁盘uuid
2k服务器有软件版的吗
戴尔服务器怎么安装
数据库持久层用什么
做软件开发是不是英文要好