预先安装autoconf 和 make
yum -y install autoconf make
jemalloc的安装
jiemalloc 开源项目网站 http://www.canonware.com/jemalloc/
wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 tar -xjf jemalloc-3.6.0.tar.bz2 cd jemalloc-3.6.0 ./configure --prefix=/usr/local/jemalloc --libdir=/usr/local/lib make && make install make clean cd ../ echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf /sbin/ldconfig
使用jemalloc优化MYSQL数据库
MYSQL或者MariaDB源码编译时添加以下参数:
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF
或者编辑mysqld_safe文件直接加载:
查找文件 /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe 下面加上
LD_PRELOAD=/usr/local/lib/libjemalloc.so
重新启动MYSQL
使用下面代码自动修改mysqld_safe文件
sed -i 's@executing mysqld_safe@executing mysqld_safe export LD_PRELOAD=/usr/local/lib/libjemalloc.so@' /usr/local/mysql/bin/mysqld_safe service mysqld restart
使用jemalloc优化NGINX
编译NGINX时添加以下参数:
--with-ld-opt="-ljemalloc"
验证 jemalloc 是否运行:
lsof -n | grep jemalloc