用jemalloc优化nginx、mysql内存管理

 首先下载jemalloc

wget -c http://www.canonware.com/download/jemalloc/jemalloc-4.2.1.tar.bz2
tar jxvf jemalloc-4.2.1.tar.bz2
cd jemalloc-4.2.1
./configure
make
make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

MySQL/MaridDB 5.5编译方法,cmake预编译时加上下面参数

-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF


或者直接加载,修改mysqld_safe

sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' /usr/local/mysql/bin/mysqld_safe
service mysqld restart


使用jemalloc优化Nginx

cd lnmp/src/nginx-1.4.2
make clean
./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"
make
make install


验证jemalloc优化Nginx是否生效,如下

lsof -n | grep jemalloc

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/241.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。