743
技術社區[雲棲]
tcMalloc 配置和優化 nginx 高性能
tcMalloc優化nginx記住:nginx一定要先啟動
1>下載安裝libunwind:
#wget https://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
wget https://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
tar -zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
2>下載安裝Google-perftools
wget https://soft.7dot.com/soft/google-perftools-1.8.tar.gz
tar -zxvf google-perftools-1.8.tar.gz
cd google-perftools-1.8
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
3>重新編譯nginx(使nginx支持Google-perftools)
cd nginx-1.2.8
./configure --with-google_perftools_module --with-http_stub_status_module
#./configure \
#> --with-google_perftools_module --with-http_stub_status_module #--prefix=/usr/local/nginx
make
make install
4> 為google-perftools 添加線程目錄
mkdir /tmp/tcmalloc
chmod 0777 /temp/tcmalloc
5> 修改nginx主配置文件
cd /usr/local/nginx/conf
修改nginx.conf 在pid這行添加下麵代碼
#pid logs/nginx.pid
#google_perftools_profiles /tmp/tcmalloc/
google_perftools_profiles /tmp/tcmalloc
檢查nginx.conf配置是否正確
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
#/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/sbin/conf/nginx.conf
重啟nginx
/usr/local/nginx/sbin/nginx -s reload
#kill -HUP cat /usr/local/nginx/logs/nginx.pid
ps ax | grep nginx | grep -v grep | awk '{print $1}' | xargs kill -9
6> 驗證
lsof -n | grep tcmalloc
最後更新:2017-04-03 05:39:11