Liunx安装 jemalloc
先github上下载:
https://github.com/jemalloc/jemalloc/releases
下载好源码包,解压
[root@sasha-payment-4 ~ ]# cd /usr/local/src
[root@sasha-payment-4 src ]# tar -xvf jemalloc-4.5.0.tar.bz2
在此目录下预编译:
#编译
[root@sasha-payment-4 src ]#cd jemalloc-4.5.0
[root@sasha-payment-4 jemalloc-4.5.0]# ./configure
完成后再编译:
[root@sasha-payment-4 jemalloc-4.5.0]# make && make install
[root@sasha-payment-4 jemalloc-4.5.0]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
[root@sasha-payment-4 jemalloc-4.5.0]# ldconfig
使用jemalloc优化Nginx
#编译nginx
[root@sasha-payment-4 nginx-1.12.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ld-opt="-ljemalloc"
[root@sasha-payment-4 nginx-1.12.1]# make
#把原来Nginx执行文件backup一份
[root@sasha-payment-4 nginx-1.12.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#拷贝Nginx执行文件
[root@sasha-payment-4 nginx-1.12.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@sasha-payment-4 nginx-1.12.1]# cd objs/
[root@sasha-payment-3 objs]# ls
autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
[root@sasha-payment-4 objs]# mv nginx /usr/local/nginx/sbin/
验证jemalloc优化Nginx是否生效
[root@sasha-payment-4 objs]# lsof -n | grep jemalloc
bash 4206 root cwd DIR 253,1 4096 171966532 /usr/local/src/jemalloc-4.5.0
nginx 18599 root mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18689 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18690 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18691 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18692 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18693 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18694 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18695 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18696 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
nginx 18697 www mem REG 253,1 2601400 12850398 /usr/local/lib/libjemalloc.so.2
说明: 至此jemalloc优化Nginx已生效