【Net 您所在的位置:网站首页 ubuntu编译安装软件源码默认在哪 【Net

【Net

2024-06-01 04:52| 来源: 网络整理| 查看: 265

1. 源码地址 https://github.com/net-snmp/net-snmp https://sourceforge.net/projects/net-snmp/files/net-snmp 2. 环境介绍 使用的NET-SNMP版本为5.9.3 Linux 系统为 centos-release-7-6.1810.2.el7.centos.x86_64 3. 源码编译 3.1 首先配置编译参数 configure 选项参数说明–prefixnet snmp 安装路径–with-default-snmp-version默认使用版本–with-sys-location设备位置–with-logfile日志文件路径-with-persistent-directory不变数据存储路径–build交叉编译环境系统说明(编译平台)–host交叉编译目标环境(运行平台)–with-endianness指定大小端模式–enable-mini-agent使用最小agent–with-cc --with-linkcc --with-ar交叉编译器使用的gcc–disable-applications不编译snmpget snmpset等应用–disable-manuals不安装网管软件的说明手册–disable-snmptrapd-subagent不支持snmptrapd的agent子代理–disable-ipv6不支持IPv6–with-mib-modules添加具体模块(dlmod agentx …)–disable-embedded-perl不支持嵌入式perl–disable–perl-cc-checks不需要perl检查–with-sys-contact设备的联系人–with–sys-location设备地址–disable-scripts不需要安装mib2c等工具 3.2 编写配置脚本

因为配置项过多,因此这里写一个 localBuild.sh 脚本文件进行configure参数配置。

# --prefix 指定安装目录当当前源文件的 out文件夹(需要我们自己创建) # --disable-manuals 不安装网管软件的说明手册 # --disable-snmptrapd-subagent 不支持snmptrapd的agent子代理 # --disable-ipv6 不支持IPv6 # --disable-scripts 不需要安装mib2c等工具 # -enable-mini-agent 使用最小agent # --with-mib-modules="notification agentx" 添加 notification agentx模块 # --disable-embedded-perl 不支持嵌入式perl # --with-perl-modules 安装perl模块 # --with-default-snmp-version 指定默认使用版本 # --with--sys-location 指定设备位置 # --with-logfile 指定日志文件路径 # --with-persistent-directory 不变数据存储路径 ./configure --prefix=/home/lijun/net-snmp-5.9.3/out --disable-manuals --disable-snmptrapd-subagent --disable-ipv6 --disable-scripts --enable-mini-agent --with-mib-modules="notification agentx" --disable-embedded-perl --with-perl-modules --with-default-snmp-version="3" --with-sys-location="china" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"

运行配置脚本

[root@hecs-332420 net-snmp-5.9.3]# ./localBuild.sh checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out ... ... # 如果有" -Press return to continue- " 提示 说明配置的不完整 # 如果不需要可以直接按回车 # 最后出现以下内容就说明配置OK! Net-SNMP configuration summary: --------------------------------------------------------- SNMP Versions Supported: 1 2c 3 Building for: linux Net-SNMP Version: 5.9.3 Network transport support: Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase IPBase ... ... 3.3 编译安装

直接在当前源码路径下进行 make。

[root@hecs-332420 net-snmp-5.9.3]# make # 我这里出现了如下错误: ... ... Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /home/lijun/net-snmp-5.9.3/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3. BEGIN failed--compilation aborted at Makefile.PL line 3. # 这是因为缺少 ExtUtils/MakeMaker 包 # 直接安装即可 [root@hecs-332420 net-snmp-5.9.3]# yum -y install perl-ExtUtils-MakeMaker # 然后再重新编译 [root@hecs-332420 net-snmp-5.9.3]# make

因为我在上述的配置项中指定的安装目录是/home/lijun/net-snmp-5.9.3/out,然而实际上源码路径中是没有的out文件夹的,因此需要我自己创建out文件,再使用make install进行安装

[root@hecs-332420 net-snmp-5.9.3]# mkdir out && make install #安装后 在out文件夹下会有 bin include lib sbin share 5个文件夹 #测试是否可用(snmpd在 sbin目录下) [root@hecs-332420 net-snmp-5.9.3]# cd ./out/sbin [root@hecs-332420 sbin]# ./snmpd -v NET-SNMP version: 5.9.3 Web: http://www.net-snmp.org/ Email: [email protected] # 安装成功! 4. 配置snmpd.conf

