17、單機運行環境搭建之 --CentOS-6.4下用tcmalloc最佳化nginx

來源:互聯網
上載者:User
一、簡介

tcmalloc全稱thread-caching malloc,是Google開發的開源工具。與標準的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_modulemake 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

至此已經替換成功。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.