In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Cacti
What is Cacti?
Cacti means cactus in English. Cacti is a set of graphical analysis tools for network traffic monitoring based on PHP,MySQL,SNMP and RRDTool. It uses snmpget to get data, uses RRDtool to draw graphics, and you don't need to know the complex parameters of RRDtool. It provides a very powerful data and user management functions, you can specify that each user can view the tree structure, host and any map, can also be combined with LDAP for user authentication, but also can add their own templates, the function is very powerful and perfect. The development of Cacti is based on making it easier for RRDTool users to use the software. In addition to basic Snmp traffic and system information monitoring, Cacti can also plug in Scripts and add Templates to make a variety of monitoring charts.
Cacti is a software implemented in PHP language, its main function is to use snmp services to obtain data, then use rrdtool to store and update data, and when users need to view data, use rrdtool to generate charts and present them to users. Therefore, snmp and rrdtool are the key to cacti. Snmp is related to data collection, and rrdtool is related to data storage and chart generation.
Mysql cooperates with PHP program to store some variable data and call it, such as hostname, host ip, snmp community name, port number, template information and other variables.
The data captured by snmp is not stored in mysql, but in the rrd file generated by rrdtool (in the rra folder of the cacti root directory). The update and storage of data in rrdtool is the processing of rrd file. Rrd file is a fixed-size archive file (Round Robin Archive), and the number of data it can store has been defined at the time of creation. For knowledge about RRDTool, please refer to RRDTool Teaching.
What is SNMP?
Snmp (Simple Network Management Protocal, simple Network Management Protocol) plays an important role in the monitoring subsystem of the architecture. In general, the basic principle is that an agent is run on each monitored host or node (such as a switch) to collect all relevant information about that node, while listening to snmp's port, that is, UDP 161. and receiving instructions (queries and settings) from the monitoring host from this port.
If net-snmp is installed, the monitored host needs to install net-snmp (including the agent of snmpd), and the monitoring side needs to install net-snmp-utils. If it accepts the message sent by the monitored end through trap-communicate, it needs to install net-snmp and enable the trap service. If you compile yourself, you need libraries for beecrypt (libbeecrypt) and elf (libraryelf).
What is RRDtools?
RRDtool refers to the Round Robin Database tool (ring database). Round robin is a technique for dealing with quantitative data as well as current element pointers. Imagine a circle with dots around it-these points are where time is stored. Draw an arrow from the center of the circle to a point around the circle-this is the pointer. Just like we are in a circle, there is no starting point and end point, you can go straight down. Over a period of time, all available locations will be used, and the loop will automatically reuse the original location. In this way, the dataset does not grow and does not require maintenance. RRDtool handles the RRD database. It stores data in the RRD database and extracts data from the RRD database.
How it works:
Snmp is related to data collection, rrdtool relational data storage and chart generation. The data captured by snmp is not stored in the database, but in the rrd file generated by rrdtool. The simple schematic diagram is as follows:
Experiment
1. Build lamp environment
(1) configure apache
[root@cacti-server ~] # yum-y install httpd
[root@cacti-server ~] # systemctl start httpd
[root@cacti-server ~] # systemctl enable httpd
[root@cacti-server] # firewall-cmd-- permanent-- add-service=http
Success
[root@cacti-server] # firewall-cmd-- reload
Success
(2) configure mariadb
[root@cacti-server ~] # yum-y install mariadb-server mysql-devel
[root@cacti-server ~] # systemctl start mariadb
[root@cacti-server ~] # mysql_secure_installation
Set root password? [Y/n]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
[root@cacti-server] # mysql-u root-p
MariaDB [(none)] > grant all privileges on *. * to test@localhost identified by 'redhat'; # create users to test php and mariadb connectivity
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)] > flush privileges
[root@cacti-server ~] # systemctl restart mariadb
[root@cacti-server ~] # systemctl enable mariadb
[root@cacti-server] # firewall-cmd-- permanent-- add-port=3306/tcp
Success
[root@cacti-server] # firewall-cmd-- reload
Success
(3) configure php
[root@cacti-server ~] # yum-y install php php-mysql php-gd php-pear
[root@cacti-server ~] # vim / etc/php.ini
Date.timezone = PRC # modify time zone
[root@cacti-server ~] # vim / var/www/html/index.php # Edit the test page
[root@cacti-server ~] # systemctl restart httpd
(4) testing
two。 Install and configure cacti
(1) download the software
[root@cacti-server ~] # cd / usr/local/src/
[root@cacti-server src] # wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
[root@cacti-server src] # tar zxvf cacti-0.8.8f.tar.gz
[root@cacti-server src] # mv cacti-0.8.8f / var/www/html/cacti
(2) create cacti database and cacti users, and grant permissions
[root@cacti-server] # mysql-u root-p
MariaDB [(none)] > create database cacti default character set utf8
MariaDB [(none)] > grant all privileges on cacti.* to cacti@localhost identified by 'redhat'
MariaDB [(none)] > flush privileges
(3) Import cacti.sql into database
[root@cacti-server cacti] # mysql-ucacti-predhat cacti
< /var/www/html/cacti/cacti.sql (4)编辑config.php和global.php [root@cacti-server cacti]# vim /var/www/html/cacti/include/config.php|global.php $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "redhat"; $database_port = "3306"; $database_ssl = false; (5)安装rrdtool以生成图像 [root@cacti-server src]# yum -y install rrdtool rrdtool-devel rrdtool-php rrdtool-perl [root@cacti-server src]# yum -y install gd gd-devel php-gd #rrdtool绘制图像需要的图形库 (6)安装snmp服务 [root@cacti-server cacti]# yum -y install net-snmp net-snmp-utils php-snmp net-snmp-libs (7)编辑配置文件 [root@cacti-server ~]# vim /etc/snmp/snmpd.conf 41 com2sec notConfigUser 127.0.0.1 public 62 access notConfigGroup "" any noauth exact all none none 85 view all included .1 80 [root@cacti-server ~]# systemctl restart snmpd.service [root@cacti-server ~]# systemctl enable snmpd.service (8)授权目录权限 [root@cacti-server ~]# useradd -r -M cacti [root@cacti-server ~]# chown -R cacti /var/www/html/cacti/rra/ [root@cacti-server ~]# chown -R cacti /var/www/html/cacti/log/ (9)配置一个抓图的计划任务 [root@cacti-server ~]# crontab -e */5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >> / tmp/cacti_rrdtool.log
(10) the browser accesses the cacti management page to install
(11) testing
[root@cacti-server] # / usr/bin/php / var/www/html/cacti/poller.php
OK u:0.00 s:0.01 r:0.80
OK u:0.00 s:0.02 r:1.21
OK u:0.00 s:0.02 r:1.39
OK u:0.00 s:0.02 r:1.50
OK u:0.00 s:0.02 r:1.87
04:02:32 PM-SYSTEM STATS: Time:1.4211 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
3. Install Spine
Note: because cacti uses cmd.php to poll data by default, the speed will be very slow, especially when there are many monitoring nodes, cmd.php is even more insufficient, so we use Spine to poll data. Cacti-spine is a fast data acquisition engine developed by C language to replace cmd.php.
(1) compile and install spine
[root@cacti-server ~] # cd / usr/local/src/
[root@cacti-server src] # wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8f.tar.gz
[root@cacti-server src] # tar zxvf cacti-spine-0.8.8f.tar.gz
[root@cacti-server cacti-spine-0.8.8f] #. / configure
[root@cacti-server cacti-spine-0.8.8f] # make
[root@cacti-server cacti-spine-0.8.8f] # make install
(2) copy the configuration file of snmp
[root@cacti-server ~] # cp / usr/local/spine/etc/spine.conf.dist / etc/spine.conf
Note: the default configuration file of spine needs to be placed in / etc before it will take effect, otherwise the following error will be reported during the test:
SPINE: Poller [0] FATAL: Unable to read configuration file! (Spine init)
(3) Edit configuration file
[root@cacti-server ~] # vim / etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass redhat
DB_Port 3306
(4) testing
[root@cacti-server ~] # / usr/local/spine/bin/spine
SPINE: Using spine config file [/ etc/spine.conf]
SPINE: Version 0.8.8f starting
SPINE: Time: 0.1278 s, Threads: 5, Hosts: 2
(5) modify the settings of web
Go to the Cacti page to set the spine path
Console-> Configuration-> Settings-> Paths-> Alternate Poller Path- > Spine Poller File Path- > / usr/local/spine/bin/spine
(6) modify the Poller Type used by Cacti
Console-> Configuration-> Settings-> Poller- > Poller Type- > spine
(7) View logs
[root@cacti-server ~] # cat / var/www/html/cacti/log/cacti.log
12:45:50 AM-SYSTEM STATS: Time:0.1146 Method:spine Processes:1 Threads:1 Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0
4. Add monitored host
(1) install snmp service
[root@cacti-client ~] # yum-y install net-snmp net-snmp-devel net-snmp-utils
(2) Edit configuration file
[root@cacti-client ~] # vim / etc/snmp/snmpd.conf
41 com2sec notConfigUser 192.168.23.156 public
62 access notConfigGroup "" any noauth exact all none none
85 view all included. 1 80
[root@cacti-client ~] # systemctl restart snmpd
[root@cacti-client ~] # systemctl enabled snmpd
(3) configure firewall
[root@cacti-client] # firewall-cmd-- permanent-- add-port=161/udp
Success
[root@cacti-client] # firewall-cmd-- reload
Success
5. Monitoring apache
Configuration of the client
(1) Edit the configuration file of apache and add the settings of server-status module
[root@cacti-client ~] # vim / etc/httpd/conf/httpd.conf
ExtendedStatus On
SetHandler server-status
Order deny,allow
Deny from all
Allow from all
[root@cacti-client ~] # systemctl restart httpd
[root@cacti-client ~] # systemctl enable httpd
(2) View the modules loaded by apache
[root@cacti-client ~] # apachectl-t-D DUMP_MODULES | grep status
Status_module (shared)
(3) visit http://192.168.23.157/server-status to view the details of the module
[root@cacti-client] # firewall-cmd-- permanent-- add-service=http
Success
[root@cacti-client] # firewall-cmd-- reload
Success
Server configuration
(1) install the php page for monitoring apache
[root@cacti-server ~] # cd / usr/local/src/
[root@cacti-serversrc] # wget http://forums.cacti.net/download/file.php?id=18576&sid=8d429b69af5be45179d928e1303f2077
[root@cacti-server src] # unzip ApacheStats_0.8.2.zip
[root@cacti-server src] # cd ApacheStats_0.8.2/
[root@cacti-serverApacheStats_0.8.2] # cp ss_apache_stats.php / var/www/html/cacti/scripts/
(2) Import template
Import the cacti_host_template_webserver_-_apache.xml template in the Cacti Web interface:
Click Import/Export- > Import Templates to upload the template.
(3) add a server and create a chart
Log in to the Cacti Web interface, add the monitored apache server device, and create the corresponding chart:
Devices- > Add- > WebServer-Apache template-> Create New Graphs, just add the required chart. The picture will come out after waiting for a period of time.
6. Monitoring mariadb
(1) create a user for monitoring hosts to connect to mariadb for monitoring
[root@cacti-client] # mysql-uroot-predhat
MariaDB [(none)] > grant process,super,replication client on *. * to 'mysqltest'@'192.168.23.156' identified by' redhat'
MariaDB [(none)] > flush privileges
[root@cacti-client ~] # systemctl restart mariadb
(2) configure firewall
[root@cacti-client] # firewall-cmd-- permanent-- add-port=3306/tcp
Success
[root@cacti-client] # firewall-cmd-- reload
Success
(3) install the php page file for monitoring mariadb
[root@cacti-server ~] # cd / usr/local/src/
[root@cacti-serversrc] # wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-monitoring-plugins-1.1.6.tar.gz
[root@cacti-server src] # tar zxvf percona-monitoring-plugins-1.1.6
[root@cacti-server src] # cd percona-monitoring-plugins-1.1.6/cacti/scripts/
[root@cacti-serverscripts] # cpss_get_mysql_stats.php / var/www/html/cacti/scripts/
(4) Editing the page file
[root@cacti-server scripts] # vim / var/www/html/cacti/scripts/ss_get_mysql_stats.php
$mysql_user = 'mysqltest'; # is used to monitor the users of the host connected to the mariadb
$mysql_pass = 'redhat'; # user password
(5) Import template
Import the cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.1.6.xml template in the Cacti Web interface:
Click Import/Export- > Import Templates to upload the template.
(6) add a server and create a chart
Log in to the Cacti Web interface, add the monitored mariabdb server device, and create the corresponding chart:
Devices- > Add- > dbServer-Mysql template-> Create New Graphs, just add the required chart. The picture will come out after waiting for a period of time.
7. Mail alarm
(1) download the plug-in
[root@cacti-server ~] # cd / usr/local/src/
[root@cacti-server src] # tar zxvf settings-v0.71-1.tgz
[root@cacti-server src] # mv settings / var/www/html/cacti/plugins/
[root@cacti-server src] # tar zxvf thold-v0.5.0.tgz
[root@cacti-server src] # mv thold / var/www/html/cacti/plugins/
(2) visit the cacti management page to install the plug-in
(3) testing
(4) the alarm is triggered. Check the email.
[root@cacti-server ~] # cat / var/spool/mail/root
..
..
To: root@192.168.23.156
Subject: ALERT: test-Used Space-/ [hdd_used] [hdd_used] went above threshold of 25 with 36.8871
From: Cacti
Date: Mon, 24 Oct 2016 14:00:03 + 0800
..
An alert has been issued that requires your attention.
..
Host: test (192.168.23.157)
URL: http://192.168.23.156/cacti//graph.php?local_graph_id=103&rra_id=1
Message: ALERT: test-Used Space-/ [hdd_used] [hdd_used] went above threshold of 25 with 36.8871
..
Content-Type: p_w_picpath/jpg
Content-Disposition: inline; filename= "103.jpg"
..
..
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.