1、首先从官网下载源码包,
http://www.net-snmp.org/download.html
脚本安装内容:
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install snmp" exit 1 fi cur_dir=$(pwd) if [ -f /usr/sbin/snmpd ]; then Echo_Red "You have installed SNMP!" echo -e "If you want to reinstall SNMP, please uninstall before you install." exit 1 fi clear echo "+------------------------------------------------------------------------+" echo "| A tool to auto-compile & install NET-SNMP on Linux |" echo "+------------------------------------------------------------------------+" tar -zxvf net-snmp-5.8.tar.gz cd net-snmp-5.8 echo `pwd` ./configure --prefix=/usr/local/net-snmp/ make make install if [ $? -ne 0 ]; then echo "failed" exit else echo "succeed" fi #添加环境变量 sed -i '$a\PATH=$PATH:/usr/local/net-snmp/sbin:/usr/local/net-snmp/bin' source /etc/profile snmpconf mv snmpd.conf /usr/local/net-snmp/share/snmp/ #snmpd添加到服务 sed -i 's#/usr/local/sbin/snmpd#/usr/local/net-snmp/sbin/snmpd#g' dist/snmpd-init.d sed -i 's#/usr/local/share/snmp/snmpd.conf#/usr/local/net-snmp/share/snmp/snmpd.conf#g' dist/snmpd-init.d cp dist/snmpd-init.d /etc/init.d/snmpd chkconfig --add snmpd chkconfig snmpd on #启动 systemctl start snmpd
安装过程,生成 snmpd.conf 会有交互,根据自己情况选择生成。
Comments (0)