CentOS 5.4 final下Systemtap的安装
一、Systemtap运行环境需求
(1)linux kernel with kprobes (mainline 2.6.11+ or backport);
(2)kernel module build environment (kernel-devel or kernel-smp-devel rpm);
(3)kernel debugging information (kernel-debuginfo rpm);
(4)C compiler (same as what kernel was compiled with);
(5)elfutils with libdwfl for debugging informatin parsing;
(6)root privileges;
即:
(1)内核支持并配置了kprobe(内核2.6.11和以上)
(2)内核模块编译环境(即编译内核模块所需的内核头文件以及模块配置信息,对于Fedora core或RedHat指kernel-devel或kernel-smp-devel RPM包)
(3)内核调试信息(对于Fedora core或Redhat指kernel-debuginfo RPM包)
(4)C编译环境
(5)支持libdwfl的elfutils(只有支持libwdfl的elfutils,systemtap才能正常工作,如果您的系统的elfutils较旧,您必须下载elfutils源码包来编译,systemtap能够和elfutils一块编译)
(6)root权限(为了运行Systemtap,您必须具有root权限)
二、CentOS 5.4 final下安装步骤
内核版本
[root@localhost opt]# uname -r
2.6.18-164.el5 <假若是2.6.18-164.el5xen是表示内核对虚拟化的支持>
操作系统版本
[root@localhost opt]# cat /etc/issue
CentOS release 5.4 (Final) Kernel \r on an \m
Cent OS 5.4发行光盘中包含了下面所列出的大部分包,
可以通过 rpm -q 命令查看,
或者
在图形界面的"应用程序"->"添加/删除软件"->"搜索"->输入软件包名来查询软件包的相关信息。
注意:下面列出的kernel-debuginfo-common,kernel-debuginfo,kernel-xen-debuginfo这三个包一般在发行光盘中都不自带,
需要到网上去下载,下面列出几个下载地址:
(i) http://debuginfo.centos.org/5/i386/ 这里可以下载 Cent OS 5 的kernrl-debuginfo的rpm包。(我的机器是 i386)
(ii) http://rpm.pbone.net/ 选择系统版本号,可以下载到相应的rpm安装包。
(注意) 如果是xen内核应该下载kernel-xen-debuginfo包;
此外kernel-debuginfo-common和kernel-debuginfo版本应该相同,后者依赖于前者,安装时先安装前者;
我在Cent OS 5.4 Final下使用SystemTap时最开始没有安装这两个包,SystemTap仍能正常工作,监测系统调用,不知何故,建议安装上,最后我下载安装的是kernel-debuginfo-2.6.18-194.11.4.el5.i686.rpm和kernel-debuginfo-common-2.6.18-194.11.4.el5.i686;
(1)安装gcc,libcap-devel
gcc是编译器(c、c++),libcap-devel是libcap的开发文件;
查看系统中是否安装相应包,这些包在Cent OS 5.4 final发行光盘都能找到;
[root@localhost opt]# rpm -q gcc
gcc-4.1.2-46.el5
[root@localhost opt]# rpm -q libcap
libcap-1.10-26
(2)安装kernel-headers
kernel-headers是被glibc使用的linux内核的头文件;
查看系统中是否安装相应包,该包在Cent OS 5.4 final发行光盘中能找到;
[root@localhost opt]# rpm -q kernel-headers
kernel-headers-2.6.18-164.el5
(3)安装kernel-devel
kernel-devel是用来构建与内核匹配的内核模块的开发软件包;
如果是Xen内核,需要安装kernel-xen-devel包,如果内核版本是smp的,则需安装kernel-[smp-]devel包;
该包在Cent OS 5.4 final发行光盘中能找到;
[root@localhost opt]# rpm -q kernel-devel
kernel-devel-2.6.18-164.el5
(4)安装kernel-debuginfo-common
该包在Cent OS 5.4 final发行光盘中没有,需要自己下载安装,下载地址在前面已经给出。
[root@localhost opt]# rpm -q kernel-debuginfo-common
package kernel-deguginfo-common is not installed
(5)安装kernel-debuginfo
如果是Xen内核,需要下载并安装kernel-xen-debuginfo;
SystemTap需要通过内核调试信息来定位内核函数和变量的位置。
该包在Cent OS 5.4 final发行光盘中没有,需要自己下载安装,下载地址在前面已经给出。
[root@localhost opt]# rpm -q kernel-xen-debuginfo
package kernel-xen-deguginfo is not installed
安装kernel-debuginfo步骤:
安装kernel-debuginfo(xen内核是kernel-xen-debuginfo)时必须首先安装kernel-debuginfo-common, 否则会提示依赖错误,因为kernel-debuginfo依赖于kernel-debuginfo-common,此外,两者版本应该一致,我下载安装的是:
kernel-debuginfo-2.6.18-194.11.4.el5.i686.rpm ( 内核是xen,则kernel-xen-debuginfo-2.6.18-194.11.4.el5.i686.rpm)
kernel-debuginfo-common-2.6.18-194.11.4.el5.i686
下载地址: http://debuginfo.centos.org/5/i386/
安装 : rpm -ivh *.rpm
查询 : rpm -q kernel-debuginfo
卸载 : rpm -e kernel-debuginfo
安装步骤:
[root@localhost kernel-debuginfo]# ls
kernel-debuginfo-2.6.18-194.11.4.el5.i686.rpm
kernel-debuginfo-common-2.6.18-194.11.4.el5.i686.rpm
[root@localhost kernel-debuginfo]# rpm -ivh kernel-debuginfo-2.6.18-194.11.4.el5.i686.rpm
error: Failed dependencies:
kernel-debuginfo-common-i686 = 2.6.18-194.11.4.el5 is needed by kernel-debuginfo-2.6.18-194.11.4.el5.i686
[root@localhost kernel-debuginfo]# rpm -ivh kernel-debuginfo-common-2.6.18-194.11.4.el5.i686.rpm
Preparing... ########################################### [100%]
1:kernel-debuginfo-common########################################### [100%]
[root@localhost kernel-debuginfo]# rpm -q kernel-debuginfo-common
kernel-debuginfo-common-2.6.18-194.11.4.el5
[root@localhost kernel-debuginfo]# rpm -ivh kernel-debuginfo-2.6.18-194.11.4.el5.i686.rpm
Preparing... ########################################### [100%]
1:kernel-debuginfo ########################################### [100%]
[root@localhost kernel-debuginfo]# rpm -q kernel-debuginfo
kernel-debuginfo-2.6.18-194.11.4.el5
(6)安装elfutils
(i)CentOS5.4 final默认安装了elfutils-0.137
#rpm –q elfutils
elfutils-0.137-3.e15
最好将Centos5.4发行光盘里面所有elfutils*的rpm包都装上;
Centos5.4安装盘中有此软件包, 共有7个
默认已安装的有以下5个rpm包
elfutils-0.137-3.el5.i386.rpm
一组用来处理编译的对象的工具集合
elfutils-libelf-0.137-3.el5.i386.rpm
读取和写入ELF文件(Executable and Linking Format. 大意为可执行、可关联的文件格式)的库
elfutils-libelf-devel-0.137-3.el5.i386.rpm
libelf的开发支持
elfutils-libelf-devel-static-0.137-3.el5.i386.rpm
static archive of libelf
elfutils-libs-0.137-3.el5.i386.rpm
用于处理编译的对象的库
还未安装的有以下几个
elfutils-devel-0.137-3.el5.i386.rpm
处理编译对象的开发库
elfutils-devel-static-0.137-3.el5.i386.rpm
处理编译对象的静态archive
(ii)下载elfutils源码包进行安装
SystemTap需要elfutils软件包提供的库函数来分析调试信息。
目前的SystemTap要求安装elfutils-0.123以上版本。
我们可以从SystemTap的站点下载RPM或者源码来升级。
elfutils老版本的下载地址是: ftp://sources.redhat.com/pub/systemtap/elfutils.old/
其他版本也可以在 https://fedorahosted.org/releases/e/l/elfutils/ 下载
或者 http://kojipkgs.fedoraproject.org/packages/elfutils/
elfutils官网在 https://fedorahosted.org/elfutils/
(7)安装Systemtap
(i)CentOS5.4默认安装了systemtap-0.9.7-5.e15
#rpm -q systemtap
systemtap-0.9.7-5.e15
最好将Centos5.4发行光盘里的Systemtap*包都装上;
Centos5.4默认安装的有2个
systemtap-0.9.7-5.e15.i386
测试系统
systemtap-runtime-0.9.7-5.e15.i386
系统运行时测试设备
还未安装的有:
在图形界面的"应用程序"->"添加/删除软件"->"搜索"->输入软件包名systemtap能够查询软件包的相关信息。
(ii)下载systemtap源码进行安装
从SystemTap的FTP站点下载最新的源码
ftp://sources.redhat.com/pub/SystemTap/snapshots/SystemTap-20100925.tar.bz2
或者
ftp://sources.redhat.com/pub/systemtap/releases/
或者也可以下载 systemtap 的 rpm 包进行安装:在 http://rpm.pbone.net/ 上搜索systemtap.
systemtap官网在 http://sourceware.org/systemtap/documentation.html
然后安装如下:
tar -jxvf SystemTap-20100925.tar.bz2
cd src
./configure
make
make install
我在Cent OS 5.4下未安装 kernel-debuginfo和kernel-debuginfo-common,使用系统默认安装的SystemTap也能够正常工作,但建议安装上 debuginfo 包.
(8)运行简单的Systemtap测试程序;
测试脚本systemtap.stp监控java进程的系统调用:
--------------------------------------------------------------------
global syscalllist
global mpname="java" /* attention : java process'name is lower-case "java" */
global debug=0 /*print middle info*/
global all=0
probe begin {
printf("%s process monitoring started ...\n",mpname)
}
probe syscall.read
{
if(all) printf("current process : %s \n",execname());
/* execname() can get the current process's name */
if (execname() ==mpname) {
/* variable name is syscall's name, it is defined in kernel function */
namex=name
if(debug) printf("%s\n",namex)
/* pid() can get the current process's PID */
pidx=pid()
if(debug) printf("%d\n",pidx)
syscalllist[pidx,namex]++
}
}
probe syscall.write
{
pname=execname()
syscallname=name
count(pname,syscallname)
}
probe kernel.function("sys_read"){
pname=execname()
objname="kf_sys_read"
count(pname,objname)
}
probe kernel.function("sys_write"){
pname=execname()
objname="kf_sys_write"
count(pname,objname)
}
//
//Remarks: Count process's some obj, such syscall,kernel.function
//
//Parameters:
//// pname : process'name
//// objname : syscall name
//
//Return values :
//// null
//
function count(pname,objname){
if (pname==mpname) {
if(debug) printf("%s ",objname)
/* current process' id */
pidx=pid()
if(debug) printf("%d\n",pidx)
syscalllist[pidx,objname]++
} }
/*
probe timer.ms(5000) {
}
*/
function print_info(){
foreach ( [pidx,namex] in syscalllist ) {
printf("%d %s = %d\n", pidx,namex, syscalllist[pidx,namex] )
} }
probe end { print_info()
printf("java process monitoring finished\n")
}
运行 stap -v systemtap.stp 命令,若运行正常则表示systemtap安装成功
[root@localhost systemtap_study]# stap -v monitorJava.stap
Pass 1: parsed user script and 52 library script(s) in 280usr/0sys/293real ms.
Pass 2: analyzed script: 6 probe(s), 4 function(s), 1 embed(s), 4 global(s) in 310usr/350sys/654real ms.
Pass 3: using cached /root/.systemtap/cache/a3/stap_a3128d43c0908f80778e75f469858507_2665.c
Pass 4: using cached /root/.systemtap/cache/a3/stap_a3128d43c0908f80778e75f469858507_2665.ko
Pass 5: starting run.
java process monitoring started ...
4151 kf_sys_read = 14
4151 read = 14
4151 kf_sys_write = 5
4151 write = 5
4049 kf_sys_read = 43
4049 read = 43
4049 kf_sys_write = 13
4049 write = 13
5873 kf_sys_read = 864
5873 read = 864
5873 kf_sys_write = 2
5873 write = 2
5861 kf_sys_read = 2561
5861 read = 2561
5861 kf_sys_write = 29
5861 write = 29
5921 kf_sys_read = 864
5921 read = 864
5921 kf_sys_write = 2
5921 write = 2
5909 kf_sys_read = 2561
5909 read = 2561
5909 kf_sys_write = 29
5909 write = 29
java process monitoring finished
Pass 5: run completed in 0usr/10sys/14408real ms.
[root@localhost systemtap_study]#
三、Cent OS 5.4 Final特殊性说明以及在一般linux系统中systemtap安装步骤
Cent OS 5.4 final在安装操作系统时只要选择了相关软件包即会默认安装上elfutils和systemtap,
并且不需要重新编译内核,因为其内核默认支持相关的选项,这些选项再下面说明。
假若系统没有安装上面叙述的(1)~(5)的一些rpm包以及elfutils和systemtap,
则需要首先下载这些rpm包完成(1)~(5)的安装,再重新编译内核,用新内核启动后再安装elfutils和systemtap
编译内核时必须保证内核支持以下选项:
make menuconfig;配置内核编译选项,按如下方式选择
General setup --->
[*] Kernel->user space relay support (formerly relayfs)
Kernel hacking --->
[*] Kernel debugging
[*] Compile the kernel with debug info
[*] Debug Filesystem
Instrumentation Support --->
[*] Kprobes (EXPERIMENTAL)
Security Options --->
[*] Default Linux Capabilities
退出时,vi .config 查看内核编译配置文件,
确保CONFIG_DEBUG_INFO, CONFIG_KPROBES, CONFIG_RELAY,CONFIG_DEBUG_FS这四项选中,使用如下命令
[root@localhost linux-2.6.25]# grep CONFIG_DEBUG_INFO .config
CONFIG_DEBUG_INFO=y
[root@localhost linux-2.6.25]# grep CONFIG_KPROBES .config
CONFIG_KPROBES=y
[root@localhost linux-2.6.25]# grep CONFIG_RELAY .config
CONFIG_RELAY=y
[root@localhost linux-2.6.25]# grep CONFIG_DEBUG_FS .config
CONFIG_DEBUG_FS=y
编译内核
make clean
make vmlinux modules
make modules_install
make bzImage
make install
用新内核重新启动系统后,安装elfutils*和Systemtap*包
CentOS 5.4 final下Systemtap的安装的更多相关文章
- Centos 6.x 系统下用yum安装Memcache
我们的第一步就是导入第三方软件仓库RPMForge ,首页进行centos 官网找到RPMForge下载地址 http://wiki.centos.org/AdditionalResources/Re ...
- YUM CentOS 7 64位下mysql5.7安装配置
配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ #下载mysql源安装包 # wget http://dev ...
- (转)windows下VMware-workstation中安装CentOS
windows下VMware-workstation中安装CentOS windows下VMware-workstation中安装CentOS,可以分两部分,安装虚拟机和安装CentOS虚拟机.具 ...
- CentOS 6.3(x86_64)下安装Oracle 10g R2
目 录 一.硬件要求二.软件三.系统安装注意四.安装Oracle前的系统准备工作五.安装Oracle,并进行相关设置六.升级Oracle到patchset 10.2.0.4七.使用rlwrap调用sq ...
- 【转】CentOS 6.3(x86_64)下安装Oracle 10g R2
目 录 一.硬件要求二.软件三.系统安装注意四.安装Oracle前的系统准备工作五.安装Oracle,并进行相关设置六.升级Oracle到patchset 10.2.0.4七.使用rlwrap调用sq ...
- 【转】CentOS 6.3(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...
- CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境【转载】
本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/11/28/2778779.h ...
- Linux学习之CentOS(一)--CentOS6.6下Mysql数据库的安装与配置
在这里我是通过yum来进行mysql数据库的安装的,通过这种方式进行安装,可以将跟mysql相关的一些服务.jar包都给我们安装好,所以省去了很多不必要的麻烦!!! [root@larry ~]# c ...
- CentOS 6.3(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...
随机推荐
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- 【树形dp 最长链】bzoj1912: [Apio2010]patrol 巡逻
富有思维性的树形dp Description Input 第一行包含两个整数 n, K(1 ≤ K ≤ 2).接下来 n – 1行,每行两个整数 a, b, 表示村庄a与b之间有一条道路(1 ≤ a, ...
- atlas 日志分析脚本
#!/usr/bin/env python # encoding: utf-8 #@author: 东哥加油! #@file: log_analyze.py #@time: 2018/8/23 17: ...
- 【php】 php 的注释和结束符号之间的关系
Closing PHP tags are recognised within single-line comments: <?php // Code will end here ?> ...
- Windows Server 2008 R2+SQL Server 2014 R2升级到Windows Server 2016+SQL Server 2016
环境: 操作系统:Windows Server 2008 R2 数据库:SQL Server 2014 因SQL Server 2016可以无域创建AlwaysOn集群,集群只剩下单节点也不会挂掉,故 ...
- C++基本数据类型占字节数
32位编译器 char :1个字节char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节.同理64位编译器)short int : 2个字节int: 4个 ...
- 关于EF使用脏读(连接会话开始执行设置隔离级别)
SQL Server中事物隔离级别Read Uncommitted和with(nolock) 注意:应该使用后者(修改后的版本):
- 在 Yii2 项目中使用 Composer 添加 FontAwesome 字体资源
2014-06-21 19:05 原文 简体 繁體 2,123 次围观 前天帮同事改个十年前的网站 bug,页面上一堆 include require 不禁让人抱头痛哭.看到 V2EX 上的讨论说,写 ...
- ubuntu 终端查看图片(eog)
远程登陆服务器的话,是没有办法直接查看图片的,这时我们需要进入图片所在目录,然后通过终端命令查看图片. 想要查看图片,需要通过ssh -X登陆,然后在终端输入命令: eog 图片名
- [android开发篇]使用系统权限流程
1 声明权限https://developer.android.com/training/permissions/declaring.html 每款 Android 应用都在访问受限的沙盒中运行.如果 ...