Cacti


Cacti

蛮麻烦的

环境

服务端:Centos7 被监控端:win7

Cacti服务端搭建

安装Mysql

rpm -Uvh http://repo.mysql.com/mysql57-community-release-el7.rpm

yum clean all && yum makecache

安装LAMP

yum install httpd mysql-server php php-gd php-mysql -y

安装RRDtool

yum install rrdtool rrdtool-devel.x86_64 rrdtool-perl.x86_64 -y

安装SNMP

yum install net-snmp-utils -y

部署LAMP

*/usr/bin/mysql –initialize –basedir=/usr/share/mysql –datadir=/var/lib/mysql/data/ 初始化Mysql*
systemctl start mysqld
vim /etc/my.cnf 在末行添加 skip-grant-tables 跳过密码验证
systemctl restart mysqld
mysql -uroot -p
mysql>use mysql; 注意要写分号
mysql>update user set authentication_string=password(123456) where user=‘root’;
exit退出到root vim /etc/php.ini  
date.timezone = “Asia/Shanghai”添加时区
systemctl start httpd
vi /var/www/html/phpinfo.php
添入测试文本<?php phpinfo(); ?> 
浏览器访问ip/phpinfo.php  (firewalld)

配置cacti

vim /etc/my.cnf添加
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
重启systemctl restart mysqld
mysql -uroot -p
mysql>create database cacti character set utf8;
mysql>ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
exit退出至root /etc/my.cnf 注释掉#skip-grant-tables 重启mysql
进入mysql
mysql>set global validate_password_policy=LOW;
mysql>set global validate_password_length=6;
mysql>alter user ‘root’@‘localhost’ identified by ‘123456;
mysql>grant all privileges on cacti.* to cacti@localhost identified by ‘password’ ;
mysql>grant select on mysql.time_zone_name to cacti@localhost identified by ‘password’;
mysql>flush privileges;

我的配置过程

导入cacti数据库
官网下载包跳转
解压到目录下

