在Debian系统上打包并使用dropwatch

为什么80%的码农都做不了架构师?>>>   hot3.png

dropwatch 安装

  • 在官网的源码浏览里找到git地址:

https://git.fedorahosted.org/git/dropwatch.git

  • 在 Makefile 和 dropwatch.spec 文件里可以看到源码包的地址和版本。

https://fedorahosted.org/releases/d/r/dropwatch

  • 源码编译安装
sudo apt-get -y install libnl-3-dev libnl-genl-3-dev binutils-dev 
mkdir -pv ~/deb-{file,root}
cd ~/deb-file
git clone https://git.fedorahosted.org/git/dropwatch.git
cd ~/deb-file/dropwatch/src
make
sudo cp -fv ~/deb-file/dropwatch/src/dropwatch /usr/bin/dropwatch 

dropwatch 打包

  • 使用 fpm 快速打包:
mkdir -pv ~/deb-root/dropwatch_1.4-1/usr/bin
cp -fv ~/deb-file/dropwatch/src/dropwatch ~/deb-root/dropwatch_1.4-1/usr/bin/dropwatch 
fpm -f -s dir -t deb -n dropwatch --epoch 1 -v 1.4 --iteration 1 -C ~/deb-root/dropwatch_1.4-1 -p ~/deb-file -d 'libnl-3-200' -d 'libnl-genl-3-200' --verbose --category 'Applications/System' --description 'Kernel dropped packet monitor' --url 'fedorahosted.org/dropwatch' --license 'GPLv2+' -m 'higkoo' usr/bin/dropwatch
  • 打包成功:
Setting workdir {:workdir=>"/tmp", :level=>:info}
Setting from flags: category=Applications/System {:level=>:info}
Setting from flags: description=Kernel dropped packet monitor {:level=>:info}
Setting from flags: epoch=1 {:level=>:info}
Setting from flags: iteration=1 {:level=>:info}
Setting from flags: license=GPLv2+ {:level=>:info}
Setting from flags: maintainer=higkoo {:level=>:info}
Setting from flags: name=dropwatch {:level=>:info}
Setting from flags: url=fedorahosted.org/dropwatch {:level=>:info}
Setting from flags: version=1.4 {:level=>:info}
Converting dir to deb {:level=>:info}
epoch in Version is set {:epoch=>"1", :level=>:warn}
No deb_installed_size set, calculating now. {:level=>:info}
Reading template {:path=>"/var/lib/gems/2.1.0/gems/fpm-1.4.0/templates/deb.erb", :level=>:info}
Debian packaging tools generally labels all files in /etc as config files, as mandated by policy, so fpm defaults to this behavior for deb packages. You can disable this default behavior with --deb-no-default-config-files flag {:level=>:warn}
Creating {:path=>"/tmp/package-deb-build20160108-3103-169fb7d/control.tar.gz", :from=>"/tmp/package-deb-build20160108-3103-169fb7d/control", :level=>:info}
Creating boilerplate changelog file {:level=>:info}
Reading template {:path=>"/var/lib/gems/2.1.0/gems/fpm-1.4.0/templates/deb/changelog.erb", :level=>:info}
Created package {:path=>"~/deb-file/dropwatch_1.4-1_amd64.deb"}
  • 查看包内容lesspipe ~/deb-file/dropwatch_1.4-1_amd64.deb
~/deb-file/dropwatch_1.4-1_amd64.deb:
 new debian package, version 2.0.
 size 15896 bytes: control archive=420 bytes.
     306 bytes,    12 lines      control              
      52 bytes,     1 lines      md5sums              
 Package: dropwatch
 Version: 1:1.4-1
 License: GPLv2+
 Vendor: higkoo@compiler
 Architecture: amd64
 Maintainer: higkoo
 Installed-Size: 34
 Depends: libnl-3-200, libnl-genl-3-200
 Section: Applications/System
 Priority: extra
 Homepage: fedorahosted.org/dropwatch
 Description: Kernel dropped packet monitor
*** Contents:
drwx------ 0/0               0 2016-01-08 22:33 ./
drwxr-xr-x 0/0               0 2016-01-08 22:33 ./usr/
drwxr-xr-x 0/0               0 2016-01-08 22:33 ./usr/bin/
-rwxr-xr-x 0/0           35728 2016-01-08 22:33 ./usr/bin/dropwatch
drwxr-xr-x 0/0               0 2016-01-08 22:33 ./usr/share/
drwxr-xr-x 0/0               0 2016-01-08 22:33 ./usr/share/doc/
drwxr-xr-x 0/0               0 2016-01-08 22:33 ./usr/share/doc/dropwatch/
-rw-r--r-- 0/0             131 2016-01-08 22:33 ./usr/share/doc/dropwatch/changelog.Debian.gz

