返回列表 发帖

CentOS8_lnmp1.7_LAMP_安装Cacti

LAMP环境的安装可参考: CentOS8_lnmp1.7_LAMP_安装Nagios


[root@redhat8 ~]# /usr/local/apache/bin/httpd -v
Server version: Apache/2.4.46 (Unix)
Server built:   Aug 14 2021 14:58:50

[root@redhat8 ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for unknown-linux-gnu (x86_64) using readline 5.1

[root@redhat8 ~]# php -v
PHP 5.3.29 (cli) (built: Aug 14 2021 15:05:35)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies


安装snmp、rrdtool:(使用本地光盘作为Yum源即可)
[root@redhat8 ~]# dnf -y install php-snmp net-snmp-utils rrdtool


安装Cacti:
tar -zxvf cacti-0.8.8b.tar.gz -C /usr/local/
mkdir /home/wwwroot/default/cacti

mv /usr/local/cacti-0.8.8b/* /home/wwwroot/default/cacti
rm -rf /usr/local/cacti-0.8.8b/

chown -R www:www /home/wwwroot/default/cacti


给Cacti创建库:
[root@redhat8 ~]# mysql -uroot -p888
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database cacti CHARACTER SET latin1;
Query OK, 1 row affected (0.00 sec)

mysql> show create database cacti;
+----------+------------------------------------------------------------------+
| Database | Create Database                                                  |
+----------+------------------------------------------------------------------+
| cacti    | CREATE DATABASE `cacti` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+------------------------------------------------------------------+
1 row in set (0.00 sec)


查看所有数据库用户及其主机信息:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)


查看数据库管理员root@localhost的权限:
mysql> show grants for root@localhost;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*41DDB5DFD213B288EE050BD64DC6AA36815A3486' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)



将目录/home/wwwroot/default/cacti/里的cacti.sql 导入到MySQL的库cacti里:
[root@redhat8 ~]# mysql -uroot -p888 cacti < /home/wwwroot/default/cacti/cacti.sql


修改Cacti的配置文件里的数据库连接信息:
[root@redhat8 ~]# vi /home/wwwroot/default/cacti/include/config.php
图片1.png
2021-8-22 00:28


Cacti的URL PATH:(登录Cacti的Web页面的格式  http://服务器IP/cacti/
图片2.png
2021-8-22 00:28


保存文件后,重启Apache:
[root@redhat8 ~]# systemctl restart httpd


要先运行以下脚本,删掉PHP被禁用的函数:(不然Cacti会检测不到数据)
[root@redhat8 ~]# cd lnmp1.7-full/tools/
[root@redhat8 tools]# bash remove_disable_function.sh
图片3.png
2021-8-22 00:29


重启Apache:
[root@redhat8 ~]# systemctl restart httpd


先手动运行几次以下的命令:
[root@redhat8 ~]# /usr/bin/php /home/wwwroot/default/cacti/poller.php

修改crontab文件,添加RRDtool抓图任务计划:
[root@redhat8 ~]# crontab -e
追加:
*/5 * * * * /usr/bin/php /home/wwwroot/default/cacti/poller.php



######
从Windows客户端安装:
http://192.168.168.155/cacti/
图片4.png
2021-8-22 00:30



图片5.png
2021-8-22 00:30



图片6.png
2021-8-22 00:30


图片7.png
2021-8-22 00:30



默认登录用户名和密码均为 admin
图片8.png
2021-8-22 00:31


强制修改初始密码的:
图片9.png
2021-8-22 00:31



Cacti的主界面:
图片10.png
2021-8-22 00:40


在主界面可以看到Cacti版本:
图片11.png
2021-8-22 00:40



查看本机的图形信息:(要等一下才有图像出来的)
图片12.png
2021-8-22 00:41


选择时间范围,查看过去1天的图形信息:
图片13.png
2021-8-22 00:41


图片14.png
2021-8-22 00:41


图片15.png
2021-8-22 00:41




######
添加Monitor,Thold等插件:
cd /root/cacti-plugin/
tar -zxvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz -C /tmp/

cd /home/wwwroot/default/cacti/
patch -p1 -N < /tmp/cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.8.diff

cd /home/wwwroot/default/cacti/plugins
tar -zxvf /root/cacti-plugin/monitor-0.8.2.tar.gz
tar -zxvf /root/cacti-plugin/settings-0.5.tar.gz
tar -zxvf /root/cacti-plugin/thold-0.4.3.tar.gz  

mysql -u root -p888 cacti < monitor/monitor.sql
mysql -u root -p888 cacti < thold/thold.sql


再次修改Cacti的配置文件:
[root@redhat8 ~]# vi /home/wwwroot/default/cacti/include/config.php
图片16.png
2021-8-22 00:42

修改为:(登录Cacti的Web页面的格式  http://服务器IP/cacti/
图片17.png
2021-8-22 00:42


保存文件后,重启Apache:
[root@redhat8 ~]# systemctl restart httpd



######
登录Cacti的Web页面 http://192.168.168.155/cacti/

点击左边导航栏“concle”》“Configuration”下的“Plugin Management”:
分别单击按钮进行激活:
图片18.png
2021-8-22 00:43


以下是已激活状态:
图片19.png
2021-8-22 00:43



插件安装成功了:
图片20.png
2021-8-22 00:43



插件“thold”:
图片21.png
2021-8-22 00:44


图片23.png
2021-8-22 00:46



插件“monitor”:
图片24.png
2021-8-22 00:46















Cacti使用SNMPv2c监控Ubuntu18.04.5

被监控主机的信息:
zhuohua@zhuohua_ubuntu:~$ cat /etc/issue
Ubuntu 18.04.5 LTS \n \l

zhuohua@zhuohua_ubuntu:~$ uname -r
4.15.0-112-generic

zhuohua@zhuohua_ubuntu:~$ hostname
zhuohua_ubuntu
zhuohua@zhuohua_ubuntu:~$ cat /etc/hostname
zhuohua_ubuntu


初始化系统管理员root的密码:
zhuohua@zhuohua_ubuntu:~$ sudo passwd root
[sudo] password for zhuohua:  #先输入当前用户的密码
Enter new UNIX password:  #输入系统管理员root的新密码
Retype new UNIX password:  #输入系统管理员root的新密码
passwd: password updated successfully


切换到系统管理员root:
zhuohua@zhuohua_ubuntu:~$ su - root
Password:  #输入系统管理员root的密码
root@zhuohua_ubuntu:~# pwd
/root


查看网卡的IP地址:
root@zhuohua_ubuntu:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.168.143  netmask 255.255.255.0  broadcast 192.168.168.255
        inet6 fe80::20c:29ff:fead:cd7c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ad:cd:7c  txqueuelen 1000  (Ethernet)
        RX packets 1163  bytes 84943 (84.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 674  bytes 88618 (88.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 291  bytes 23498 (23.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 291  bytes 23498 (23.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0



被监控主机安装SNMP相关软件包:(要连接公网)
root@zhuohua_ubuntu:~# sudo apt-get update

root@zhuohua_ubuntu:~# apt-get -y install snmpd snmp snmp-mibs-downloader


SNMP服务默认已启动:
systemctl status snmpd
图片1.png
2021-8-22 00:53


SNMP服务默认会开机自动启动:
root@zhuohua_ubuntu:~# systemctl is-enabled snmpd
enabled


本机测试SNMP服务是否正常:(默认就是使用SNMPv2c
root@zhuohua_ubuntu:~# snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.1.1
iso.3.6.1.2.1.1.1.0 = STRING: "Linux zhuohua_ubuntu 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64"


修改SNMP服务的两个配置文件:
root@zhuohua_ubuntu:~# vi /etc/snmp/snmpd.conf

view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1
修改为:
#view   systemonly  included   .1.3.6.1.2.1.1
#view   systemonly  included   .1.3.6.1.2.1.25.1
view   systemonly  included   .1

#  Listen for connections from the local system only
agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
#agentAddress udp:161,udp6:[::1]:161
修改为:
#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
#agentAddress udp:161,udp6:[::1]:161

#SNMP Community默认就是 public
#rocommunity public  localhost
#  Default access to basic system info
rocommunity public  default    -V systemonly
#  rocommunity6 is for IPv6
rocommunity6 public  default   -V systemonly


root@zhuohua_ubuntu:~# vi /etc/snmp/snmp.conf
mibs :
修改为:
#mibs :


重启SNMP服务:
root@zhuohua_ubuntu:~# systemctl restart snmpd


本地测试:
root@zhuohua_ubuntu:~# snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.4.3.0
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 2097148 kB

root@zhuohua_ubuntu:~# sudo netstat -antup | grep 161
udp        0      0 0.0.0.0:161             0.0.0.0:*                           16374/snmpd


Ubuntu的防火墙默认是关闭状态:
root@zhuohua_ubuntu:~# sudo ufw status
Status: inactive



######
在Cacti服务器远程测试被监控主机的SNMP服务是否正常:
[root@redhat8 ~]# snmpwalk -v 2c -c public 192.168.168.143 1.3.6.1.2.1.1.1
SNMPv2-MIB::sysDescr.0 = STRING: Linux zhuohua_ubuntu 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64

[root@redhat8 ~]# snmpwalk -v 2c -c public 192.168.168.143 .1.3.6.1.4.1.2021.4.3.0
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 2097148 kB



######
Cacti服务器导入新的Linux主机模板:( Import Templates )
图片2.png
2021-8-22 00:57


上传模板:
图片3.png
2021-8-22 00:57

注释:文件从Windows客户端上传的。

导入模板:
图片4.png
2021-8-22 00:58


导入成功:
图片5.png
2021-8-22 00:58




######
Cacti服务器添加被监控主机:

1. 添加主机:
图片6.png
2021-8-22 00:58


图片7.png
2021-8-22 00:58

备注:不要用中文。

图片8.png
2021-8-22 00:59


图片9.png
2021-8-22 00:59

备注:
SNMP Version使用 SNMPv2c
SNMP Community使用 public


2. 为主机添加图形:
保存成功后,点击右上边的 *Create Graphs for this Host (为这个主机新建图形)
图片10.png
2021-8-22 01:00


将需要的选项右边的复选框勾上,对应项就会变成黄色;选好后,点击右下角的 Create
图片11.png
2021-8-22 01:00


图片12.png
2021-8-22 01:00



3.把主机添加到树:
点击导航栏中“Management”下的“Graph Trees”,再点击右上角的“Add”:(创建新的树)
图片13.png
2021-8-22 01:00


图片14.png
2021-8-22 01:01


进入指定的树,点击“Add”:
图片15.png
2021-8-22 01:01


主机成功添加到树:
图片16.png
2021-8-22 01:01



正常的话,图形是有数值出现的:(需要等一段时间,才会出现的)
图片17.png
2021-8-22 01:02


图片18.png
2021-8-22 01:02






######
Cacti使用游客用户:(不能更改配置,但可以查看图形数据等等)
图片19.png
2021-8-22 01:02


图片20.png
2021-8-22 01:03


把guest改为自定义用户:
图片21.png
2021-8-22 01:03


自定义用户的权限:
图片22.png
2021-8-22 01:03



使用游客用户登录Cacti:
图片23.png
2021-8-22 01:03


图片24.png
2021-8-22 01:04


图片25.png
2021-8-22 01:04


图片26.png
2021-8-22 01:04






相关文章:
CentOS8_lnmp1.7_LNMPA_安装Cacti
Oracle Linux6.9安装Cacti

Zabbix5.0.12_使用SNMP监控iKuai路由器(SNMPv2c+SNMP OID)

MySQL的字符集
Zabbix使用自编译/预编译Agent监控Ubuntu18.04.5

返回列表