2021-05-12 14:32:11
CentOS 5.8 上安裝 SystemTap-2.6
最近為了分析公司的一個 nginx + lua 的應用效能,正好需要用到春神的那套 nginx-lua 的分析指令碼,因此就立馬去搭建下
環境:
- CentOS 5.8
- Lua 5.2.3
- luajit-2.0.3
- systemtap-2.6
- nginx
依賴項:
- systemtap-2.6 依賴於 elfutils
註:CentOS 5.8 上面安裝 systemtap-2.6 的時候,elfutils 的版本不能太高,不然會報錯,安裝 systemtap-2.6 失敗,目前使用的版本是 elfutils-0.149
該文的前提是你已經編譯安裝好了支援 lua 的 nginx 版本,以及你已經安裝好了 systemstap 所需的你對應作業系統的 kernel-debug-debuginfo
和 kernel-debuginfo-common
,這個版本必須和你的系統的核心版本一模一樣,一個字元不一樣都不行,檢視版本的方法是:
[apps@TEST-APP-011 ~]$ uname -r
2.6.18-308.el5
所以我對應的版本是:
kernel-debug-debuginfo-2.6.18-308.el5.x86_64.rpm
kernel-debuginfo-common-2.6.18-308.el5.x86_64.rpm
具體的安裝步驟可以參考官方文件。
下載安裝所需的軟體
下載 systemtap-2.6
cd /tmp/ && wget https://sourceware.org/systemtap/ftp/releases/systemtap-2.6.tar.gz --no-check-certificate
下載 elfutils-0.149
cd /tmp && wget https://Fedorahosted.org/releases/e/l/elfutils/0.149/elfutils-0.149.tar.bz2 --no-check-certificate
安裝 systemtap-2.6
-
解壓 elfutils-0.149
cd /tmp/ && tar -xvf elfutils-0.149.tar.bz2
-
解壓 systemtap-2.6
cd /tmp && tar -zxvf systemtap-2.6.tar.gz
-
安裝 systemtap-2.6
編譯
cd /tmp/systemtap-2.6 && ./configure --prefix=/opt/stap --disable-docs --disable-publican --disable-refdocs CFLAGS="-g -O2" --with-elfutils=/tmp/elfutils-0.149
安裝
make -j8 && make install
-
做軟連線
sudo ln -snf /opt/stap/bin/stap /usr/bin/stap
-
驗證命令
stap -V Systemtap translator/driver (version 2.6/0.149, non-git sources) Copyright (C) 2005-2014 Red Hat, Inc. and others This is free software; see the source for copying conditions. enabled features: LIBRPM LIBSQLITE3 NSS BOOST_SHARED_PTR TR1_UNORDERED_MAP NLS LIBXML2
註:有時候執行
stap -V
命令的時候會出錯,錯誤如下:
stap: /usr/lib64/libelf.so.1: version `ELFUTILS_1.5' not found (required by stap) stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.138' not found (required by stap) stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.142' not found (required by stap) stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.143' not found (required by stap) stap: /usr/lib64/libdw.so.1: version `ELFUTILS_0.149' not found (required by stap)
解決辦法是,執行如下命令:
//檢視 stap 的安裝路徑
[apps@TEST-APP-011 ~]$ eu-readelf -d /usr/bin/stap|grep -E "RPATH|RUNPATH"
RPATH Library rpath: [/opt/stap/lib/systemtap]
RUNPATH Library runpath: [/opt/stap/lib/systemtap]
// 加入環境變數
export LD_LIBRARY_PATH=/opt/stap/lib/systemtap:$LD_LIBRARY_PATH
使用春神的指令碼
下載指令碼:
git clone https://github.com/openresty/nginx-systemtap-toolkit.git
拿其中的一個指令碼校驗,結果如下:
sudo ./ngx-req-distr -c -m `cat /opt/nginx/sbin/nginx.pid`
Tracing 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 (/opt/nginx-lua/sbin/nginx)...
worker 5959: 0 reqs, 0 conns
worker 5960: 0 reqs, 0 conns
worker 5961: 0 reqs, 0 conns
worker 5962: 0 reqs, 0 conns
worker 5963: 0 reqs, 0 conns
worker 5964: 0 reqs, 0 conns
worker 5965: 0 reqs, 0 conns
worker 5966: 0 reqs, 0 conns
worker 5967: 0 reqs, 0 conns
worker 5968: 0 reqs, 0 conns
worker 5969: 0 reqs, 0 conns
worker 5970: 387290 reqs, 15 conns
worker 5971: 610857 reqs, 106 conns
worker 5972: 0 reqs, 0 conns
worker 5973: 0 reqs, 0 conns
worker 5974: 21 reqs, 74 conns
worker 5975: 0 reqs, 0 conns
worker 5976: 531284 reqs, 96 conns
worker 5977: 571358 reqs, 213 conns
worker 5978: 560546 reqs, 165 conns
worker 5979: 629476 reqs, 14297 conns
worker 5980: 575010 reqs, 247 conns
worker 5981: 650624 reqs, 622 conns
worker 5982: 499562 reqs, 249 conns
worker 5983: 0 reqs, 0 conns
軟體來源地址
- https://fedorahosted.org/releases/e/l/elfutils/0.149/
- https://github.com/openresty/nginx-systemtap-toolkit
- http://debuginfo.centos.org/5/x86_64/
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-06/118588.htm
相關文章