Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using SNMP to manage large-scale Network-cacti

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

First, the principle introduction:

1. Brief introduction to SNMP

At present, SNMP (simple Network Management Protocol) is the most widely used network management protocol in the network. SNMP is an industry standard widely accepted and put into use, which is used to ensure that management information is transmitted between any two points in the network. It is convenient for network administrators to retrieve information, modify information, locate faults, complete fault diagnosis, carry out capacity planning and generate reports at any node on the network.

SNMP uses a polling mechanism and provides only the most basic feature set, which is especially suitable for use in small, fast and low-cost environments. The implementation of SNMP is based on the connectionless transport layer protocol UDP, so it can realize barrier-free connection with many products.

2. The working mechanism of SNMP

SNMP is divided into two parts: NMS and Agent:

NMS (Network Management Station, network management station) is a workstation that runs client programs. At present, the commonly used network management platforms are QuidView, Sun NetManager and IBM NetView.

Agent is server-side software that runs on network devices.

NMS can send GetRequest, GetNextRequest and SetRequest messages to Agent. After receiving these request messages from NMS, Agent performs Read or Write operations according to the message type to generate Response messages and return the messages to NMS.

Agent will also actively send Trap messages to NMS to report events to NMS when abnormal conditions or state changes occur in the device (such as device restart).

3. Version of SNMP

Currently, SNMP Agent in the device supports SNMP v3 version, which is compatible with SNMP v1 version and SNMP v2C version.

SNMP v3 uses username and password authentication.

SNMP v1 and SNMP v2C are authenticated by group name (Community Name), and SNMP messages that are not approved by the device will be discarded. The SNMP community name is used to define the relationship between SNMP NMS and SNMP Agent. The group name acts like a password, restricting SNMP NMS access to the SNMP Agent on the device. You can choose to specify one or more of the following properties related to the group name:

1. Define the MIB view that the community name can access.

two。 Set the community name's access to the MIB object to read-write permission (write) or read-only permission (read). A community name with read-only permission can only query device information, while a community name with read-write permission can also configure the device.

3. Sets the basic access control list specified by the community name.

4. MIB supported by the device

Management variables are used to describe the management objects in the device in the SNMP message. In order to uniquely identify the management objects in the device, SNMP uses a hierarchical naming scheme to identify the management objects. The entire hierarchy is like a tree, and the nodes of the tree represent management objects, as shown in figure 1-1 below. Each node can be uniquely identified by a path from the root.

The function of MIB (Management Information Base, Management Information Base) is to describe the hierarchical structure of the tree, which is a collection of standard variables defined by the monitored network devices. In figure 1-1, the management object B can be uniquely identified by a string of numbers {1.2.1.1}, which are the object identifiers (Object Identifier) of the management object.

The common MIB supported by the system is shown in Table 1-1 below.

2. Installation, analysis and use of RRDtool:

Working schematic diagram:

The whole system consists of four parts:

1. Cacti system platform is used for users to set up and view charts; Cacti needs the support of LAMP environment.

2. Snmp is used to collect data and draw pictures for rrdtool, use port 161.162, use MIB database to maintain data information, according to OID positioning data (similar to 1.3.6.1.2.1); use net-snmp 's own snmpget and snmpwalk programs under Linux, and php's snmp function under Windows.

3. RRDTool drawing engine is used to store performance data and draw images.

4. Mysql database is used to store the information needed by RRDTool drawing.

Common monitoring objects of Cacti:

1. Server resources: CPU, memory, disk, process, number of connections, etc.

2. Server type: WEB, Mail, FTP, database

3. Network interface: traffic, forwarding speed, packet loss rate

Cacti focuses on network traffic and system load monitoring (network traffic, cpu, hard disk utilization, etc.)

1. Install cacti based on lamp environment (apache+mysql+php+net-snmp+rrdtool)

one

Yum install-y httpd httpd-devel mysql mysql-server mysql-devel

Php php-devel php-mysql php-common php-gd php-mbstring php-xml

Php-imap php-ldap php-odbc php-pear php-xmlrpc php-bcmath

Gd gd-devel freetype freetype-devel libjpeg libjpeg-devel libpng

