0. Description
About a complete tutorial, or that sentence, the domestic is either incomplete, or too old, and the idea is not clear, so here to write a complete for everyone to share.
While the monitoring of Linux hosts can be done by executing specific commands, it is easier to get the Linux host's information by SNMP than after, but it is definitely worth the time it takes to configure the configuration before using it. And if you need to develop a Linux host monitoring software, that use of SNMP is definitely the first choice, after all, it can get too much information!
Here's what's behind to share the complete process of installing, configuring, starting SNMP, and remote testing on Ubuntu .
The operating system used here is:Ubuntu 15.10
1. Installation
We need to install the following three packages:
-
snmpd: SNMP server-side software
-
SNMP: SNMP client software
-
snmp-mibs-downloader: Software to download updates to the local MIB library
Although in the end I will use another host for remote testing, but at the beginning, or on the server also put the SNMP client software installed, easy to do some basic testing.
Execute the following command to install the three software:
[Email protected]:~$ sudo apt-get install snmpd SNMP snmp-mibs-downloader
It is important to note that during the installation of Snmp-mibs-downloader, the program will automatically download the MIB library and save it in the/usr/share/mibs directory:
[Email protected]:/usr/share/mibs$ Lsiana IETF
If you find that there are no directories or files, you can also manually execute the following command to download the MIB library after installing Snmp-mibs-downloader:
[Email protected]:~$ sudo download-mibs
There will be a lot of output information.
In this case, the first step of installation work is completed.
2. Configuration
In fact, after the installation of SNMPD software, the system is for us to automatically open the service:
[Email protected]:~$ sudo service snmpd status * SNMPD is running
Before starting the configuration, let's start with some simple tests to see if the service is working:
[Email protected]:~$ snmpwalk-v 2c-c public localhost 1.3.6.1.2.1.1.1iso.3.6.1.2.1.1.1.0 = STRING: "Linux leaf 4.2.0-34- Generic #39-ubuntu SMP Thu Mar 22:13:01 UTC x86_64 "
No problem, there is information to return, then the next direct configuration, but before the start of the configuration backup configuration files:
[Email protected]:~$ cd/etc/snmp[email protected]:/etc/snmp$ sudo cp snmpd.conf snmpd.conf.ori[email protected]:/etc/ snmp$ ls snmpd*snmpd.conf Snmpd.conf.ori
Of course, it should be noted that the following, the use of SNMPv2, in fact, this has been able to meet our needs.
(1) Configuration node
Modify the/etc/snmp/snmpd.conf file, approximately 45 lines, and comment out the following two lines:
View systemonly included. 1.3.6.1.2.1.1view systemonly included. 1.3.6.1.2.1.25.1
Add the following line:
View systemonly included. 1
In this way, we can get more node information, because if we don't, we can that is just the information contained in the above two commented-out nodes.
After modifying, restart the SNMP service, and then use the command to observe:
[Email protected]:/etc/snmp$ sudo service snmpd restart[email protected]:/etc/snmp$ snmpwalk-v 2c-c public localhost. 1. 3.6.1.4.1.2021.4.3.0iso.3.6.1.4.1.2021.4.3.0 = integer:1950716
OK, no problem! But it's important to note that here. 1.3.6.1.4.1.2021.4.3.0 represents a node for the total amount of swap space for a Linux host, and output 1950716 indicates that the total amount of swap space on our hosts is about 2GB.
(2) Configuring the MIB Library
Although the above can normally we want, but the output is not intuitive, then we can configure the MIB library, but it should be noted that this configuration is the configuration of the client software (but now still on the same server host on my operation).
Modify the/etc/snmp/snmp.conf configuration file to comment out the following line:
MIBs:
Then restart the SNMP service and observe with the command:
[Email protected]:/etc/snmp$ sudo service snmpd restart[email protected]:/etc/snmp$ snmpwalk-v 2c-c public localhost. 1. 3.6.1.4.1.2021.4.3.0ucd-snmp-mib::memtotalswap.0 = integer:1950716 KB
As you can see, now the output is very intuitive! Then, in fact, when we get the relevant node information, we can also not enter that long string of numbers:
[Email protected]:/etc/snmp$ snmpwalk-v 2c-c public localhost memtotalswap.0ucd-snmp-mib::memtotalswap.0 = integer:195 0716 kb[email protected]:/etc/snmp$ snmpwalk-v 2c-c public localhost memtotalreal.0ucd-snmp-mib::memtotalreal.0 = INTEG er:8093524 KB
In fact, you'll be able to find out how powerful it is to use SNMP! About the value of the node of the MIB library from where, do not need to remember, you can find on the Internet, you can also see my summary of a 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 this definition, then I suggest you go to see the relevant professional books, a good recommendation is "TCP/IP Detailed Volume 1: agreement", if the network is not very good, you can also learn.
It is important to note that it is now only configured and tested on the server side, in fact this step should be done on the client (another host), here is just for convenience.
(3) Configure the Community
In fact, the so-called community, it is understood as a password on the line, before we use the Snmpwalk command to of the host, there is a-c public parameter, in fact, it is specified this community for public, this is the default configuration, of course, in practice, we can not use the default value, So it needs to be modified.
Modify the configuration file/etc/snmp/snmpd.conf, about 52 lines, will be the following two lines:
Rocommunity public default-v systemonlyrocommunity6 public default-v systemonly
Modified to:
Rocommunity xpleaf123 default-v systemonlyrocommunity6 xpleaf123 default-v systemonly
So here we change the community to xpleaf123, restart the SNMP service, and take a look at the command:
[Email protected]:/etc/snmp$ snmpwalk-v 2c-c public localhost memtotalreal.0timeout:no Response from Localhost[email PR otected]:/etc/snmp$ snmpwalk-v 2c-c xpleaf123 localhost memtotalreal.0ucd-snmp-mib::memtotalreal.0 = integer:8093524 Kb
You can see that the first fetch was unsuccessful because we have updated the community, the old public will no longer be able to use it, or the authentication fails to obtain the host information provided by SNMP.
(4) Allow remote host access
By default, the SNMP service is only turned on locally, and it is not possible to obtain SNMP information for that host remotely:
[email protected]:/etc/snmp$ sudo netstat-antup | grep 161 UDP 0 0 127.0.0.1:161 0.0.0.0:* 11615/snmpd
As you can see, port 161 is only open to native (the 161 port number is the port number of the SNMP service) and we need to modify it to open the SNMP service.
Modify the/etc/snmp/snmpd.conf configuration file, approximately 15 lines, and comment out the following line:
Agentaddress udp:127.0.0.1:161
Also remove the comment from the following line:
#agentAddress udp:161,udp6:[::1]:161
Restart the SNMP service, and then observe through the command:
[email protected]:/etc/snmp$ sudo netstat -antup | grep 161udp 0 0 0.0.0.0:161 0.0.0.0: * 11656/snmpd udp6 0 0 ::1:161 :::*            11656/SNMPD
You can see that the service is open and supports both IPV4 and IPV6.
After that, we can test it on the remote host.
3. Start
In fact, the previous operation we have been starting the SNMP service, but here is to ensure that:
[Email protected]:~$ sudo service snmpd start[email protected]:~$ sudo netstat-antup | grep 161udp 0 0 0.0.0.0:161 0.0.0.0:* 11656/snmpd udp6 0 0:: 1:161:::* 11656/snmpd
4. (remote) test
At the server local we have done the test, and no problem, the next thing we want to do is to test the remote host.
My other remote host operating system is also Ubuntu 15.04, and has installed the SNMP client software and MIB library download software, while configuring the MIB library, the following direct remote testing:
[Email protected]:~$ snmpwalk-v 2c-c xpleaf123 115.159.*.* memtotalswap.0ucd-snmp-mib::memtotalswap.0 = integer:195071 6 Kb[email protected]:~$ snmpwalk-v 2c-c xpleaf123 115.159.*.* memtotalreal.0ucd-snmp-mib::memtotalreal.0 = integer:809 3524 kb[email protected]:~$ snmpwalk-v 2c-c xpleaf123 115.159.*.*. 1.3.6.1.4.1.2021.9.1.6.1ucd-snmp-mib::d SKTOTAL.1 = I nteger:8123832
As you can see, the test is absolutely no problem! and gets the same value as the server that was previously available locally.
Of course, if you find that you can not get it, then you need to consider the server's host on the firewall settings have no problem.
5. What's the use?
If you have a background development language (such as Python), and then your front-end base is good (HTML, JS, jquery, Bootstrap, Ajax, etc.), based on the basis of SNMP, then you can fully develop a Linux host monitoring host, It's not hard, it's complicated how you need to deal with your data, and that's something that needs to be looked at by everyone or every company.
Bo Master at present himself is doing related monitoring software development, but monitoring is not a Linux host, but other network equipment, although also a bit small complex, but as long as the technical thinking is right, then everything is no problem.
Because the feeling of SNMP for most of the friends should be very useful, so write this article to share, although only for the Ubuntu
But on other Linux distributions, the belief is similar. Or that sentence, hoping to help the needy friends.
This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1757333
Complete process of SNMP installation, configuration, startup, and remote testing on Ubuntu