本次nginx服务器均使用阿里云ecs c6规格族服务器

使用支持长连接的服务,支持长连接即可,本次选用.net服务,用于长连接测试,服务可以自己写一个demo,支持建立长连接就好
# 下载依赖
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
# 创建相关目录src为下载nginx安装包目录,soft为nginx安装目录
mkdir -p /data/{src,soft}
# 进入下载目录
cd /data/src/
# 下载nginx安装包
wget http://nginx.org/download/nginx-1.21.0.tar.gz
# 解压
tar fx nginx-1.21.0.tar.gz
# 配置nginx编译环境
./configure --prefix=/data/soft/nginx --with-http_stub_status_module
# 编译安装
make && make install
vim /data/soft/nginx/conf/nginx.conf
user root;
# 根据cpu核数进行修改该参数,如2核参数写2,8核参数写8
worker_processes 8;
# 同时连接的数量受限于系统上可用的文件描述符的数量,与ulimit -n的参数一致
worker_rlimit_nofile 655350;
# 根据cpu核数编写,2核 01 10,四核,0001 0010 0100 1000,八核如下
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
events {
# 使用epoll模型
use epoll;
# 尽可能多的接受连接
multi_accept on;
# 单个worker进程最大打开的连接数
worker_connections 150000;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream backend {
server 172.16.0.226:7000 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.226:7001 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7000 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7001 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7002 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7003 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7004 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.72:7005 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7000 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7001 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7002 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7003 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7004 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.0.73:7005 weight=1 max_fails=2 fail_timeout=30s;
keepalive 3000;
}
server {
listen 8088;
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
# 修改可打开文件数
vim /etc/security/limits.conf
修改前
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
修改后
root soft nofile 655350
root hard nofile 655350
* soft nofile 655350
* hard nofile 655350
centos7修改可打开文件数
# 修改系统可打开文件数
vim /etc/systemd/system.conf
修改后
# 修改参数
DefaultLimitNOFILE=10240000
DefaultLimitNPROC=10240000
重启生效 reboot
内核参数修改
vim /etc/sysctl.conf
表示可排队数量,本次压测只测长连接,所以长连接数满了后,排队也没用
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
访问:http://jmeter.apache.org/
点击download release

解压即可使用,需要jdk,这里不表了












直接仍到linux系统中就好
因为jmeter启动过程中 默认使用启动参数是-Xms1g -Xmx1g
因为我们使用的是4核8G的压测服务器,所以修改linux系统中jmeter启动参数为4G
vim bin/jmeter +166
这样我们的准备工作就完成了
cd apache-jmeter-5.4.3/bin/
# -n 命令行执行 -t 指定执行脚本
./jmeter -n -t nginx.jmx
# 查看nginx服务器中连接8088端口的连接数
netstat-n | grep 8088 | wc- l

到最后也没压出来nginx具体可以建立多少个长连接,和服务器规格有关吧,哈哈,一次测试,看看对你有啥帮助没,看看你们领导有这个需求不!!!