centos 6.3 64bit用tcmalloc优化nginx



centos 6.3 64bit用tcmalloc优化nginx
 
一,tcmalloc全称thread-caching malloc,是谷歌开发的开源工具。与标准的glibc库的malloc比。tcmalloc在内存分配效率和速度比malloc高。至于为什么比malloc,有兴趣可以参考。下面这个网址。
http://www.mysqlops.com/2011/06/14/google-tcmalloc-malloc.html#more-737 
二,现在开始介绍在64bit centos 6.3的版本中让nginx使用tcmalloc。需要用到的软件都已经上传到附件中。
三,安装libunwind库。
 
# tar xf libunwind-1.0.tar.gz 
# tar xf libunwind-1.0 
#CFLAGS=-fPIC ./configure添加编译参数 
# make CFLAGS=-fPIC 
# make CFLAGS=-fPIC install 
  www.2cto.com  
这样执行会出现如下错误:
libtool: install: error: relink `libunwind-setjmp.la' with the above command before installing it 
make[3]: *** [install-libLTLIBRARIES] Error 1 
make[3]: Leaving directory `/down/libunwind-1.0/src' 
make[2]: *** [install-am] Error 2 
make[2]: Leaving directory `/down/libunwind-1.0/src' 
make[1]: *** [install] Error 2 
make[1]: Leaving directory `/down/libunwind-1.0/src' 
make: *** [install-recursive] Error 1 
 
产生这种问题的原因:autotools兼容性的问题,运行命令autoreconf -i -f  ,在重新编译安装下。
#autoreconf -i -f 
#make clean 
#CFLAGS=-fPIC ./configure 
#make  CFLAGS=-fPIC  
#make  CFLAGS=-fPIC install 
四,安装gpperftools:
#tar xf  gperftools-2.0.tar.gz 
# cd gperftools-2.0 
#./configure  
#make && make install  
 
这样安装会会报如下错误:
cc1plus: warning: unrecognized command line option "-Wno-unused-result" 
ake: *** [stacktrace.lo] Error 1 
为什么出现在这种错误,因此是64bit系统,至于更深度的解释,安装说明中有。下面重新编译。
#make clean  
#./configure  --enable-frame-pointers  
#make &&  make install  
#echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf 
#ldconfig 
 
五,编译pcre,使nginx支持http rewrite。
# tar xf pcre-8.10.tar.gz  
# cd pcre-8.10 
# ./configure 
# make && make install 
  www.2cto.com  
六,编译nginx
# tar xf nginx-1.2.3.tar.gz  
# ./configure  
--with-http_ssl_module \ 
  --with-http_flv_module \ 
  --with-http_stub_status_module \ 
  --with-http_gzip_static_module \ 
  --http-client-body-temp-path=/var/tmp/nginx/client/ \ 
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 
  --http-scgi-temp-path=/var/tmp/nginx/scgi \ 
  --with-pcre \ 
  --with-google_perftools_module 
# make && make install 
 
7,为gperftools创建线程目录
#mkdir /tmp/tcmalloc 
#chmod 0777 /tmp/tcmalloc 
 
8,修改nginx的配置文件
#vim /usr/local/nginx/conf/nginx.conf 
#pid        logs/nginx.pid; 
google_perftools_profiles /tmp/tcmalloc;添加这一行 
9,启动nginx,并验证tcmalloc有没有正常加载
# /usr/local/nginx/sbin/nginx 
# lsof -n |grep tcmalloc 
nginx      1893    nobody    9w      REG              253,0        0      43018 /tmp/tcmalloc.1893 
nginx      1894    nobody   11w      REG              253,0        0      43016 /tmp/tcmalloc.1894 
至此已经替换成功。
 

相关内容

    暂无相关文章