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-debuginfokernel-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

  1. 解压 elfutils-0.149

    cd /tmp/ && tar -xvf elfutils-0.149.tar.bz2
    
  2. 解压 systemtap-2.6

    cd /tmp && tar -zxvf systemtap-2.6.tar.gz
    
  3. 安装 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
    
  4. 做软连接

    sudo ln -snf /opt/stap/bin/stap /usr/bin/stap
    
  5. 验证命令

    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#sample-bt
  • http://debuginfo.centos.org/5/x86_64/

参考阅读

  • https://github.com/openresty/nginx-systemtap-toolkit#sample-bt
  • http://m.blog.csdn.net/blog/hubaolin/18146413

你可能感兴趣的:(lua,luajit,nginx,systemtap,centos)