mysql -uroot -p123456
mysql>use cacti ;
mysql>source /root/cacti-1.2.1/cacti.sql ;/var/www/html/下创建mkdir cacti
cp -r /root/cacti-1.2.1/* /var/www/html/cacti

vi /var/www/html/cacti/include/config.php修改配置信息
$database_type = ‘mysql’;
$database_default = ‘cacti’;
$database_hostname = ‘localhost’;
$database_username = ‘cacti’;
$database_password = ‘password’;
$database_port = ‘3306’;
$database_ssl = false;

增加cacti用户权限
useradd -s /sbin/nologin cacti
mkdir /var/www/html/cacti/rra/log
chown -R cacti /var/www/html/cacti/rra/log/

配置定时任务crontab
crontab –e
添入内容*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
crontab -l有输出即正常
systemctl enable crond
systemctl start crond

安装其他相关组件
https://oss.oetiker.ch/rrdtool/pub/rrdtool-1.7.0.tar.gz
https://www.cacti.net/downloads/spine/cacti-spine-1.2.1.tar.gz
编译时需要的软件包
yum install glib2-devel cairo-devel libxml2-devel pango pango-devel help2man

解压后cd rrdtool-1.7.0
./configure --prefix=/usr/local/rrdtool
make
make install

web初始化cacti
setenforce 0关闭防火墙 临时关闭或
vi /etc/selinux/config  将SELINUX=enforcing改为SELINUX=disabled 永久关闭
浏览器访问ip/cacti
log报错修改:chmod 777 /var/www/html/cacti/log
默认密码admin/admin

一些报错修改(不修改不能继续安装)

1.报错:Your MySQL TimeZone database is not populated. Please populate this database before proceeding.

修改:mysql_tzinfo_to_sql /usr/share/zoneinfo/Asia/Shanghai Shanghai | mysql -u root -p mysql

2.报错:A valid timezone that matches MySQL and the system

修改:vim /etc/php.ini 将date.timezone前面的分号去掉(重启httpd)

3.报错:某些php模块显示没有安装

修改:yum install -y php-缺少的模块名,安装之后systemctl restart httpd并刷新cacti网页

4.Set global max_allowed_packet=17700000;

5.权限问题(不可写入)chmod a+w /var/www/html/cacti/resource/snmp_queries/或777

6.cacti无法显示图像:chmod 777 -R /var/www/html/cacti/rra并service snmpd restart

7.监控本机localhost,snmp返回失败:修改主机名为127.0.0.1而不是localhost

ok

被监控端Win7

控制面板开启SNMP服务

设置服务团体public,允许任何主机访问

关闭防火墙


yum install perl-devel perl-CPAN perl-YAML

perl -MCPAN -e shell

cpan> install LWP::UserAgent

被监控端Centos7

yum -y install net-snmp net-snmp-utils

/etc/snmp/snmpd.conf

com2sec notConfigUser default public

access notConfigGroup ‘’’’ any noauth exact all none none

去掉注释#view all included .1 80

加一行view all included .1

service snmpd start

测试 snmpwalk -v 2c- c public 192.168.106.xx

监控ESXI

vsphere client打开esxi的ssh服务

putty上去配置snmp(/etc/vmware/snmp.xml)

<config>
<snmpSettings>
<enable>true</enable> #将标签false改为true.
<port>161</port>
<EnvEventSource>indications</EnvEventSource>
<loglevel>info</loglevel>
<communities>public</communities>  #社区名称
<targets></targets>
</snmpSettings>
</config>

cacti添加esxi主机(同一网段)

监控Cisco交换机

交换机用com口转usb线连接到win,putty通过com3口登陆进行snmp的配置(网段ip)

服务器添加交换机

配置邮件报警

qq邮箱开启smtp并获得授权码

在cacti管理界面输入相应信息并发送测试邮件

升级Cacti

因插件版本问题,将原本的Cacti1.2.1升级到最新版1.2.12(2020.5.3)

备份数据库 mysqldump -uroot -p123456 -l --add-drop-table cacti > cacti_old.sql
备份cacti根目录 mv /var/www/html/cacti /var/www/html/cacti_old
官网下载最新版包mv cacti-1.2.12/ /var/www/html/cacti
vim /data/www/cacti/include/config.php 数据库配置同前
cp /var/www/html/cacti_old/rra/* /var/www/html/cacti/rra/
cp -u /var/www/html/cacti_old/scripts/* /var/www/html/cacti/scripts/
cp -u -R /var/www/html/cacti_old/resource/* /var/www/html/cacti/resource/

刷新管理平台界面并安装

配置Thold警报机制

从cacti的github界面下载插件thold包跳转

将包解压后放在/var/www/html/cacti/plugins路径下并改名为thold

刷新控制台,安装插件


根据图形模版来设置阈值

配置开源邮件服务器EwoMail接收报警

EwoMail官方文档跳转

邮件smtp配置及效果图


线上的离线环境centos系统安装snmp服务

下载rpm包,根据依赖一个一个安装

包的下载地址:https://rpmfind.net/

示例:

轮询器优化cmd->spine

官网下载最新包 源码编译时报错:c compiler cannot create executables

一开始以为是gcc没装好,remove后重装还是报错,找了十来篇文章无果,突然看到一篇

查找原因,查看config.log 日志
真正的错误并不在这里,而是在最后一个错误出现的地方
我遇到的错误是:   “collect2: ld returned 1 exit status”
因为缺少了动态库文件。
我这里缺少的是lssl,就是openssl的库文件。
使用命令yum install -y openssl-devel(前面没装的原因)

本来开心的一,又报错

configure:error: Cannot find SNMP headers.  Use--with-snmp= to specify non-default path.
网上说要./configure --prefix=/usr/local/spine --with-snmp=/usr/local/net-snmp
我find了一下,发现两个路径都不对,文章还都是copy来copy去的,一模一样,继续找下去终于正解
解决办法:# yum install -y net-snmp-devel

配置

cp /usr/local/spine/etc/spine.conf.dist  /usr/local/spine/etc/spine.conf
vi /usr/local/spine/etc/spine.conf
填写数据库信息,即Cacti数据库
DB_Host         localhost
DB_Database     cacti
DB_User         cacti
DB_Pass         password
DB_Port         3306
测试是否正常 /usr/local/spine/bin/spine

文章作者: Ricechips
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Ricechips !
 上一篇
Opennebula Opennebula
Opennebula网上的资料也太少了吧! 环境 主控端服务器:Centos7 192.168.106.201 节点服务器(虚拟机):Centos7 192.168.106.2 虚拟机里面的虚拟机:ttylinux (chop wood
2020-08-20 Ricechips
下一篇 
Samba-AD Samba-AD
Samba-AD域控 环境搭建官方文档:依赖搭建步骤 configure使报错:未找到GnuTLS(查询文档,明确要求要从外部获取)wget http://www.ring.gr.jp/pub/net/gnupg/gnutls/v3.6/
2020-08-20 Ricechips
  目录