nginx之tengine与高并发内核参数

nginx发行版tengine的基础安装配置,与实现nginx高并发相关内核参数的调整

tengine部署

http://tengine.taobao.org/

淘宝开源的nginx的二次开发版;

Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

1,安装依赖包

yum install -y gcc gcc++ zlib-devel openssl-devel pcre-devel
编译工具
压缩
加密
正则

2,三步走

解压后
./configure
make
make install

默认安装的prefix是/usr/local/nginx
nginx -v查看版本为tengine
启动访问测试页面也是tengine

tengine支持DSO,sbin目录多了个dso_install命令
nginx -V 显示默认带有编译的模块,全是static
<prefix>/modules放模块目录

参数基本兼容nginx,额外特性具体参考官网,注意基本哪个版本的nginx的指令配置;

[root@host4 nginx]# ./sbin/nginx -v
Tengine version: Tengine/2.2.1 (nginx/1.8.1)

nginx高并发相关内核参数调优

nginx的高并发特性,需要底层内核支持;

内核参数设置:适用的是大多数通用场景;针对nginx的高并发场景,需要设置不同的内核参数;**且nginx做web,做四层反代,七层反代,做内容缓存,需要的内核参数也不尽相同;**

提高并发tcp连接的配置

编辑/etc/sysctl.conf

[root@host2 ~]# cat /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.file-max=999999
# 单个进程最大可以打开的句柄数
net.ipv4.tcp_tw_reuse = 1
# 1表示,允许time-wait状态的连接的socket重新用于新的tcp连接,对于有大量的time-wait的连接来说,可提高效率

net.ipv4.tcp_keepalive_time=600
# tcp发送keepalive消息的间隔,默认2h,改为10min,更快清理无效连接
net.ipv4.tcp_fin_timeout = 30
#服务器关闭连接时,socket保持在fin-wait-2状态的时间
#
net.ipv4.tcp_max_tw_buckets = 5000
# 允许time-wait状态的套接字数量的最大值,若超过会立即开始清理,默认是8000,过多的time-wait套接字,会使得服务器变慢
#
net.ipv4.ip_local_port_range = 1024 65000
# 定义tcp udp连接的本地端口取值
net.ipv4.tcp_rmem = 10240 87380 12582912
# 定义tcp接收缓存的最小值 默认值 较大值
net.ipv4.tcp_wmem = 10240 87380 12582912
# 定义tcp写缓存的最小 默认 最大值
net.core.netdev_max_backlog=8096
# 网卡接收数据包速度大于内核处理速度时,暂时保存的队列大小
#
#
# 以下4参数根据实际情况而定
net.core.rmem_default = 6291456
# 内核套接字读即接收缓存区默认大小
net.core.wmem_default = 6291456
#内核套接字发送缓冲区默认大小
net.core.rmem_max=12582912
net.core.wmem_max=12582912
#内核套接字发送接收缓存区最大值


net.ipv4.tcp_syncookies=1
#解决tcp的syn攻击
net.ipv4.tcp_max_syn_backlog=8192
#tcp握手时,syn队列的较大长度,默认1024,设置大防止nginx繁忙来不及调用accept时,客户端的连接不至于被丢失
net.ipv4.tcp_tw_recycle=1
#启用timewait快速回收
#net.core.somaxconn=262114
#默认128,调节系统同时发起的tcp连接数,高并发场景,默认值会导致连接超时或重传
net.ipv4.tcp_max_orphans=262114
# 用于简单防止dos攻击

# sysctl -p生效
# sysctl -a查看所有目前的内核参数
[root@host2 ~]# sysctl -p
fs.file-max = 999999
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_rmem = 10240 87380 12582912
net.ipv4.tcp_wmem = 10240 87380 12582912
net.core.netdev_max_backlog = 8096
net.core.rmem_default = 6291456
net.core.wmem_default = 6291456
net.core.rmem_max = 12582912
net.core.wmem_max = 12582912
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 262114
updatedupdated2020-10-192020-10-19
加载评论