SSH安装SNMP(监控宝测试通过)

2011年3月2日 | 分类: Linux | 标签: , , , , , , , , , ,

更新:2012.8.30到5.7.1版本及修改为服务启动。
使用SSH脚本安装给我的服务器添加了一个监控宝,环境:centos 5.5+net-snmp
当前最新的版本是net-snmp-5.7.1,代码这里下载snmp.sh

wget http://www.yishanhome.com/wp-content/uploads/2011/03/snmp.sh;sh snmp.sh

snmp.sh代码如下:

?Download snmp.sh
#!/bin/bash
printf "
####################################################
#                                                  #
# This is a Shell-Based tool of SNMP installation  #
# Author: yishan                                   #
# Website: http://www.yishanhome.com               #
#                                                  #
####################################################
"
  echo "Command is running, please wait....."
yum install -y gcc gcc-c++ openssl openssl-devel
myusername="yishanhome"
echo "Please Your UserName:"
read -p "(Default : yishanhome):" myusername
if [ "$myusername" = "" ]; then
	myusername="yishanhome"
fi
myuserpws="yishanpws"
echo "Please input myuserpws(Less than 8 characters):"
read -p "(Default UserPassword: yishanpws):" myuserpws
if [ "$myuserpws" = "" ]; then
	myuserpws="yishanpws"
fi
myip="60.195.249.83"
echo "Please input Authorized IP:"
read -p "(Default Authorized IP: 60.195.249.83):" myip
if [ "$myip" = "" ]; then
	myip="60.195.249.83"
fi
clear
wget http://voxel.dl.sourceforge.net/project/net-snmp/net-snmp/5.7.1/net-snmp-5.7.1.tar.gz
tar xzf net-snmp-5.7.1.tar.gz
cd net-snmp-5.7.1
./configure --prefix=/usr/local/snmp --with-mib-modules=ucd-snmp/diskio --with-default-snmp-version=3 --with-sys-contact=admin@example.com  --with-sys-location=Unknown  --with-logfile=/var/log/snmpd.log --with-persistent-directory=/var/net-snmp
make
make install
echo "rouser $myusername auth" >>/usr/local/snmp/share/snmp/snmpd.conf
echo "createUser $myusername MD5 $myuserpws" >>/usr/local/snmp/share/snmp/snmpd.conf
iptables -A INPUT -i eth0 -p udp -s $myip --dport 161 -j ACCEPT
cp dist/snmpd-init.d /etc/init.d/snmpd
sed -i 's/usr\/local\/sbin\/snmpd/usr\/local\/snmp\/sbin\/snmpd/g' /etc/init.d/snmpd
sed -i 's/usr\/local\/share\/snmp\/snmpd.conf/usr\/local\/snmp\/share\/snmp\/snmpd.conf/g' /etc/init.d/snmpd
chkconfig --level 345 snmpd on
service snmpd start
echo "Your Authorized UserName:$myusername"
echo "Your Authorized Password:$myuserpws"
echo "Your Authorized IP:$myip"

default version of-snmp-version(3): 3(在这里版本通常有三种形式:1,2c,3)
Systemcontact information(配置该设备的联系信息):admin@yishanhome.com(也可以是邮箱地址)
System location (该系统设备的地理位置):BEIJING-China
Location to write logfile (日志文件位置): /var/log/snmpd.log
Location to Write persistent(数据存储目录): /var/net-snmp
查看snmp进程号:

ps aux |grep snmpd

如果想关掉则杀掉进程号:

kill -9 snmpd 进程号

参考文章:http://wiki.jiankongbao.com/doku.php/%E6%96%87%E6%A1%A3:%E5%AE%89%E5%85%A8%E6%8C%87%E5%BC%95#linux_snmp
net-snmp到这里下载最新版本http://sourceforge.net/projects/net-snmp/files/net-snmp/

修改v3密码

查询snmp ID

ps -ef

kill结束snmp
删除原有的snmp配置文件,

rm -f /usr/local/snmp/share/snmp/snmpd.conf
rm -f /var/net-snmp/snmpd.conf

重新建立配置文件

echo "rouser 新的用户名 auth" >>/usr/local/snmp/share/snmp/snmpd.conf
echo "createUser 新的用户名 MD5 新的密码" >>/var/net-snmp/snmpd.conf
/usr/local/snmp/sbin/snmpd
目前还没有任何评论.

返回顶部