Centos7安裝cacti 和nagios

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7安裝cacti 和nagios相关的知识,希望对你有一定的参考价值。

Centos7安裝cacti 和nagios

cacti

 

一、環境準備

0.設置主機名稱,SELINUX,防火墻以及時區

[[email protected] ~]# hostnamectl set-hostname nms01
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# timedatectl set-timezone Asia/Shanghai
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service


1.安裝httpd

[[email protected] ~]# yum install httpd httpd-devel -y
[[email protected] ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[[email protected] ~]# systemctl start httpd.service


2.安裝並設置數據庫mariadb

[[email protected] ~]# yum install mariadb mariadb-server mariadb-devel -y
[[email protected] ~]# vi /etc/my.cnf.d/cacti.cnf
[mysqld]
bind-address = 10.0.0.103
default-storage-engine = innodb
innodb_file_per_table
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8
[[email protected] ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# mysql_secure_installation 
[[email protected] ~]# 
[[email protected] ~]# mysql -uroot -p
Enter password: 
MariaDB [(none)]> create database cacti;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on cacti.* to [email protected] identified by ‘cacti‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


3.安裝php

[[email protected] ~]# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli -y


4.安裝php-snmp、net-snmp

[[email protected] ~]# yum install php-snmp net-snmp-utils net-snmp-libs net-snmp-devel -y
[[email protected] ~]# systemctl enable snmpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
[[email protected] ~]# systemctl start snmpd.service


5.安裝rrdtool

[[email protected] ~]# yum install rrdtool -y



二、下載安裝cacti

[[email protected] ~]# yum install wget gcc  -y
[[email protected] ~]# wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
[[email protected] ~]# tar -xvf cacti-0.8.8h.tar.gz -C /usr/local/
[[email protected] local]# ln -s cacti-0.8.8h cacti
[[email protected] local]# vi cacti/include/config.php 
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;
[[email protected] local]# useradd cacti -d /usr/local/cacti
[[email protected] local]# chown -R cacti /usr/local/cacti/
[[email protected] local]# chgrp -R cacti /usr/local/cacti
[[email protected] local]# chmod -R 755 /usr/local/cacti/
[[email protected] local]# mysql -ucacti -p cacti </usr/local/cacti/cacti.sql 
Enter password: 
###################################################################
[root~]# firewall-cmd --permanent --zone=public --add-service=http
[root~]# firewall-cmd --reload 
###################################################################
[[email protected] local]# vi /etc/httpd/conf.d/cacti.conf
Alias /cacti    /usr/local/cacti   
<Directory /usr/local/cacti/>
         <IfModule mod_authz_core.c>
 # httpd 2.4
 Require all granted
         </IfModule>
 <IfModule !mod_authz_core.c>
 # httpd 2.2
 Order deny,allow
 Deny from all
 Allow from all
         </IfModule>
</Directory> 
[[email protected] local]# systemctl restart httpd.service
[[email protected] local]# vi /etc/cron.d/cacti
*/5 * * * *    cacti   /usr/bin/php /usr/local/cacti/poller.php > /dev/null 2>&1


訪問web頁設置

http://10.0.0.103/cacti/install/



三、下載安裝spine

[[email protected] ~]# wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz
[[email protected] ~]# tar zxvf cacti-spine-0.8.8h.tar.gz
[[email protected] ~]# cd cacti-spine-0.8.8h
[[email protected] cacti-spine-0.8.8h]# ./configure 
[[email protected] cacti-spine-0.8.8h]# make
[[email protected] cacti-spine-0.8.8h]# make install
[[email protected] ~]# cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
[[email protected] ~]# vi /usr/local/spine/etc/spine.conf
DB_Host         localhost
DB_Database     cacti
DB_User         cacti
DB_Pass         cacti
DB_Port         3306
[[email protected] ~]# /usr/local/spine/bin/spine 
09/02/2016 04:58:04 PM - SPINE: Poller[0] FATAL: Unable to read configuration file! (Spine init)
[[email protected] ~]# cp /usr/local/spine/etc/spine.conf /etc/spine.conf
[[email protected] ~]# /usr/local/spine/bin/spine 
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8h starting
SPINE: Time: 0.0961 s, Threads: 5, Hosts: 2


其他

1.查看文件屬於那個包

[[email protected] local]# yum provides snmpwalk




nagios

1.安裝相關依賴包

[[email protected] ~]# yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip -y

2.創建用戶和組

[[email protected] ~]# useradd nagios
[[email protected] ~]# groupadd nagcmd
[[email protected] ~]# usermod -a -G nagcmd nagios
[[email protected] ~]# usermod -a -G nagcmd apache


3.下載nagios和nagios-plugins

[[email protected] ~]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
[[email protected] ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

4.解壓安裝nagios

[[email protected] ~]# tar zxvf nagios-4.1.1.tar.gz
[[email protected] ~]# cd nagios-4.1.1
[[email protected] nagios-4.1.1]# ./configure --with-command-group=nagcmd
[[email protected] nagios-4.1.1]# make all
[[email protected] nagios-4.1.1]# make install
[[email protected] nagios-4.1.1]# make install-init
[[email protected] nagios-4.1.1]# make install-config
[[email protected] nagios-4.1.1]# make install-commandmode
[[email protected] nagios-4.1.1]# make install-webconf

5.修改httpd.conf文件

[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html,index.php
</IfModule>


6.創建web訪問用戶名和密碼

[[email protected] ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin


7.安裝nagios-plugins

[[email protected] ~]# tar xf nagios-plugins-2.1.1.tar.gz 
[[email protected] ~]# cd nagios-plugins-2.1.1
[[email protected] nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
[[email protected] nagios-plugins-2.1.1]# make all
[[email protected] nagios-plugins-2.1.1]# make install


8.啟動服務並設置自啟動

[[email protected] ~]# systemctl start httpd.service
[[email protected] ~]# systemctl enable httpd.service
[[email protected] ~]# service nagios start
[[email protected] ~]# chkconfig nagios on
[[email protected] ~]# chkconfig nagios --list
nagios         0:off1:off2:on3:on4:on5:on6:off


9.如果防火墻未關閉則做如下配置

[[email protected] ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[[email protected] ~]# firewall-cmd --reload



10.訪問驗證

http://10.0.0.103/nagios/


本文出自 “Eshin” 博客,请务必保留此出处http://eshin.blog.51cto.com/422646/1850695

以上是关于Centos7安裝cacti 和nagios的主要内容,如果未能解决你的问题,请参考以下文章

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvisnagios+cacti整合

Centos7 安装部署Zabbix及邮件告警

centos7.4安装监控软件系列2:nagios

Cacti与nagios结合所需插件的安装与报错处理

Centos 6.7 安张nagios和cacti 并添加监控主机

cacti,zabbix,nagios各自原理及区别