您的位置:首页 > 运维架构 > Nginx

17、单机运行环境搭建之 --CentOS-6.4下用tcmalloc优化nginx

2013-04-15 09:46 816 查看

一、简介

tcmalloc全称thread-cachingmalloc,是谷歌开发的开源工具。与标准的glibc库的malloc比。tcmalloc在内存分配效率和速度比malloc高。至于为什么比malloc,有兴趣可以参考。下面这个网址。

http://www.mysqlops.com/2011/06/14/google-tcmalloc-malloc.html#more-737


二、安装libunwind库。

cd/usr/local
wgethttp://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gztarxflibunwind-1.1.tar.gz
cdlibunwind-1.1
CFLAGS=-fPIC./configure  #添加编译参数
makeCFLAGS=-fPIC
makeCFLAGS=-fPICinstall


三、安装gpperftools:

cd/usr/local

用迅雷下载https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz然后上传到/usr/local,因为好像wget下载https的东东是不行的,或者很麻烦。

tar-zxvfgperftools-2.0.tar.gz

cdgperftools-2.0

./configure

make&&makeinstall

echo"/usr/local/lib">/etc/ld.so.conf.d/usr_local_lib.conf

/sbin/ldconfig


如果以前优化过mysql,那么gperftools就不用装了。

这里开始安装Nginx,参考我的另一篇博客完成操作。

#cd/usr/local/src

#wgethttp://tengine.taobao.org/download/tengine-1.4.4.tar.gz#tarzxvftengine-1.4.4.tar.gz
#cdtengine-1.4.4


./configure--add-module=/usr/local/src/ngx_cache_purge-2.1--prefix=/usr/local/nginx--with-http_stub_status_module--with-pcre=/usr/local/src/pcre-8.32--with-google_perftools_module

make
makeinstall



四、配置过程

为gperftools创建线程目录

mkdir/tmp/tcmalloc
chmod0777/tmp/tcmalloc


修改nginx的配置文件

vi/usr/local/nginx/conf/nginx.conf

#pidlogs/nginx.pid;

google_perftools_profiles/tmp/tcmalloc;

添加这一行


启动nginx,并验证tcmalloc有没有正常加载

#servicenginxrestart

安装一下lsof命令:

yuminstalllsof-y

#lsof-n|greptcmalloc





至此已经替换成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: