Redhat7 installation and configuration NET-SNMP - Method 2 (tar package compilation and installation)

1. Version description:

Platform: x86
OS: Red Hat Enterprise Linux Server release 7.6 (Maipo)
gcc: 4.8.5 (comes with the system)
net-snmp: 5.7.3

2. Preparation

2.1 Confirm gcc environment

Installation through the net-snmp compilation package requires the system to install the gcc environment in advance.

# find / -name gcc
/usr/bin/gcc
/usr/lib/gcc
/usr/libexec/gcc

# /usr/bin/gcc -v
使用内建 specs。
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

2.2 net-snmp download

Download address: http://www.net-snmp.org/
Click download to select the appropriate version to download locally.

3. Upload net-snmp and decompress it

# gunzip net-snmp-5.7.3.tar.gz 
# tar -xvf net-snmp-5.7.3.tar 
# cd net-snmp-5.7.3

4. Compile and install net-snmp

# ./configure		#一路按回车,默认值确认

# make && make install
# echo $?			#如果返回值是0,就是执行成功;如果是返回值是0以外的值,就是失败。

5. Copy the configuration file

# cp /tmp/net-snmp-5.7.3/python/netsnmp/tests/snmpd.conf /usr/local/share/snmp/snmpd.conf

6. Modify configuration file

# vim /usr/local/share/snmp/snmpd.conf

将:
#       sec.name  source          community
com2sec local     localhost      public
com2sec mynetwork 192.168.1.0/24    public

改为:
#       sec.name  source          community
com2sec local     localhost      cmsnmp
com2sec mynetwork 192.168.56.0/24    cmsnmp

PS:
(1) cmsnmp is the community name, which can be defined by yourself
(2) 192.168.56.0/24 is the network segment of the snmp server, or it can be the IP address of the server.
(3) The corresponding configuration files will be different between installing through compilation and installing net-snmp using yum, so be sure to check carefully.

7. Start net-snmp

# /usr/local/sbin/snmpd -v		#查看版本
NET-SNMP version:  5.7.3
Web:               http://www.net-snmp.org/
Email:             [email protected]

# /usr/local/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf			#启动程序

8. Local testing

snmpget -v 1 -c cmsnmp localhost sysUpTime.0			#此处localhost也可以用本地IP代替
snmpwalk -v 2c -c cmsnmp -m ALL localhost .1.3 | more	#此处localhost也可以用本地IP代替

9. snmp server side test

a) cmsnmp is the community name
b) 10.168.1.129 is the client IP address

snmpwalk -v 2c -c cmsnmp 10.168.1.129 .1.3.6.1.2.1.25.2.2  			#取得系统总内存
snmpwalk -v 2c -c cmsnmp 10.168.1.129 hrSystemNumUsers  			#取得系统用户数
snmpwalk -v 2c -c cmsnmp 10.168.1.129 .1.3.6.1.2.1.4.20    			#取得IP信息
snmpwalk -v 2c -c cmsnmp 10.168.1.129 system   						#查看系统信息
snmpwalk -v 2c -c cmsnmp 10.168.1.129 ifDescr 						#获取网卡信息

If executed, the output information is normal, indicating that there is no problem with the configuration.
If the following information is displayed:

Timeout: No Response from 10.168.1.129

You need to consider whether it is caused by the firewall settings.

10. Firewall settings

10.1 The firewall can be turned off in the business environment

# systemctl stop firewalld			#关闭防火墙
# systemctl status firewalld		#查看防火墙状态

10.2 The firewall cannot be turned off in the business environment

If the business environment cannot close the firewall, then we can set up port 161 to allow connections from the snmp server:

# systemctl start firewalld			#打开防火墙
# systemctl status firewalld		#查看防火墙状态
# firewall-cmd --zone=public --add-port=161/udp --permanent		
									#开放161端口															
									#--permanent的作用是使设置永久生效,不加的话机器重启之后失效
# firewall-cmd --reload				#配置修改后重新加载
# firewall-cmd --zone=public --query-port=161/udp		
									#确认配置是否生效:输出yes表示生效

Supongo que te gusta

Origin blog.csdn.net/m0_37862262/article/details/107244093
Recomendado
Clasificación