Linux 搭建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 訪問web
http://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-snmp
net-snmp-5.7.2-24.el7.x86_64
net-snmp-libs-5.7.2-24.el7.x86_64
net-snmp-devel-5.7.2-24.el7.x86_64
net-snmp-agent-libs-5.7.2-24.el7.x86_64
net-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 snmpd
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
# netstat -pantu | grep snmpd
tcp 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 [email protected] Tue Jan 9 22:10:01 2018
Return-Path: <[email protected]>
X-Original-To: cactiuser@localhost
Delivered-To: [email protected]
From: Cacti <[email protected]>
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 監控服務器