您的位置:首页 > 运维架构 > Linux

Linux 搭建Cacti 监控服务器

2018-01-10 17:49 423 查看
Cacti 监控服务器
搭建Cacti监控服务器 192.168.4.21

一, 部署运行环境 LAMP/LNMP

二,安装Cacti
2.1 创建存储信息的库 cactidb
# mysql -uroot -p123456
MariaDB [(none)]> create database cactidb;
2.2 授权存储数据时,连接数据库服务器的用户 test@
MariaDB [(none)]> grant all on cactidb.* to test@'localhost' identified by "123456";
//测试授权
# mysql -utest -p123456
2.3 安装Cacti
//安装所需的软件包
# ls
cacti-0.8.8h.tar.gz monitor-v1.3-1.tgz thold-v0.5.0.tgz
cacti-spine-0.8.8h.tar.gz settings-v0.71-1.tgz
//将cacti程序安装在网络目录下
# tar -zxf cacti-0.8.8h.tar.gz
# ls cacti-0.8.8h///网页文件
# mv cacti-0.8.8h /var/www/html/cacti
//更改所属组,所属者
# chown -R apache:apache /var/www/html/cacti/
2.4 访问WEB页面 做初始化配置
2.4.1 创建存储配置信息的表
//导入cacti.sql 中的表记录
# mysql -utest -p123456 cactidb < /var/www/html/cacti/cacti.sql
# mysql -utest -p123456 cactidb
MariaDB [cactidb]> show tables;
2.4.2 修改配置文件 设置存储配置信息使用的库
# vim /var/www/html/cacti/include/config.php
# sed -n '26,32p;' /var/www/html/cacti/include/config.php
$database_type = "mysql";//使用的数据库软件
$database_default = "cactidb";//存储信息的库
$database_hostname = "localhost";//主机名
$database_username = "test";//授权用户名
$database_password = "123456";//授权用户密码
$database_port = "3306";//监听端口
$database_ssl = false;//默认不加密

2.4.3 访问webhttp://192.168.4.21/cacti




会发现 报红 是因为没有安装依赖包



2.4.4 安装依赖的软件包
# yum list | grep -i rrdtool//绘图工具
rrdtool.i686 1.4.8-9.el7 dvd
rrdtool.x86_64 1.4.8-9.el7 dvd
# yum -y install rrdtool



# yum list | grep -i snmp
# yum -y install net-snmp*
# rpm -qa | grep -i snmp
net-snmp-agent-libs-5.7.2-24.el7.x86_64
net-snmp-devel-5.7.2-24.el7.x86_64
net-snmp-libs-5.7.2-24.el7.x86_64
net-snmp-5.7.2-24.el7.x86_64
net-snmp-utils-5.7.2-24.el7.x86_64



初始账户密码 admin admin



然后会强制重置密码 123456



web 页面的设置都会存储到数据库

# mysql -utest -p123456 cactidb





2.4.5 CACTI软件的使用
黑色背景 分类
蓝颜色字 具体配置项
1 查看软件提供的监控模版
Templates
Graph Templates
Host Templates
Data Templates

2 查看监控主机
Management
Devices



三,安装高速采集器 spine
3.1 安装 spine
# tar -zxf cacti-spine-0.8.8h.tar.gz
# cd cacti-spine-0.8.8h/
# ./configure --help
--with-mysql MySQL base directory [[/usr/local/mysql]]

# ./configure --with-mysql
configure: error: Cannot find MySQL header files under yes

只要是库文件和头文件报错 就是没有安装
mariadb-devel
# yum list | grep mariadb
# make && make install
# ls /usr/local/spine/
bin etc
# ls /usr/local/spine/bin/
spine//采集器程序
# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf

3.2 修改 spine 程序的配置文件 设置使用的数据库服务器
# vim /etc/spine.conf
# tail -5 /etc/spine.conf
DB_Host localhost
DB_Database cactidb
DB_User test
DB_Pass 123456
DB_Port 3306

3.3 配置 cacti 调用 spine
# ls /usr/local/spine/bin/spine /usr/local/spine/bin/spine




四,配置监控主机配置4.1 监控远端主机
a,配置被监控端1 运行snmpd服务:装包 修改配置文件 启动服务# yum -y install net-snmp-*# rpm -qa | grep -i net-snmpnet-snmp-5.7.2-24.el7.x86_64net-snmp-libs-5.7.2-24.el7.x86_64net-snmp-devel-5.7.2-24.el7.x86_64net-snmp-agent-libs-5.7.2-24.el7.x86_64net-snmp-utils-5.7.2-24.el7.x86_64
//允许监控服务器访问服务# sed -i '41s/default/192.168.4.21/' /etc/snmp/snmpd.conf # sed -n '41p' /etc/snmp/snmpd.conf com2sec notConfigUser 192.168.4.21 public//设置访问权限# sed -i '62s/systemview/all/' /etc/snmp/snmpd.conf # sed -n '62p' /etc/snmp/snmpd.conf access notConfigGroup "" any noauth exact all none none//如何找到# sed -i '85s/^#//' /etc/snmp/snmpd.conf # sed -n '85p' /etc/snmp/snmpd.conf view all included .1 80# systemctl start snmpd# systemctl enable snmpdCreated symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.# netstat -pantu | grep snmpdtcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 5649/snmpd udp 0 0 0.0.0.0:161 0.0.0.0:* 5649/snmpd
b,监控服务器配置登录管理页面添加 查看 删除1 添加监控主机 并选择监控模版











