Linux下安装net-snmp
程序员文章站
2022-07-15 15:08:34
...
Linux下root权限安装net-snmp5.7.3
1.#tar zxvf net-snmp-5.7.3.tar.gz //解压
2.#cd net-snmp-5.7.3
3.#./configure --prefix=/usr/local/snmp //配置
配置中会出现这样的提示:
default version of-snmp-version: 2
Systemcontact information(配置设备的联系人):jackhe
System location(设备的位置):Shenzhen
下面两个默认就行
Location to write logfile(日志文件位置):/var/log/snmpd.log
Location to Write persistent(数据存储目录): /var/net-netsnmp
4.#make && make install //编译并安装
5.#cp EXAMPLE.conf /usr/loca/share/snmp/snmpd.conf
6.#vi snmpd.conf
添加"agentAddress udp:161"行配置项(5.7.3版本已有该项)
解除 trap2sink localhost public 注释使改行生效 发送v2trap
【rocommunity public default -V systemonly】把 -V systemonly去掉,这是设置访问权限的,去掉后能访问全部
#ps aux | grep snmp | grep -v grep |awk '{print $2}'| xargs kill"关闭snmp的相关服务
#netstat -an |grep 161"查看snmp的服务是否启动
#/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf 启动snmp服务:
#使用"iptables –L –n"查看当前iptables规则
#"iptables -I INPUT -p udp --dport 161 -j ACCEPT"命令添加UDP 161端口到iptables防火墙中,
然后执行"iptables save"命令保存防火墙的更改
7. #vi /etc/rc.local //设置netsnmp自启动,末尾加上&
/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf &
8. #vi /etc/profile //设置环境变量,在export命令前加上
PATH=/usr/local/bin:/usr/local/sbin:$PATH
9. #/usr/local/sbin/snmpd -d //自启动服务,看是否启动
#netstat -an |grep 161
#ps -ef|grep snmpd //查看snmpd的进程id
#kill -9 xx
10.测试
#/usr/local/snmp/bin/snmpwalk -v 2c -c public localhost if
#/usr/local/snmp/bin/snmpwalk -v 2c -c public 192.168.1.10 if
#/usr/local/snmp/bin/snmpget -v 2c -c public localhost 1.3.6.1.2.1.1.1.0
二、卸载SNMP
如果安装后想卸载SNMP,可以执行"make uninstall"命令,卸载步骤如下:
1、使用"netstat -an |grep 161"查看snmp服务是否启动
2、如果已经启动就使用命令"ps aux | grep snmp | grep -v grep |awk '{print $2}'| xargs kill"关闭snmp的相关服务
3、进入SNMP源码目录(net-snmp-5.7.3)
4、执行"make uninstall"命令卸载SNMP
5、删除/usr/local下的snmp目录以及snmp目录里面的所有文件,usr/local/snmp是SNMP的安装路径
#!/bin/sh
#kill snmpd pid
pidlist=`ps -ef|grep snmpd | grep -v "grep"|awk '{print $2}'`
echo "snmpd Id list :$pidlist"
if [ "$pidlist" = "" ]
then
echo "no snmpd pid alive"
else
for pid in ${pidlist}
{
kill -9 $pid
echo "KILL $pid:"
echo "service stop success"
}
fi
#start snmpd
echo "loading snmpd.conf"
/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf
echo "start snmpd service complete"
1.#tar zxvf net-snmp-5.7.3.tar.gz //解压
2.#cd net-snmp-5.7.3
3.#./configure --prefix=/usr/local/snmp //配置
配置中会出现这样的提示:
default version of-snmp-version: 2
Systemcontact information(配置设备的联系人):jackhe
System location(设备的位置):Shenzhen
下面两个默认就行
Location to write logfile(日志文件位置):/var/log/snmpd.log
Location to Write persistent(数据存储目录): /var/net-netsnmp
4.#make && make install //编译并安装
5.#cp EXAMPLE.conf /usr/loca/share/snmp/snmpd.conf
6.#vi snmpd.conf
添加"agentAddress udp:161"行配置项(5.7.3版本已有该项)
解除 trap2sink localhost public 注释使改行生效 发送v2trap
【rocommunity public default -V systemonly】把 -V systemonly去掉,这是设置访问权限的,去掉后能访问全部
#ps aux | grep snmp | grep -v grep |awk '{print $2}'| xargs kill"关闭snmp的相关服务
#netstat -an |grep 161"查看snmp的服务是否启动
#/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf 启动snmp服务:
#使用"iptables –L –n"查看当前iptables规则
#"iptables -I INPUT -p udp --dport 161 -j ACCEPT"命令添加UDP 161端口到iptables防火墙中,
然后执行"iptables save"命令保存防火墙的更改
7. #vi /etc/rc.local //设置netsnmp自启动,末尾加上&
/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf &
8. #vi /etc/profile //设置环境变量,在export命令前加上
PATH=/usr/local/bin:/usr/local/sbin:$PATH
9. #/usr/local/sbin/snmpd -d //自启动服务,看是否启动
#netstat -an |grep 161
#ps -ef|grep snmpd //查看snmpd的进程id
#kill -9 xx
10.测试
#/usr/local/snmp/bin/snmpwalk -v 2c -c public localhost if
#/usr/local/snmp/bin/snmpwalk -v 2c -c public 192.168.1.10 if
#/usr/local/snmp/bin/snmpget -v 2c -c public localhost 1.3.6.1.2.1.1.1.0
二、卸载SNMP
如果安装后想卸载SNMP,可以执行"make uninstall"命令,卸载步骤如下:
1、使用"netstat -an |grep 161"查看snmp服务是否启动
2、如果已经启动就使用命令"ps aux | grep snmp | grep -v grep |awk '{print $2}'| xargs kill"关闭snmp的相关服务
3、进入SNMP源码目录(net-snmp-5.7.3)
4、执行"make uninstall"命令卸载SNMP
5、删除/usr/local下的snmp目录以及snmp目录里面的所有文件,usr/local/snmp是SNMP的安装路径
#!/bin/sh
#kill snmpd pid
pidlist=`ps -ef|grep snmpd | grep -v "grep"|awk '{print $2}'`
echo "snmpd Id list :$pidlist"
if [ "$pidlist" = "" ]
then
echo "no snmpd pid alive"
else
for pid in ${pidlist}
{
kill -9 $pid
echo "KILL $pid:"
echo "service stop success"
}
fi
#start snmpd
echo "loading snmpd.conf"
/usr/local/snmp/sbin/snmpd -c /usr/local/share/snmp/snmpd.conf
echo "start snmpd service complete"
上一篇: snmp trap
下一篇: Hadoop分布式集群的搭建