監控軟件Cacti搭建php
1、環境準備mysql
一、安裝epel擴展源linux
[root@cacti ~]# yum install -y epel-release
二、搭建lamp環境sql
[root@cacti ~]# yum install -y httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng-devel [root@cacti ~]# /etc/init.d/httpd start 正在啓動 httpd: [肯定] [root@cacti ~]# /etc/init.d/mysqld start 初始化 MySQL 數據庫: Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h cacti password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [肯定] 正在啓動 mysqld: [肯定]
三、安裝cacti監控主機數據庫
[root@cacti ~]# yum install -y cacti net-snmp net-snmp-utils rrdtool net-snmp-devel net-snmp-libs lm-sensors php-xml zlib libpng freetype cairo-devel pango-devel gd [root@cacti ~]# /etc/init.d/snmpd start 正在啓動 snmpd: [肯定] [root@cacti ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.73 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; mysql> grant all on cacti.* to 'cactiuser'@'localhost' identified by 'cactiuser'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@cacti ~]# mysql -u root cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql [root@cacti ~]# vim /usr/share/cacti/include/config.php $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactiuser"; $database_port = "3306"; $database_ssl = false; [root@cacti ~]# vim /etc/httpd/conf.d/cacti.conf Deny from all 修改成 Allow from all [root@cacti ~]# /etc/init.d/httpd restart 中止 httpd: [肯定] 正在啓動 httpd: [肯定]
四、經過瀏覽器訪問vim
若是訪問不了,請檢查主機的iptables和selinux
瀏覽器
圖:一bash
圖:二服務器
圖:三ide
到了登錄,默認的帳號爲admin,密碼爲admin
圖:四
登錄以後,系統會強制用戶更改密碼
圖:五
圖:六
點擊graphs-Default Tree-Host Localhost,進入系統監控界面
咱們看到監控界面,沒有出圖,設置一下出圖
[root@cacti ~]# /usr/bin/php /usr/share/cacti/poller.php OK u:0.00 s:0.00 r:0.00 OK u:0.00 s:0.00 r:0.01 OK u:0.00 s:0.00 r:0.03 OK u:0.00 s:0.00 r:0.05 OK u:0.00 s:0.00 r:0.08 06/13/2015 09:59:49 PM - SYSTEM STATS: Time:0.1974 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5 [root@cacti ~]# crontab -e # 讓命令每5分鐘執行一次 */5 * * * * /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
咱們在刷新一下,圖就出來了
圖:八
數據須要等待一下子,才能出來
接下來咱們添加被監控的主機
# 在被監控的主機上安裝 [root@rsa ~]# yum install -y net-snmp lm_sensors [root@rsa ~]# vim /etc/snmp/snmpd.conf #syslocation Unknown (edit /etc/snmp/snmpd.conf) syslocation 192.168.1.118 # group context sec.model sec.level prefix read write notif access notConfigGroup "" any noauth exact all none none view all included .1 80 去掉註釋符「#」 [root@rsa ~]# /etc/init.d/snmpd start 正在啓動 snmpd: [肯定]
依次點擊console -> Devices -> add,添加主機
開始添加被監控主機的信息,填寫完畢,點擊Create
建立完畢,看是否通訊正常,建立完主機,建立要監控的項目點擊 Create Graphs for this Host,
根據須要,去選擇要監控的項目
監控項目添加完畢,將主機添加到監控主幹線上,點擊左側Graph Trees
到主界面查看,是否添加成功,最好在監控服務器上刷新一下
[root@cacti ~]# /usr/bin/php /usr/share/cacti/poller.php --force OK u:0.00 s:0.00 r:0.00 OK u:0.00 s:0.00 r:0.01 OK u:0.00 s:0.00 r:0.03 OK u:0.00 s:0.00 r:0.05 OK u:0.00 s:0.00 r:0.08 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.09 OK u:0.00 s:0.00 r:0.10 06/13/2015 05:16:53 PM - SYSTEM STATS: Time:0.2109 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:20 RRDsProcessed:17
成功添加!!