2 设置监控项









3 创建图片



4 图像树 监控主机的文件夹 并把监控主机的图片添加到图像数里







5 编写抓取数据的cron任务

# cd /var/www/html/cacti/
# ls rra
# vim /etc/php.ini
# sed -n '878p;' /etc/php.ini
date.timezone = Asia/Shanghai
# php /var/www/html/cacti/poller.php
# ls rra
web12_hdd_free_14.rrd web12_mem_buffers_8.rrd web12_traffic_in_13.rrd
web12_hdd_free_15.rrd web12_mem_swap_9.rrd web12_users_11.rrd
web12_load_1min_10.rrd web12_proc_12.rrd

# crontab -e
# crontab -l
*/5 * * * * php /var/www/html/cacti/poller.php &> /dev/null
# systemctl is-active crond.service
active

6 查看监控图片







4.2 监控本机
a,配置被监控端 本机
1 运行snmpd服务:装包 修改配置文件 启动服务
# sed -n '41p;62p;85p' /etc/snmp/snmpd.conf
com2sec notConfigUser default public
access notConfigGroup "" any noauth exact systemview none none
#view all included .1 80
# sed -i '41s/default/localhost/' /etc/snmp/snmpd.conf
# sed -i '62s/systemview/all/' /etc/snmp/snmpd.conf
# sed -i '85s/^#//' /etc/snmp/snmpd.conf
# sed -n '41p;62p;85p' /etc/snmp/snmpd.conf
com2sec notConfigUser localhost public
access notConfigGroup "" any noauth exact all none none
view all included .1 80
# systemctl start snmpd ;systemctl enable snmpd

登录管理界面进行如下操作(和上面操作几乎相同)
1 添加监控主机 并选择监控模版





2 设置监控项







3 创建图片



4 图像树 监控主机的文件夹 并把监控主机的图片添加到图像数里



5 查看监控图片







4.3 监控报警 (监控服务器 主机21)



4.3.1 安装插件 按照如下监控顺序安装
# tar -zxf monitor-v1.3-1.tgz
# mv monitor /var/www/html/cacti/plugins/
# ls /var/www/html/cacti/plugins
index.php monitor
在图形界面 激活







激活后 会多出一个 monitor 模块



# tar -zxf settings-v0.71-1.tgz
# mv settings /var/www/html/cacti/plugins
# ls /var/www/html/cacti/plugins
index.php monitor settings

# tar -zxf thold-v0.5.0.tgz

# mv thold /var/www/html/cacti/plugins
# ls /var/www/html/cacti/plugins
index.php monitor settings thold



4.3.2 配置监控报警 :
对本机登录的用户数做监控报警
报警方式 是发邮件
报警项 : 登录用户数 警告值 1 错误值 2

具备条件
邮件服务器 localhost
发件人root@localhost
收件人cactiuser@localhost
# systemctl restart postfix.service
# systemctl enable postfix
# useradd cactiuser
# grep cactiuser /etc/passwd
cactiuser:x:1002:1003::/home/cactiuser:/bin/bash
测试 邮件可用
# mail -s 'test' cactiuser < /etc/hosts
# mail -u cactiuser
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/cactiuser": 1 message 1 new
>N 1 root Tue Jan 9 21:57 19/765 "test"
&

配置监控报警:
1 创建消息列表
console ---> Management ---> Notification Lists ---> Add



name消息列表名description 描述emails 邮件地址




2 设置监控报警项
console ---> Management ---> Thresholds ---> add











3 指定服务器 (安装插件后 默认不做配置 就是使用本机)





添加在线用户





在监控服务器 cactiuser 邮箱中 收到 如下警告信息

# mail -u cactiuser
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/cactiuser": 2 messages 1 new 2 unread
U 1 root Tue Jan 9 21:57 20/775 "test"
>N 2 Cacti Tue Jan 9 22:10 242/16425 "WARNING: localhost - "
& 2
Message 2:
From Cacti@localhost.localdomain Tue Jan 9 22:10:01 2018
Return-Path: <Cacti@localhost.localdomain>
X-Original-To: cactiuser@localhost
Delivered-To: cactiuser@localhost.localdomain
From: Cacti <Cacti@localhost.localdomain>
To: cactiuser@localhost.localdomain
Date: Wed, 10 Jan 2018 11:10:01 +0800
X-Mailer: Cacti-Thold-v0.5
User-Agent: Cacti-Thold-v0.5
Subject: WARNING: localhost - Logged in Users [users] [users] went above thresho
ld of 1 with 2
Content-Type: multipart/related; boundary="--REL__MAILER_12139_1515553801_736526
0"
Status: R

Part 1:
Content-Type: multipart/alternative; boundary="--ALT__MAILER_12139_1515553801_73
65260"

Content-Type: text/plain; charset="UTF-8"

A warning has been issued that requires your attention.

Host: localhost (127.0.0.1)
URL: http://192.168.4.21/cacti//graph.php?local_graph_id=21&rra_id=1 Message: WARNING: localhost - Logged in Users [users] [users] went above thresho
ld of 1 with 2

Part 2:
Content-ID: <12139_1515553801_7364490@localhost>
Content-Type: image/png
Content-Disposition: inline; filename="21.png"

图形界面 检验当前邮件服务是否可用



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 搭建 Cacti