ubuntu snmp Installation and Configuration

0.5 Description

       

        A complete tutorial on, then again, the country is either incomplete or too old, and not thinking clearly, so here write an entire to share with you. 

        Although can be done by executing specific commands to monitor Linux host, but then compared to obtain information via snmp Linux hosts will be more relaxed way simpler, but in the configuration before use may need to spend a little more time , but it is definitely worth it! And if you need to develop monitoring software Linux host, then use snmp is definitely the first choice, after all, it is too much information available!

        Content behind it to share in the Ubuntu install, configure, and start the whole process snmp remote testing.

        Operating system used here is: Ubuntu 15.10

 

 

1. Install

 

        We need to install the following three software packages:

snmpd: snmp server software

snmp: snmp client software

snmp-mibs-downloader: download the update to the local mib library software

        While the final I will use another host for remote testing, but at the beginning or end of the service but also the snmp client software to install, and easy to do some basic tests.

        Execute the following command to install three software:

ubuntu @ leaf: ~ $ sudo apt -get install snmpd snmp snmp-mibs-downloader
        should be noted that, in the process of installing snmp-mibs-downloader, the program will help us to automatically download mib library, and save it in / usr / share / mibs directory:

Leaf @ Ubuntu: / usr / report this content share / LS $ mibs
the IANA ietf
        if some found no directory or file, you can also manually execute the following command after installing snmp-mibs-downloader to download mib library:

ubuntu @ leaf: ~ $ sudo download -mibs
        have a lot of output.

        In this case, the first step in the installation work is done.

 

 

2. Configure

 

        In fact, snmpd After installing the software, the system is automatically turned on this service to our:

Leaf @ Ubuntu: ~ $ sudo the snmpd Service Status
 * IS the snmpd running
        before you start configuration, let's do some simple tests to see whether the normal service:

Leaf @ Ubuntu: ~ $ snmpwalk -v -c public. 2C localhost 1.3.6.1.2.1.1.1
iso.3.6.1.2.1.1.1.0 = STRING: "Linux 4.2.0-34-the Generic Leaf # 39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 "
        no problem, messages will be returned, then the rest is directly a variety of configurations, but before you start configuring it back up configuration files:

Leaf @ Ubuntu: ~ $ cd / etc / snmp
Ubuntu @ Leaf: / etc / snmp $ sudo cp the snmpd.conf snmpd.conf.ori
Ubuntu @ Leaf: / etc / snmp $ LS * the snmpd
the snmpd.conf snmpd.conf.ori
        of course, to note that, talking about the back, all using SNMPv2, in fact, already meet our needs.

 

(1) Configuration node

        /Etc/snmp/snmpd.conf modify the file, probably in line 45, the following two lines commented:

systemonly included .1.3.6.1.2.1.1 View
View systemonly included .1.3.6.1.2.1.25.1
        add the following line:

view systemonly included .1
        In this case, we can get more information node, because if you do not, the information we can get, just comment out the information above two node contains.

        After the changes, restart the snmp service, and then use the command to look at:

Leaf @ Ubuntu: / etc / snmp $ sudo restart the snmpd Service
xpleaf @ Leaf: / etc / snmp $ snmpwalk -v -c public. 2C localhost .1.3.6.1.4.1.2021.4.3.0
iso.3.6.1.4.1.2021.4.3. INTEGER = 0: 1,950,716
        the OK, no problem! But note that here is a node .1.3.6.1.4.1.2021.4.3.0 represented the total amount of swap space LInux host, and output 1950716, it shows the total amount of swap space on our host is probably about 2GB.

 

(2) Configuration of MIB

        While the above may normally get the information we want, but the output is very intuitive, when we look at the MIB to configure it, but it needs to be noted that this configuration is the configuration of the client software (or just now I operate on the same server host).

        /Etc/snmp/snmp.conf modify the configuration file, comment out the following line:

mibs:
        then restart the snmp service, and then observe the command:

Leaf @ Ubuntu: / etc / snmp $ sudo Service the snmpd restart
Ubuntu @ Leaf: / etc / snmp $ snmpwalk -v -c public. 2C localhost .1.3.6.1.4.1.2021.4.3.0
UCD-the SNMP-MIB :: memTotalSwap.0 = INTEGER: 1950716 kB
        can be seen, the present output is very intuitive! It follows, in fact, when we get relevant information node, you can enter numbers that do not have a long list:

