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

一、简介

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

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

二、安装libunwind库。

cd /usr/local
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar xf libunwind-1.1.tar.gz cd libunwind-1.1
CFLAGS=-fPIC ./configure  #添加编译参数 make CFLAGS=-fPIC make CFLAGS=-fPIC install

三、 安装gpperftools:

cd /usr/local

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

./configure
make && make install 

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

/sbin/ldconfig

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

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

   #cd /usr/local/src

#wget http://tengine.taobao.org/download/tengine-1.4.4.tar.gz
#tar zxvf tengine-1.4.4.tar.gz
#cd tengine-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 
make install
 

四、配置过程 

为gperftools创建线程目录

mkdir /tmp/tcmalloc 
chmod 0777 /tmp/tcmalloc 

 

修改nginx的配置文件

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

#pid        logs/nginx.pid; 

google_perftools_profiles /tmp/tcmalloc;

添加这一行 

 

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

# service nginx restart

安装一下lsof命令:

yum install lsof -y

# lsof
-n |grep tcmalloc

至此已经替换成功。

posted @ 2013-04-15 09:46  糖豆爸爸  阅读(2037)  评论(0编辑  收藏  举报
Live2D