一、nginx并发优化
server1:172.25.2.1 server2:172.25.2.2 server3:172.25.2.3
- 停止openresty中的nginx,开启原生nginx
/usr/local/openresty/nginx/sbin/nginx -s stop
systemctl start nginx.service

- server2和server3安装apache
yum install -y httpd systemctl enable --now httpd echo server2 > /var/www/html echo server3 > /var/www/html - 修改用户进程可打开文件数限制
vim /etc/security/limits.conf
nginx - nofile 65535

- 显示当前用户限制
ulimit -a  nginx做反向代理服务器: - worker_processes
工作进程数(最好将其设置为可用的CPU内核数)或者,可以将其设置为auto。 这样nginx会自动根据核心数为生成对应数量的worker进程。 - worker_connections
单个工作进程并发连接数 - worker_cpu_affinity 01 10
pu有多少个核,就有几位数,1代表内核开启,0代表内核关闭 - nginx作为http服务器时
max_clients = worker_processes * worker_connections - nginx作为反向代理服务器
max_clients = worker_processes * worker_connections / 2 - 使用epoll模型
use epoll - worker进程的最大打开文件数限制。如果没设置的话,这个值为操作系统的限制。
worker_rlimit_nofile
cd /usr/local/nginx/conf vim nginx.conf    


二、nginx平滑升级与回滚
- 编译新版本nginx,make,但是不make install
tar zxf nginx-1.19.1.tar.gz cd nginx-1.19.1/ vim auto/cc/gcc
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module make #注意不要make install
- 查看编译产生的新版本nginx
 查看版本:  - 复制新版nginx到相关目录下
 - 查看当前运行的版本,1.18.0

kill -USR2 nginx master进程号 升级新程序
kill -WINCH 原nginx master进程号 关闭原worker进程但保留主进程:为了回退
查看当前nginx进程号 版本升级 kill -USR2 nginx master进程号 kill -WINCH 原nginx master进程号 
kill -HUP 原nginx master进程号 #唤醒原进程
kill -WINCH 新nginx master进程号 #回收新版本的worker进程
kill -QUIT 新nginx master进程号 #关闭新版本主进程 

|