linux之nginx优化之自身优化

一、 nginx根据自身优化:

1、基于编译安装包优化

  例如:tar -zxvf nginx.tar.gz

  cd nginx/auto/cc

  vim gcc

  注释:关闭nginx的debug模块,减小安装包大小

   #debug

            #CFLAGS="$CFLAGS -g" 

2、基于nginx性能优化,通过googl-pertools及libunwind库包优化,针对服务器性能以及并发数、内存分配、速度进行优化。

例如:1、安装libunwind

   tar -zxvf libunwind.tar.gz

cd libunwind

CFLAGS=-fPIC ./confgure

make CFLAGS=-fPIC

make CFLAGS=-fPIC install

2、安装gperftools

tar -zxvf gperftools.tat.gz

cd gperftools

./configure

make && make install

3、重新编译nginx

tar -zxvf nginx.tar.gz

cd nginx

./configure --with-http_stub_status_module 支持健康监控模块

--with-google_perftools_module 支持gperftllos模块

--prefix=/usr/local/nginx  安装目录

4、创建文件夹,存放gperftools文件

mkdir  /tmp/tcmallor

chmod 777 /tmp/tcmallor

5、修改nginx配置文件,配置支持gperftools存放文件

打开nginx.conf

在pid下增加

google_perftooks_profiles /tmp/tcmallor

然后启动nginx

可以查看lsof -n|grep tcmallor 查看是否存在数据

二、通过nginx内核优化

   加入到linux内核参数中,/etc/sysctl.conf文件中。生效:/sbin/sysctl -p

例如:

net.ipv4.tcp_max_tw_backets=6000 设定timewait的数量,默认为180000

net.ipv4.ip_local_port_range=1024 65000 设定打开端口的范围

net.ipv4.tcp_tw_recycle=1 启用timewait快速回收

net.ipv4.tcp_tw_reuse=1  允许timewait 的 socket重用于新的链接

net.ipv4.tcp_syncookies=1 启用syncookies,当syn列队溢出时候,启用cookies处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值