Linux Shell编程:SNMP服务安装

Linux下实现SNMP服务的一键安装配置,具体实现过程如下所示(CentOS 7操作系统)。

(1)角色判断

判断当前登录的用时是否为root用户,防止安装软件时不能进行安装。如果不是root用户将退出脚本执行,否则将继续进行脚本执行。

#!/bin/bash

#进行一键安装SNMP创建Shell脚本

#

#判断当前用户是否为root

if [ "$(id -u)" != "0" ]

then

       echo "This Shell must be run as root" 1>&2

       exit 1

fi

(2)检查软件是否安装

检查SNMP服务需要的安装包是否已经安装,如果没有安装通过Shell脚本直接进行安装。

#检查系统是否存在yum命令

YUM_CMD=`whereis yum | awk '{print $2}'`

if [ "$YUM_CMD" != "" ]

then

       #检测是否安装gcc

       cmd=`rpm -q gcc | grep -v "not installed"`

       if [ "${cmd}x" = "x" ]

       then

              echo "install gcc start >>>"

              yum install -y gcc 1>/dev/null 2>&1

       else

              echo "not need install gcc"

       fi

       cmd1=`rpm -q net-snmp | grep -v "not installed"`

       if [ "${cmd1}x" = "x" ]

       then

              echo "install net-snmp start >>>"

              yum install -y net-snmp 1>/dev/null 2>&1

       else

              echo "not need install net-snmp"

       fi

       cmd2=`rpm -q net-snmp-utils | grep -v "not installed"`

       if [ "${cmd2}x" = "x" ]

       then

              echo "install net-snmp-utils start >>>"

              yum install -y net-snmp-utils 1>/dev/null 2>&1

       else

              echo "not need install net-snmp-utils"

       fi

else

       echo "Don't have yum"

       exit 1

fi

(3)修改配置文件

修改SNMP服务的配置文件,自定义SNMP的共同体名称以及SNMP结果视图节点,具体如下所示。

SNMPConfName="/etc/snmp/snmpd.conf"

if [ -f ${SNMPConfName} ]

then

       #配置SNMP服务,将原始的SNMP配置文件进行重命名

       echo "config file start >>>"

       mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

       #创建配置文件赋予权限

       touch ${SNMPConfName}

       chmod 777 ${SNMPConfName}

       echo "##" >> ${SNMPConfName}

       #配置SNMP配置文件内容

       echo "com2sec      mynetwork    default    public" >> ${SNMPConfName}

       echo "group   MyROGroup   v1   mynetwork" >> ${SNMPConfName}

       echo "group   MyROGroup   v2c  mynetwork" >> ${SNMPConfName}

       echo "group   MyROGroup   usm mynetwork" >> ${SNMPConfName}

       echo "view     systemview    included .1.3.6.1.2.1.1" >> ${SNMPConfName}

       echo "view     systemview    included .1.3.6.1.2.1.25.1.1" >> ${SNMPConfName}

       echo "view     all    included .1" >> ${SNMPConfName}

       echo "access  MyROGroup   ""    any  noauth   0     all    all    none" >> ${SNMPConfName}

       echo "dontLogTCPWrappersConnects yes" >> ${SNMPConfName}

       echo "agentaddress 161" >> ${SNMPConfName}

else

       echo "Config File not exit"

fi

(4)服务与安全配置

启动SNMP服务,并设置SNMP自启动;配置防火墙允许161/udp端口进行访问,具体配置如下。

#服务管理与安全配置

if [ -f ${SNMPConfName} ]

then

       #服务启动

       echo "Service snmpd start"

       systemctl restart snmpd

       systemctl enable snmpd

      

       #防火墙配置

       echo "firewall config start"

       firewall-cmd --zone=public --add-port=161/udp --permanent

       firewall-cmd --reload

fi

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux环境下的snmp测试脚本, Installing SNMPv2C Agent Conformance Test Package 2008/04/08 IPv6 Promotion Council Terminology =========== Tester Node (TN) A tester node for the conformance tests. Node Under Test (NUT) A testee node for the conformance tests. Network Under Test The network where the conformance tests are executed. Tester Interface The network interface of TN hooked up to the Network Under Test. Interface Under Test The network interface of NUT hooked up to the Network Under Test. Prerequisites ============= Prerequisites for TN: - The package supports FreeBSD 6.0-RELEASE or higher version. - The package can also coexist with FreeBSD version of KAME. Installing the package onto TN ============================== 0. Before Starting (A) You need to install following softwares. - Perl (Required version : 5.8.7 or higher) - Net-SNMP (Required version : 5.3.1 or higher) *** You can download it from the following URL: http://net-snmp.sourceforge.net/ - v6eval (Required version : 3.0.11 or higher) Please refer to 00README.v6eval in "v6eval" for more information. *** You can download it from the following URL: http://www.tahi.org/release/ - koi (Required version : 1.1.1 or higher) Please refer to README file in "koi" package for more information. *** You can download it from the following URL: http://www.tahi.org/release/ 1. Extracting ct package % tar zxvf ct-snmpv2c-ag-X.X.tar.gz 2. Copying ct package Copy ct directory to any directory you like. % cp -pR $ORGDIR/ct-snmpv2c-ag-X.X $SOMEWHERE/ct-snmpv2c-ag-X.X % chmod -R +w $SOMEWHERE/ct-snmpv2c-ag-X.X 4. Setup ct environment % (enable TN's ipv6 capibility) % cd $SOMEWHERE/ct-snmpv2c-ag-X.X % edit config.txt % make test [End of INSTALL]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值