守护进程collectd工具中python插件不可用解决办法

来源:互联网 发布:手机旋转屏幕软件 编辑:程序博客网 时间:2024/06/07 13:51

  笔者在Redhat、ubuntu两个系统中都用collectd-5.7.2.tar.bz2的包装了collectd工具,系统自带python,其中Redhat自带python2.6,ubuntu自带python2.7。在collectd装好以后,进入/opt/collectd/etc/collect.conf配置文件中,可以看到##LoadPlugin python,这代表python插件不可用,然后回过头,查看collect安装过程中./configure配置过程:

checking for python3-config... nochecking for python2-config... nochecking for python-config... nochecking Python.h usability... nochecking Python.h presence... nochecking for Python.h... no
libpython . . . . . . no
Modules:...python  . . . . . . . no...

  虽然系统中有python,但是配置的时候并没有将依赖项配置出来,又尝试安装高版本python,软连接修改默认版本,修改了环境变量巴拉巴拉一大堆操作,然并卵,虽然安装高版本以后,可以配置到python,但是安装collectd的结果是安装不完整,没有share,没有etc......

  走到绝路的时候终于发现条重要信息:点击打开链接,表明上不是一个问题,但本质差不多,原来是因为没有安装python-dev,虽然在终端输入python也可以直接调用python的 交互模式:

root@ubuntu:/home/yanlei/Downloads/collectd-5.7.2# pythonPython 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> 

python使用是能正常使用,但还是需要安装python-dev,这是为什么呢,分析见链接:点击打开链接。

linux发行版通常会把类库的头文件和相关的pkg-config分拆成一个单独的xxx-dev(el)包.
以python为例, 以下情况你是需要python-dev的:
(1)你需要自己安装一个源外的python类库, 而这个类库内含需要编译的调用python api的c/c++文件
(2)你自己写的一个程序编译需要链接libpythonXX.(a|so)
(注:以上不含使用ctypes/ffi或者裸dlsym方式直接调用libpython.so)
其他正常使用python或者通过安装源内的python类库的不需要python-dev.

安装命令如下:

root@ubuntu:/home/yanlei# apt-get install python-dev

  然后将已装好的collectd工具卸载,卸载方式可以自行百度,或者回到解压包用make uninstall,然后直接将/opt下collectd目录直接用rm-rf删除,重新安装collectd,注意./configure配置的结果:

checking for python3-config... nochecking for python2-config... /usr/bin/python2-configchecking Python.h usability... yeschecking Python.h presence... yeschecking for Python.h... yes
libpython . . . . . . yes
Modules:python  . . . . . . . yes
  这说明已经找到需要依赖的东西了,安装完成后打开collectd.conf,可以看到python插件前的符号已经由两个#变成了一个#号:

#LoadPlugin python
到此为止,python插件就可以正常使用了。


(PS:笔者是个刚入行的新手,操作Linux才一个星期,上面一些概念可能会有说得不对的地方,请见谅。)