Libpng-devel zlib zlib-devel libxml2 libxml2-devel libjpeg* libgcrypt

Libgcrypt-devel libxslt libxslt-devel php-snmp net-snmp net-snmp-utils

Perl-DBI rrdtool perl-rrdtool perl-DBD-MySQL net-snmp-libs lm_sensors

12345service httpd startservice mysqld startchkconfig httpd onchkconfig mysqld onmysqladmin-u root password root # set the mysql login password

2. Install and configure cacti

1), install cacti

123wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gztar zxvf cacti-0.8.8b.tar.gzmv cacti-0.8.8b/* / var/www/html

2) Import the database structure

123mysql > create database cacti;mysql > use cacti;mysql > source / var/www/html/cacti.sql

3) configure cacti to connect to the database:

123456789vi / var/www/html/include/config.php$database_type = "mysql"; $database_default = "cactidb"; $database_hostname = "localhost"; $database_username = "root"; $database_password = "root"; $database_port = "3306"; $database_ssl = false;$url_path = "/"; # uncomment and change the path to root

4), install cacti graphically, and type IP to start the installation

The default user and password are all admin, and you will be asked to change your password after entering.

5) configure snmp to monitor the local host

12345vi / etc/snmp/snmpd.confcom2sec notConfigUser 127.0.0.1 publicaccess notConfigGroup "" any noauth exact all none noneview all included .1 80service snmpd restart

3. Other configurations of cacti

1), php sets the time zone

123vi / etc/php.inidate.timezone = Asia/Shanghaiservice httpd restart

2) run it manually to generate the initial image file: (compile the installation path / usr/local/apache/htdocs/)

1/usr/bin/php / var/www/html/poller.php

3) set up scheduled tasks and generate charts every five minutes:

12crontab-eBay usr/bin/php 5 * / usr/bin/php / var/www/html/poller.php

4) modify the default setting of cacti: console- > setting

Rrdtool-v # View rrdtool version

Snmp version: sets the snmp version, usually version2

Snmp community: sets the community name. The default is public.

5) set permissions:

1234chown-R apache.root / var/www/html/chmod 775-R / var/www/htmlchmod 777 / var/www/html/rra / var/www/html/logchown-R root.root / var/www/html/rra / var/www/html/log

6), monitor the local host

After the configuration, check the localhost and find that the figure is all-nan:

Solution: rrdtool fetch-r 300 localhost_mem_buffers_3.rrd AVERAGE # uses rrdtool to get crawled information, and the result is-nan. Now it looks like the last date is 1379679000. When date +% s gets more than the last date, it's time to draw a picture.

4. Monitor Linux hosts

The monitored host is configured with SNMP:

123456yum install-y net-snmp-*vi / etc/snmp/snmpd.confcom2sec notConfigUser 192.168.0.10 public # changed to allow IPaccess notConfigGroup "" any noauth exact all none noneview all included. 1 80service snmpd restart # of the monitoring host to restart snmp

Monitor host add devices:

Console- > Device- > Add- > create

Add to the graphics tree:

Console- > Graph Trees- > Add- > Tree Item Type- > Host- > Select Host-> create

5. Monitor Windows hosts

First of all, the snmp service has been added to the host, and then installing snmp-informant-std will add more SNMP Trap in the service, which does not need to be configured, and then configure Snmp Service:

Start-run-services.msc, find "snmp service", right open "Properties", select "Security", at "accept group name", click "add", write the community used by your cacti at "group name", select "accept snmp packets from these hosts", default is "localhost", click "Edit", change "localhost" to the actual ip address of the cacti monitoring server!

6. Start with the following solutions without drawing or data

1. Image not generated, run # / usr/bin/php / var/www/html/poller.php

two。 Permission issue, modify permission # chmod 777-R / var/www/html/rra / var/www/html/log/

3.snmp configuration problem, detect whether there is a data output # snmpwalk-V2C-c public 127.0.0.1

4. Delete all files under rra and clear the cache # system utilities-> Rebuild poller cache

5. The system time is not accurate. Reset time date.timezone = PRC

6. Database table is damaged, repair # mysqlcheck-ao cacti-auto-repair-uroot-p

7. No pictures and no data # service snmpd restart

7. Try to restart the snmpd service # service snmpd restart

The installation is finished here!

7. Related detailed configuration 1-the following is to view the data through the RRDtool command

[root@localhost ~] # yum install net-snmp

[root@localhost ~] # yum install net-snmp-utils

[root@localhost] # snmpwalk-v 2c-c public localhost host

HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (1618864) 4GRO 29PUR 48.64

HOST-RESOURCES-MIB::hrSystemUptime.0 = No more variables left in this MIB View (It is past the end of the MIB tree)

[root@localhost] # snmpwalk-v 2c-c public localhost

SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.18-164.el5PAE # 1 SMP Tue Aug 18 15:59:11 EDT 2009 i686

SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10

DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (745096) 2 purl 04purl 10.96

SNMPv2-MIB::sysContact.0 = STRING: Root (configure / etc/snmp/snmp.local.conf)

SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain

SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit / etc/snmp/snmpd.conf)

SNMPv2-MIB::sysORLastChange.0 = Timeticks: (13) 0001 00.13

SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB

SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB

SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip

SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB

SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup

SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance

SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance

SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance

SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities

SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for ma

[root@localhost ~] # vi / etc/snmp/snmpd.conf

# First, map the community name "public" into a "security name"

# sec.name source community

# com2sec notConfigUser default public

Com2sec notConfigUser 127.0.0.1 mypublic

Com2sec notConfigUser 10.109.0.0/16 mypublic

# Second, map the security name into a group name:

# groupName securityModel securityName

Group notConfigGroup v1 notConfigUser

Group notConfigGroup v2c notConfigUser

[root@localhost ~] # service snmpd restart

[root@localhost] # snmpwalk-v 2c-c mypublic 10.109.131.198

SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.18-164.el5PAE # 1 SMP Tue Aug 18 15:59:11 EDT 2009 i686

SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10

DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (15379) 02purl 33.79

SNMPv2-MIB::sysContact.0 = STRING: Root (configure / etc/snmp/snmp.local.conf)

SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain

SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit / etc/snmp/snmpd.conf)

SNMPv2-MIB::sysORLastChange.0 = Timeticks: (4) 0RV 001R 00.04

SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB

SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB

SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip

SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB

SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup

SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance

......

[root@localhost ~] # chkconfig snmpd on

[root@localhost] # chkconfig-- list snmpd

Snmpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@localhost ~] # yum install ruby

...

Downloading Packages:

(1x2): ruby-libs-1.8.5-5.el5_3.7.i386.rpm | 1.6 MB 00:00

(2max 2): ruby-1.8.5-5.el5_3.7.i386.rpm | 274 kB 00:00

...

[root@localhost] # rpm-ivh rrdtool-1.2.27-4.el5.i386.rpm

[root@localhost] # rpm-ivh rrdtool-perl-1.2.27-4.el5.i386.rpm

[root@localhost] # rrdtool create test.rrd-- step 5-- start-1 DS:testds:GAUGE:8:0:U RRA:AVERAGE:0.5:1:17280 RRA:AVERAGE:0.5:10:3456 RRA:AVERAGE:0.5:100:1210

[root@localhost] # ll-h test.rrd

-rw-r--r-- 1 root root 173K Feb 22 16:14 test.rrd

[root@localhost ~] # rrdtool info test.rrd

Filename = "test.rrd"

Rrd_version = "0003"

Step = 5

Last_update = 1487751267

DS [testds] .type = "GAUGE"

DS [testds] .clients _ heartbeat = 8

DS [testds] .min = 0.0000000000e+00

DS [testds] .max = NaN

DS [testds] .last _ ds = "UNKN"

...

[root@localhost ~] # cat insert.sh

#! / bin/bash

#

For I in {1... 200000}; do

Mysql-e "INSERT INTO testdb.tb1 (NAME) VALUES ('stu$I')"

Mysql-e "SELECT * FROM testdb.tb1" & > / dev/null

Done

[root@localhost ~] # cat getselect.sh

#! / bin/bash

#

While true; do

SELECT= `mysql-- batch-e "SHOW GLOBAL STATUS LIKE 'com_select'" | awk' / Com_select/ {print $2}'`

Rrdtool update mysql.rrd N:$SELECT

Sleep 3

Done

573 rrdtool fetch-r 5 mysql.rrd AVERAGE

574 rrdtool fetch-r 30 mysql.rrd AVERAGE

575 rrdtool fetch-r 30 mysql.rrd max

576 rrdtool fetch-r 30 mysql.rrd MAX

577 rrdtool fetch-r 30 mysql.rrd LAST

580 rrdtool graph mysql.png-s 1487747370-t "mysql select"-v "select/3" DEF:select3=mysql.rrd:myselect:AVERAGE:step=3 LINE1:select3#FF0000: "SELECT"

581 rrdtool graph mysql.png-s 1487747370-t "mysql select"-v "select/30" DEF:select3=mysql.rrd:myselect:AVERAGE:step=30 LINE1:select3#FF0000: "SELECT"

583 rrdtool graph mysql2.png-s 1487747370-t "mysql select"-v "select/3" DEF:select3=mysql.rrd:myselect:AVERAGE:step=30 DEF:max30=mysql.rrd:myselect:MAX:step=30 DEF:last30=mysql.rrd:myselect:LAST:step=30 LINE1:select3#FF0000: "SELECT"

584 rrdtool graph mysql3.png-s 1487747370-t "mysql select"-v "select/30" DEF:select3=mysql.rrd:myselect:AVERAGE:step=30 DEF:max30=mysql.rrd:myselect:MAX:step=30 DEF:last30=mysql.rrd:myselect:LAST:step=30 LINE1:select3#FF0000: "SELECT"

589 rrdtool graph mysql4.png-s 1487747370-t "mysql select"-v "select/30" DEF:select3=mysql.rrd:myselect:AVERAGE:step=30 DEF:max30=mysql.rrd:myselect:MAX:sep=30 DEF:last30=mysql.rrd:myselect:LAST:step=30 LINE1:select3#FF0000: "SELECT" GPRINT:last30:LAST: "CURRENT\: .21F" GPRINT:max30:MAX: "MAXIMUM\:% 6.21f"

8. Related detailed configuration 2-create a HTTP virtual host and view it manually

[root@localhost ~] # vi / etc/httpd/extra/httpd-vhosts.conf

ServerName cacti.jacktest.com

DocumentRoot "/ web/vhosts/cacti"

Options Indexes

AllowOverride none

Require all granted

ErrorLog "logs/cacti-error_log"

CustomLog "logs/cacti-access_log" common

[root@localhost ~] # mkdir / web

[root@localhost ~] # mkdir / web/vhosts

[root@localhost ~] # ls / web/vhosts

[root@localhost] # tar xf cacti-0.8.8a.tar.gz-C / web/vhosts/

[root@localhost ~] # cd / web/vhosts/

[root@localhost vhosts] # ll

Lrwxrwxrwx 1 root root 12 02-23 09:26 cacti- > cacti-0.8.8a

Drwxr-xr-x 13 1000 users 4096 2012-04-23 cacti-0.8.8a

[root@localhost vhosts] # service httpd restart

[root@localhost cacti] # mysqladmin create cactidb

[root@localhost cacti] # mysql cactidb

< cacti.sql [root@localhost cacti]# mysql -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'" [root@localhost cacti]# mysqladmin flush-privileges [root@localhost cacti]# mysql -ucactiuser -p mysql>

Show databases

+-+

| | Database |

+-+

| | information_schema |

| | cactidb |

| | test |

+-+

3 rows in set (0.01sec)

[root@localhost cacti] # vi config.php

$database_type = "mysql"

$database_default = "cactidb"

$database_hostname = "localhost"

$database_username = "cactiuser"

$database_password = "cactiuser"

$database_port = "3306"

$database_ssl = false

/ *

Edit this to point to the default URL of your Cacti install

Ex: if your cacti install as at http://serverip/cacti/ this

Would be set to / cacti/

, /

/ / $url_path = "/ cacti/"

$url_path = "/"

[root@localhost include] # useradd cactiuser

[root@localhost cacti] # pwd

/ web/vhosts/cacti

[root@localhost cacti] # chown-R cactiuser:cactiuser rra/ log

Poller.php-- = = > > Spine

[root@localhost cacti] # echo'* / 5 * / usr/local/php/bin/php / usr/local/apache/htdocs/cacti/poller.php & > / dev/null' > / var/spool/cron/cactiuser # automatically executes poller.php every 5 minutes

[root@localhost cacti] # crontab-u cactiuser-e

[root@localhost vhosts] # vi / etc/php.ini

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

; date.timezone =

Date.timezone = PRC

[root@localhost vhosts] # service httpd restart

[cactiuser@localhost ~] $/ usr/local/php/bin/php / web/vhosts/cacti/poller.php

02Blue24Universe 09:44:13 AM-SYSTEM STATS: Time:0.1567 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0

[root@localhost log] # vi / usr/local/apache/htdocs/cacti/log/cacti.log

02Blue24Universe 09:40:01 AM-SYSTEM STATS: Time:0.1457 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0

[root@localhost rra] # ls / usr/local/apache/htdocs/cacti/rra/

Localhost_load_1min_5.rrd localhost_mem_swap_4.rrd localhost_users_6.rrd

Localhost_mem_buffers_3.rrd localhost_proc_7.rrd

9. Related detailed configuration 3-- manually view monitoring documents

1. Test collection commands:

[cactiuser@localhost] $snmpnetstat-v 2c-c public-Can-Cp tcp 10.109.131.144

two。 Show a result

[root@localhost htdocs] # vim / usr/local/apache/htdocs/scripts/tcpconn.sh

#! / bin/bash

#

# $1: hostname or ip

# $2: snmp comunity

SNMPNETSTAT=/usr/bin/snmpnetstat

ESTABLISHED= `$ SNMPNETSTAT-v 2c-c $2-Can-Cp tcp $1 | grep-I 'established' | wc-l`

Echo-n "established:$ESTABLISHED"

Execution result: established:19

3. Show multiple results

#! / bin/bash

#

# $1: hostname or ip

# $2: snmp comunity

SNMPNETSTAT=/usr/bin/snmpnetstat

TEMPFILE= `mktemp / tmp/$1_ tcpconn.XXXXXXXX`

$SNMPNETSTAT-v 2c-c $2-Can-Cp tcp $1 > $TEMPFILE

ESTABLISHED= `grep-I'$ESTABLISHED' $TEMPFILE | wc-l `

TIMEWAIT= `grep-I'$TIMEWAIT' $TEMPFILE | wc-l `

SYNRECEIVED= `grep-I'$SYNRECEIVED' $TEMPFILE | wc-l `

Echo-n "established:$ESTABLISHED timewait:$TIMEWAIT synreceived:$SYNRECEIVED"

10. Related downloads

1) download rrdtool:

Https://mirrors.tuna.tsinghua.edu.cn/epel//5/i386/

2) download cacti-0.8.8a:

Http://vdisk.weibo.com/s/ukAFmeXH43dKX

3) download cacti-spine-0.8.8a:

Http://www.cacti.net/downloads/spine/

4) download monitor-v1.3-1.tgz:

Http://docs.cacti.net/plugin:monitor

5) installation and optimization of Cacti0.8.8a (Spine-Monitor-Setting-thold)

Http://damondeng.blog.51cto.com/1038075/1226857

6) thold-v0.5.0.tgz download: http://docs.cacti.net/plugin:thold#download

Settings-v0.71-1.tgz download: http://docs.cacti.net/plugin:thold#download

Monitor-v1.3-1.tgz download: http://docs.cacti.net/plugin:monitor

7) Cacti uses third-party templates to monitor windows hosts

Http://www.cactifans.org/category/cacti%E8%A7%86%E9%A2%91

8) cacti template collection:

Http://csevan.blog.163.com/blog/static/117971266201071292318877/

9) easily manage linux services with Webmin

Http://guojiping.blog.51cto.com/5635432/987817

10) the latest version of Cnyunwei-Cacti+Nagios V11 is released and will be used as soon as the installation is completed.

Http://www.cnyunwei.com/thread-5714-1-1.html

-end

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report