MRTG Server Setup (monitor network traffic)
[Date: 2012-07-03] |
Source: Linux Community Split_two |
[Font: Big Small] |
"Experimental Environment"
Monitor: Red Hat Linux 5.3 ip:10.10.10.2/24 the operating window of the monitor is a green font
Monitored by: Red Hat Linux 5.3 ip:10.10.10.10/24 operation as white font
"Experimental Purpose"
Monitor network traffic
"Experimental Steps"
1, the monitoring machine needs to install 3 software packages, NET-SNMP (Install a Network Management Protocol), MRTG (this monitoring software), httpd (because the need to display the Web page, so you must install HTTP), of course, you can choose RPM installation or Yum installation, the following demo is installed with Yum. All three of them are necessary to install ha!
Mount the optical drive and install the NET-SNMP package.
Installing the MRTG Package
Installing the HTTPD Package
2, after installation can be installed on the monitoring machine SNMP, I want to monitor a Linux server. Also installs the NET-SNMP package
Edit/etc/snmp/snmpd.conf, to modify three positions
Modify SystemView to Mib2
Remove this line # comment
Add a community name on line No. 395 rocommunity 123456 Adds a read-only attribute to the community name password is 123456
3. Restart the SNMP service on the monitored machine, the default is not started, so the time to stop is a failure
4, the next step in the monitoring machine configuration
First build a MRTG working directory, then generate MRTG configuration file, the host is monitored 10.10.10.10 His community name password is 123456
Modify the above generated/var/www/html/mrtg/mrtg.cfg configuration file, without modifying the previous
Remove the WORKDIR:/HOME/HTTP/MRTG # number and change it to Workdir:/VAR/WWW/HTML/MRTG
Will options[_]: growright, bits #号去掉在下面添加一行
Language:chinese Support Chinese
It's after the modification.
Modify Complete
Continue to modify the Apache master configuration file below
Add or modify a line to become Adddefaultcharset GB2312 for Apache to support Chinese
After modification
Rebuild the configuration file, typically three times to succeed
Generate a Web page file
Modify the/etc/httpd/conf.d/mrtg.cfg file, modify the previous
After the modified
Restart Apache Service
Here is a brief introduction to using MRTG to monitor network traffic under CentOS
Refer to the bird's Linux private dishes, my Linux introduction ah
http://linux.vbird.org/linux_security/old/04mrtg.php
1, installation MRTG
Yum Install MRTG
Using Yum saves you a lot of hassle and does not have to care about those dependent packages.
2. Configuration
After installation, there will be a default basic MRTG configuration file in the/ETC/MRTG directory.
We use the command to create a new configuration file, currently we want to monitor the network status of 3 Linux servers, first confirm 3 Linux server SNMP configuration, three servers are as follows:
Server organization Name IP address
Web1 nubbcom 192.168.0.21
WEB2 nubbcom 192.168.0.22
WEB3 nubbcom 192.168.0.23
Produce one MRTG configuration file for each server separately
Cfgmaker [email protected] > Mrtg_web1.cfg
Cfgmaker [email protected] > Mrtg_web2.cfg
Cfgmaker [email protected] > Mrtg_web3.cfg
Some of the following configuration items are required to be configured
# Created by
#/usr/bin/cfgmaker [email protected]
# # Global Config Options
# for UNIX
Workdir:/var/www/html/mrtg/#这里要去掉原来的注释, and configure your current MRTG working directory as the directory of MRTG files.
# or for NT
# Workdir:c:\mrtgdata
# # Global Defaults
# to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits #顾名思义啊, use bits or use bytes to choose for yourself.
Note: The above configuration should be left shelf, no spaces appear, otherwise the execution of the configuration file will be error, the following example:
[Email protected] mrtg]# LANG=C/USR/BIN/MRTG mrtg_web2.cfg
Error:line 8 (Workdir:/var/www/html/mrtg/) in CFG file (mrtg_web2.cfg) does do sense
3. Enable MRTG
After executing the MRTG command and setting the configuration file
[Email protected] mrtg]# LANG=C/USR/BIN/MRTG mrtg_web1.cfg
Three times required for first time operation
The first time there is no MRTG file, so create the relevant file
26-10-2011 12:03:12, Rateup WARNING:/usr/bin/rateup could not read the primary log file for 192.168.0.21_2
26-10-2011 12:03:12, Rateup WARNING:/usr/bin/rateup The backup log file for 192.168.0.21_2 is invalid as well
26-10-2011 12:03:12, rateup WARNING:/usr/bin/rateup Can ' t remove 192.168.0.21_2.old updating log file
26-10-2011 12:03:12, rateup WARNING:/usr/bin/rateup Can ' t rename 192.168.0.21_2.log to 192.168.0.21_2.old updating log fi Le
26-10-2011 12:03:12, Rateup WARNING:/usr/bin/rateup could not read the primary log file for 192.168.0.21_3
26-10-2011 12:03:12, Rateup WARNING:/usr/bin/rateup The backup log file for 192.168.0.21_3 is invalid as well
26-10-2011 12:03:12, rateup WARNING:/usr/bin/rateup Can ' t remove 192.168.0.21_3.old updating log file
26-10-2011 12:03:12, rateup WARNING:/usr/bin/rateup Can ' t rename 192.168.0.21_3.log to 192.168.0.21_3.old updating log fi Le
Twice
26-10-2011 12:03:15, rateup WARNING:/usr/bin/rateup Can ' t remove 192.168.0.21_2.old updating log file
26-10-2011 12:03:16, rateup WARNING:/usr/bin/rateup Can ' t remove 192.168.0.21_3.old updating log file
three times.
No information
After execution, you will see all the MRTG files in the working directory, and some graphics display the elements and log files used by the page.
[[email protected] mrtg]# ll/var/www/html/mrtg/
Total 972
-rw-r--r--1 root root 1445 Oct 26 12:09 19 2.168.0.21_2-day.png
-rw-r--r--1 root root 6441 Oct 12:09 192.168.0.21_2.html
-rw-r--r--1 root root 48198 Oct 192.168.0.21_2.log
-rw-r--r--1 root root 1361 Oct 12:09 12:09 192.168.0.21_2-month.png
-rw-r--r-- 1 root root 48198 Oct 12:09 192.168.0.21_2.old
-rw-r--r--1 root root 1417 Oct 12:09 192.168.0.21_2-week.pn G
-rw-r--r--1 root root 1685 Oct 12:09 192.168.0.21_2-year.png
-rw-r--r--1 root root 1445 Oct 26 12 : 192.168.0.21_3-day.png
-rw-r--r--1 root root 6442 Oct 12:09 192.168.0.21_3.html
-rw-r--r--1 root root 48198 Oct 12:09 192.168.0.21_3.log
Unfortunately, this MRTG command can only load one configuration file in turn, and other server files are executed individually, which can be very inconvenient in the case of a number of monitored objects, so that multiple profiles may be merged into a large file.
Simplifies the operations performed by MRTG.
[email protected] mrtg]# cat mrtg_web*.cfg >mrtg.cfg
From then on, execution requires only one action
[Email protected] mrtg]# LANG=C/USR/BIN/MRTG mrtg.cfg
The MRTG command is only executed manually, to be able to see continuous graphics, must be timed to perform MRTG operation to obtain the current traffic, using crontab per minute acquisition.
[Email protected] mrtg]# CRONTAB-E
*/1 * * * * lang=c/usr/bin/mrtg/etc/mrtg/mrtg.cfg
4. Setting up the Monitoring page
The previous step has completed the acquisition of traffic data and the generation of related files, but we need to customize the same display data for a monitoring page.
MRTG itself provides a command to generate a monitoring home page indexmaker, which executes it to generate Web pages.
[Email protected] mrtg]# indexmaker mrtg.cfg >/var/www/html/mrtg/index.html
Enter the URL http://web server name or ip/mrtg/to view the current home page.
Note: Here you need to set up the Apache first, speaking MRTG monitoring home configuration settings good.
Add: The following issues occurred while monitoring the firewall
[Email protected] mrtg]# Cfgmaker[email protected]>mrtg_isg2000-1.cfg
SNMP Error:
No response received
Snmpv1_session (remote host: "172.10.10.3" [172.10.10.3].161)
Community: "ct10000"
Request ID:-869504328
PDU bufsize:8000 bytes
Timeout:2s
Retries:5
BACKOFF:1)
at/usr/bin/. /LIB64/MRTG2/SNMP_UTIL.PM Line 627
Snmpwalk problem for 1.3.6.1.2.1.1 on[email protected]: v4only
At/usr/bin/cfgmaker Line 918
Warning:skipping[email protected]As no info could be retrieved
Finally verify that the SNMP used by the firewall is V2 version, so the specified SNMP version is re-executed V2
[Email protected] mrtg]# cfgmaker--snmp-options=:::::2 [email protected] >mrtg_isg2000-1.cfg
Ok! Successful execution
MRTG is through the SNMP protocol, to run the SNMP protocol host to inquire about the relevant information, the host passed the value to MRTG, and then MRTG to the chart on the page (such as)!
the predecessor of SNMP (Imple network Management Protocol, simple Web Management Protocol) is the simple Gateway Monitoring Protocol (SGMP), which is used to manage communication lines. Subsequently, Sgmp was greatly modified, especially with the addition of an internet-defined SMI and MIB: architecture, and the improved protocol was known as SNMP. The goal of SNMP is to manage the hardware and software platforms produced by many manufacturers on the internet, so SNMP is affected by the Internet standard Network management framework. Now that SNMP is out of the third version of the Protocol, its functionality has been greatly enhanced and improved over the past.
Reference
http://gehailong.blog.51cto.com/765312/633825
One installation MRTG
Yum install gd-* libpng-* perl-* zlib-* httpd-* net-snmp-* mrtg-*
Two configuration MRTG
- Cfgmaker--global "Workdir:/usr/local/apache/htdocs/mrtg" \
- --global "Options[]:growright,bits"--show-op-down --ifref=name \
- --output/usr/local/apache/htdocs/mrtg/mrtg.cfg [email protected] [email protected]
- Env LANG=C/USR/BIN/MRTG/USR/LOCAL/APACHE/HTDOCS/MRTG/MRTG.CFG
- Indexmaker --output=/usr/local/apache/htdocs/mrtg/index.html --title=mrtg/usr/local/apache/htdocs/ Mrtg/mrtg.cfg
- Command explanation:
- The 2.1 cfgmaker command is used to generate the MRTG configuration file.
- --global is a two global configuration parameter to specify the MRTG working directory and the Growth unit (bit) of the traffic
- --show-op-down is to display all interface traffic, by default only the interface with traffic is displayed
- --ifref= name indicates that thecaption above the generated traffic picture is the name of the interface
- --output=Mrtg.cfg represents the name of the MRTG configuration file
- [Email protected], note that @ Front is the community name of SNMP, is to do authentication, the equivalent of the password, the name of the community to be on the managed device to lift the set up, this needs attention.
- 2.2 env lang=c/usr/bin/mrtg/usr/local/apache/htdocs/mrtg/mrtg.cfg
- Set the environment variable Lang to C (Chinese Chinese) and use the MRTG command to handle the configuration file of the MRTG just generated; Note that the command needs to be performed 3 times .
- 2.3 indexmaker --output=/var/ww/html/index.html --title= page title/var/www/html/mrtg.cfg
- Indexmaker is used to generate a Web page file, you need to specify the MRTG configuration file later.
- 2.4 Restart Apache and then use http://To build MRTG IP to access the monitoring content
- 2.5 is performed every 2 minutes to achieve real-time monitoring purposes
- Crontab-e
- */2 * * * * env LANG=C/USR/BIN/MRTG/USR/LOCAL/APACHE/HTDOCS/MRTG/MRTG.CFG
Three-monitor router/switch/server interface traffic
3.1 Monitoring network devices
Take the Cisco 3560 switch as an example: The device SNMP-enabled command is: SNMP Community community Name RO/RW
1f#conf ter
Enter configuration commands, one per line. End with cntl/z.
1f (config) #snmp-server Community Switch RO
1f (config) #snmp-server trap-source gigabitethernet 0/25
1f (config) #snmp-server enable traps
1f (config) #end
3.2 Monitoring Windows systems
Windows installs the Simple Network Management Protocol (in addition to the removal program), and then it can find the SNMP service
Security options, click Add
Community Name, group (read-only), SNMP service configuration (string/password)
Accept the Add MRTG IP address from this write SNMP packet
3.3 Monitoring Linux Systems
Installing SNMP
Yum Install net-snmp-*
Edit snmpd.conf configuration file
Vim/etc/snmp/snmpd.conf
41 Line 1 Change the default to MRTG server ip;2 change public to a more complex recognized string
Com2sec notconfiguser Default Dongnan
62 Line 1 Change SystemView to all for all SNMP access rights
Access Notconfiggroup "" Any noauth exact none none
85 Lines # comment symbol removed
View all included. 1 80
Start SNMPD
Chkconfig snmpd on &&/etc/init.d/snmpd start
End
MRTG configuration is straightforward, suitable for monitoring equipment or server bandwidth traffic, if you need more advanced features, you can try Nagios|cacti|zabbix and so on.
MRTG monitoring network traffic simple configuration