dropwatch 使用

  • 查看支持的模块列表 dropwatch -l list
  • 监视指定模块 dropwatch -l kas
  • 输入 start 开始
  • Ctrl + c 中止
  • 输入 exit 退出
higkoo@compiler:~$ dropwatch -l list
Available lookup methods:
kas - use /proc/kallsyms
higkoo@compiler:~$ dropwatch -l kas
Initalizing kallsyms db
dropwatch> start
Enabling monitoring...
Kernel monitoring activated.
Issue Ctrl-C to stop monitoring
1 drops at tcp_rcv_state_process+1b6 (0xffffffff8146ca66)
1 drops at sk_stream_kill_queues+4b (0xffffffff814130cb)
1 drops at tcp_rcv_state_process+1b6 (0xffffffff8146ca66)
1 drops at sk_stream_kill_queues+4b (0xffffffff814130cb)
2 drops at tcp_rcv_state_process+1b6 (0xffffffff8146ca66)
2 drops at sk_stream_kill_queues+4b (0xffffffff814130cb)
1 drops at ip_rcv_finish+16b (0xffffffff814534fb)
1 drops at tcp_rcv_state_process+1b6 (0xffffffff8146ca66)
1 drops at sk_stream_kill_queues+4b (0xffffffff814130cb)
1 drops at tcp_rcv_state_process+1b6 (0xffffffff8146ca66)
1 drops at sk_stream_kill_queues+4b (0xffffffff814130cb)
^CGot a stop message
dropwatch> exit
Shutting down ...
  • 放到仓库其它机器即可享用 sudo apt-get -y install dropwatch
    在Debian系统上打包并使用dropwatch_第1张图片

遇到的问题

  • 原来 dropwatch 只有 el 友好:
higkoo@compiler:~/deb-file/dropwatch$ make
mkdir -p stage 
ln -s ~/deb-file/dropwatch stage/dropwatch-1.4
tar jchf ~/deb-file/dropwatch/stage/dropwatch-1.4.tbz2 --exclude \.git --exclude stage -C stage dropwatch-1.4/
mv ~/deb-file/dropwatch/stage/*.tbz2 ~/deb-file/dropwatch
rm -f -r stage
rpmbuild --define "_sourcedir ~/deb-file/dropwatch" --define "_srcrpmdir ~/deb-file/dropwatch" -bs ~/deb-file/dropwatch/dropwatch.spec
/bin/sh: 1: rpmbuild: not found
Makefile:19: recipe for target 'srpm' failed
make: *** [srpm] Error 127
  • 依赖libnl库,sudo apt-get -y install libnl-3-200 libnl-3-dev
higkoo@compiler:~/deb-file/dropwatch/src$ make
Package libnl-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libnl-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libnl-3.0' found
cc -g -Wall -Werror  -D_GNU_SOURCE  -c -o main.o main.c
main.c:38:29: fatal error: netlink/netlink.h: No such file or directory
 #include 
                             ^
compilation terminated.
: recipe for target 'main.o' failed
make: *** [main.o] Error 1
  • 依赖BFD库,sudo apt-get -y install binutils-dev
higkoo@compiler:~/deb-file/dropwatch/src$ make
cc -g -Wall -Werror -I/usr/include/libnl3  -D_GNU_SOURCE  -c -o main.o main.c
cc -g -Wall -Werror -I/usr/include/libnl3  -D_GNU_SOURCE  -c -o lookup.o lookup.c
lookup.c:30:17: fatal error: bfd.h: No such file or directory
 #include 
                 ^
compilation terminated.
: recipe for target 'lookup.o' failed
make: *** [lookup.o] Error 1
  • 依赖libnl-genl库,sudo apt-get -y install libnl-genl-3-200 libnl-genl-3-dev
higkoo@compiler:~/deb-file/dropwatch/src$ make
cc -g -Wall -Werror -I/usr/include/libnl3  -D_GNU_SOURCE  -c -o lookup.o lookup.c
cc -g -Wall -Werror -I/usr/include/libnl3  -D_GNU_SOURCE  -c -o lookup_bfd.o lookup_bfd.c
cc -g -Wall -Werror -I/usr/include/libnl3  -D_GNU_SOURCE  -c -o lookup_kas.o lookup_kas.c
cc   main.o lookup.o lookup_bfd.o lookup_kas.o  -lbfd -lreadline -lnl-3 -lnl-genl-3 -o dropwatch
/usr/bin/ld: cannot find -lnl-genl-3
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'dropwatch' failed
make: *** [dropwatch] Error 1

转载于:https://my.oschina.net/anglix/blog/599360

你可能感兴趣的:(在Debian系统上打包并使用dropwatch)