Leaf @ Ubuntu: / etc / SNMP the snmpwalk -v $ 2C -C public localhost memTotalSwap.0
the UCD-the SNMP-memTotalSwap.0 the MIB :: = INTEGER: 1950716 kB
Ubuntu Leaf @: / etc / SNMP the snmpwalk -v $ 2C -C localhost memTotalReal.0 public
UCD-memTotalReal.0 the sNMP-MIB :: = INTEGER: 8093524 kB
        fact, after this, you will be able to discover how to use the snmp there is a strong! About the MIB node values come from, and do not need to remember, you can find online, you can also see my summary of the blog post: "linux snmp common node value" can also be found on my blog: http: //xpleaf.blog.51cto.com. Of course, if you want to know what it means, why should this definition, then I suggest you go to the relevant professional books, a good recommendation is "TCP / IP Detailed Volume 1: The agreement" if the network infrastructure is not good, you can go to learn about.

        Note that, just now configure and test the server side, in fact, this step of the operation should be in the client (on another host) accomplished here for convenience only.

 

(3) Configuration Community

        The so-called community, understand it as a password on the line, in front of us when using the snmpwalk command to obtain information about the host, there is a parameter -c public, in fact, specify this community for the public, which is the default configuration, of course, in practice, we can not use the default value, so it needs to be changed a bit.

        Modify the configuration file /etc/snmp/snmpd.conf, probably in line 52, the following two lines:

-V systemonly public default rocommunity
rocommunity6 public default -V systemonly
        amended as follows:

xpleaf123 default -V systemonly rocommunity
rocommunity6 xpleaf123 default -V systemonly
        this revised to put the Community xpleaf123, and restart the snmp service, look through the command:

Leaf @ Ubuntu: / etc / snmp $ snmpwalk -v -c public. 2C localhost memTotalReal.0
Timeout: No the Response from localhost
Ubuntu @ Leaf: / etc / snmp $ snmpwalk -v -c. 2C xpleaf123 localhost memTotalReal.0
UCD-SNMP- MIB :: memTotalReal.0 = INTEGER: 8093524 kB
        can be seen for the first time access to information is not successful, because we've updated the community, the old public will no longer be used, otherwise the authentication fails can not get snmp host information provided.

 

(4) to allow remote access host

        By default, snmp service is only open to local, it is unable to obtain information about the snmp remote host via:

Leaf @ Ubuntu: / etc / snmp $ sudo netstat -antup | grep 161  
udp 0 0 127.0.0.1:161 0.0.0.0:* 11615 / the snmpd
        can see, the only open port 161 (port number 161 of the machine is snmp services port number), we need to change it, let snmp service opening.

        /Etc/snmp/snmpd.conf modify the configuration file, probably in 15 lines, comment out the following line:

agentAddress udp: 127.0.0.1: 161
        at the same time remove the comment below this line:

#agentAddress udp: 161, udp6: [ :: 1]: 161
        to restart the snmp service, and then observe the command:

Leaf @ Ubuntu: / etc / snmp $ sudo netstat -antup | grep 161
udp 0 0 0.0.0.0:161 0.0.0.0:* 11656 / the snmpd     
udp6 :: 0 0 1: 161 ::: * 11656 / the snmpd
        can see services have been opened up, and supports both IPv4 and IPv6.

        After this, we will be able to test the remote host.

 

 

3. Start

 

        In fact, we have been operating in front of the start snmp service, but here is to ensure that it:

ubuntu@leaf:~$ sudo service snmpd start
ubuntu@leaf:~$ sudo netstat -antup | grep 161
udp        0      0 0.0.0.0:161             0.0.0.0:*                           11656/snmpd     
udp6       0      0 ::1:161                 :::*                                11656/snmpd

 


4. (remote) test

 

        In the tests we have done locally on the server, and there is no problem, here we have to do is to test the remote host.

        I was on another remote host operating system is Ubuntu 15.04, and has been installed snmp mib database client software and download software, configure the MIB database, the following direct remote testing:

Leaf @ xpleaf: ~ -C $ 2C xpleaf123 the snmpwalk -v * 115.159 * memTotalSwap.0..
the UCD-the SNMP-memTotalSwap.0 the MIB :: = INTEGER: 1,950,716 kB
xpleaf Leaf @: ~ $ 115.159 xpleaf123 the snmpwalk -v 2C -C .. * * memTotalReal.0
the UCD-the SNMP-memTotalReal.0 the MIB :: = INTEGER: 8,093,524 kB
xpleaf Leaf @:.. ~ -C $ 2C xpleaf123 the snmpwalk -v * 115.159 * .1.3.6.1.4.1.2021.9.1.6 .1
UCD-dskTotal.1 the SNMP-MIB :: = INTEGER: 8123832
        can be seen, the test is no problem! And the values of the previous acquisition are obtained as the local server.

        Of course, if you find that still can not get, then you need to think about on the host server's firewall settings have no problem.
----------------
Disclaimer: This article is the original article CSDN bloggers "xpleaf", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/xpleaf/article/details/51100725

Guess you like

Origin www.cnblogs.com/alanjl/p/11685064.html