纯净版centos7安装netsnmp +python的调用,坎坷之路

错略的安装过程,末尾有帖子,里面有配置的一些详细解释

一、安装net-snmp

选择一个SNMP版本,比如5.7.3,下载地址如下:

http://www.net-snmp.org/download.html

1、上传到/root目录下,并解压

tar xzvf net-snmp-5.7.3.tar.gz
cd net-snmp-5.7.3

2、安装gcc

yum install gcc

3、编译安装

./configure --prefix=/usr/local/snmp --with-mib-modules='ucd-snmp/diskio ip-mib/ipv4InterfaceTable'
make  && make install
可以解决下面make报错问题:
yum install perl-ExtUtils-MakeMaker package

make报错示例:
BEGIN failed--compilation aborted at Makefile.PL line 1.
make: *** [perlmakefiles] Error 2

安装好了之后查看版本
snmpd -v

bash: snmpd: command not found...

我的是因为没有装net-snmp-utils,有时候自己装好了,不用自己装,没弄懂为什么

yum -y install net-snmp-utils

装好后snmpd -v就可以看到版本了

二 、安装Python3和pip

yum install epel-release -y
报错:
[root@bogon net-snmp-5.7.3]# ln -s /bin/python3.6 /bin/python
ln: failed to create symbolic link ‘/bin/python’: File exists
删除Python rm -rf /usr/bin/python
重新建立软连接

ln -s /bin/python3.6 /bin/python
因为yum默认python2

vim /usr/bin/yum

在第一行后面加个数字2即可:

#! /usr/bin/python2

三、导入import net-snmp

echo "/usr/local/snmp/lib" >> /etc/ld.so.conf
ldconfig
python setup.py build
产生报错:
File "setup.py", line 14
  
    sys.argv.remove(arg)
                      ^
    TabError: inconsistent use of tabs and spaces in indentation
    
解决:
vim setup.py

将14行代码tab字符改成空格
因为python版本升级
12行的string没有这个模块
需要改成str
netsnmp/client_intf.c:1:20: fatal error: Python.h: No such file or directory
 #include 
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1
netsnmp/client_intf.c:9:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
 #include 
                                      ^
compilation terminated.
error: command 'gcc' failed with exit status 1
解决:
这是因为缺少Python和net-snmp的环境

yum install python36-devel -y

yum install net-snmp-devel -y
最后总算是完成了:
[root@bogon python]# python
Python 3.6.6 (default, Jan 26 2019, 16:53:05) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netsnmp
>>>

希望朋友们出现什么问题解决后贴到评论里,相互交流下,感谢!

感谢下面的帖子帮助:

安装net-snmp:

http://blog.sina.com.cn/s/blog_930800170102vzau.html
https://www.cnblogs.com/homeways/p/6375394.html

安装Python3:

https://blog.51cto.com/wenguonideshou/2083301

解决yum的一些错误:

https://blog.csdn.net/awenluck/article/details/31782041
https://blog.csdn.net/qq_37960324/article/details/83572850
https://blog.csdn.net/qq_41185868/article/details/86708491

你可能感兴趣的:(linux)