1、下载jemalloc

1
2
3
4
5
6
7
wget https://github.com/jemalloc/jemalloc/releases/download/5.1.0/jemalloc-5.1.0.tar.bz2
tar xjf jemalloc-5.1.0.tar.bz2
cd jemalloc-5.1.0
./configure
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

2、编译nginx

1
./configure --prefix=/data/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-openssl=../openssl-1.1.1a --with-zlib=../zlib-1.2.11 --with-pcre=../pcre-8.42 --add-module=../ngx_brotli --with-ld-opt="-ljemalloc"

3、重启nginx

1
2
3
4
5
6
7
8
#!/bin/bash
/usr/bin/cp -rpf /data/nginx/sbin/nginx /data/nginx/sbin/nginx_$(date +%Y-%m-%d)
/usr/bin/cp -rpf objs/nginx /data/nginx/sbin/nginx
/bin/kill -USR2 `cat /data/nginx/logs/nginx.pid`
sleep 30s;
ps aux |grep nginx |grep -v grep
/bin/kill -s QUIT `cat /data/nginx/logs/nginx.pid.oldbin`
ps aux |grep nginx |grep -v grep

4、查看

1
lsof -n | grep jemalloc