启动snmpd代理程序需要指定我们的snmpd.conf配置文件,我们发现无论在源码中还是我们的out文件夹中是没有这个文件,但是在源码中给了一个示例配置文件EXAMPLE.conf,这里我们做一些修改即可。

[root@hecs-332420 net-snmp-5.9.3]# cp ./EXAMPLE.conf ./out/share/snmp/snmpd.conf [root@hecs-332420 net-snmp-5.9.3]# cd ./out/share/snmp [root@hecs-332420 net-snmp-5.9.3]# vi snmpd.conf # 对以下部分做一定修改即可 # # AGENT BEHAVIOUR # # Listen for connections from the local system only # agentAddress udp:127.0.0.1:161 # Listen for connections on all interfaces (both IPv4 *and* IPv6) #agentAddress udp:161,udp6:[::1]:161 # 上述只是指定了 本地访问 可以修改为 agentAddress udp:161 5.运行snmpd代理 # snmpd 运行参数 # -c FILE 指定文件为配置文件 # -C 不读取默认的配置文件(默认路径:(config search path: /home/lijun/net-snmp-5.9.3/out/etc/snmp:/home/lijun/net-snmp-5.9.3/out/share/snmp:/home/lijun/net-snmp-5.9.3/out/lib/snmp:/root/.snmp)) # -d dump接收和发送SNMP数据包 # -D TOKEN 对于给定的TOKEN(标志)打开调试信息 ( -Dmib_init) # -I [-]INITLIST 对于要初始化的MIB列表显示 # -M DIRLIST 指定MIB库的路径(默认路径:(default $HOME/.snmp/mibs:/home/lijun/net-snmp-5.9.3/out/share/snmp/mibs)) # -V 显示详细信息 # -Le 把日志信息输出到错误中 -Lo 输出到标准输出 -Lf file 把日志信息输出到 file文件中 # -Lf FILE 把错误信息输出到指定文件中 [root@hecs-332420 net-snmp-5.9.3]# cd ./out/sbin [root@hecs-332420 net-snmp-5.9.3]# ./snmpd -c ../share/snmp/snmpd.conf -f -Lo -C -d -M ../share/snmp/mibs/ ../share/snmp/snmpd.conf: line 90: Warning: Unknown token: proc. ../share/snmp/snmpd.conf: line 92: Warning: Unknown token: proc. ../share/snmp/snmpd.conf: line 94: Warning: Unknown token: proc. ../share/snmp/snmpd.conf: line 104: Warning: Unknown token: disk. ../share/snmp/snmpd.conf: line 105: Warning: Unknown token: disk. ../share/snmp/snmpd.conf: line 106: Warning: Unknown token: includeAllDisks. ../share/snmp/snmpd.conf: line 116: Warning: Unknown token: load. ../share/snmp/snmpd.conf: line 143: Warning: Unknown token: iquerySecName. ../share/snmp/snmpd.conf: line 146: Warning: Unknown token: defaultMonitors. ../share/snmp/snmpd.conf: line 148: Warning: Unknown token: linkUpDownNotifications. ../share/snmp/snmpd.conf: line 160: Warning: Unknown token: extend. ../share/snmp/snmpd.conf: line 161: Warning: Unknown token: extend-sh. ../share/snmp/snmpd.conf: line 193: Warning: Unknown token: master. Sending 44 bytes to UDP: [127.0.0.1]:162->[127.0.0.1]:37295 0000: 30 2A 02 01 00 04 06 70 75 62 6C 69 63 A4 1D 06 0*.....public... 0016: 0A 2B 06 01 04 01 BF 08 03 02 0A 40 04 C0 A8 00 .+.........@.... 0032: EB 02 01 00 02 01 00 43 01 01 30 00 .......C..0. NET-SNMP version 5.9.3 # 这儿就启动成功了 可以通过 netstate 查看 [root@hecs-332420 sbin]# netstat -ulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0:161 0.0.0.0:* 30970/./snmpd udp 0 0 127.0.0.1:37295 0.0.0.0:* 30970/./snmpd 6.测试snmpd

使用snmpget测试,查看是否能获取到我们想要的信息。

# -v 1|2c|3 specifies SNMP version to use # -c COMMUNITY set the community string [root@hecs-332420 net-snmp-5.9.3]# cd ./out/bin [root@hecs-332420 bin]# ./snmpget -v 2c -c public localhost sysUpTime.0 SNMPv2-MIB::sysUpTime.0 = Timeticks: (18927) 0:03:09.27 7. 完结


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有