dthre 发表于 2016-9-9 11:18:52

Centos7安裝cacti 和nagios

Centos7安裝cacti 和nagios
cacti

一、環境準備
0.設置主機名稱,SELINUX,防火墻以及時區

1
2
3
4
5
6
# hostnamectl set-hostname nms01
# getenforce
Disabled
# timedatectl set-timezone Asia/Shanghai
# systemctl stop firewalld.service
# systemctl disable firewalld.service





1.安裝httpd

1
2
3
4
# yum install httpd httpd-devel -y
# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# systemctl start httpd.service





2.安裝並設置數據庫mariadb

1
2
3
4
5
6
7
8
9
# yum install mariadb mariadb-server mariadb-devel -y
# vi /etc/my.cnf.d/cacti.cnf

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





1
2
3
4
5
6
7
8
9
10
11
12
13
# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# systemctl start mariadb.service
# mysql_secure_installation
#
# 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 cacti@localhost 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

1
# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli -y





4.安裝php-snmp、net-snmp

1
2
3
4
# yum install php-snmp net-snmp-utils net-snmp-libs net-snmp-devel -y
# systemctl enable snmpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
# systemctl start snmpd.service





5.安裝rrdtool

1
# yum install rrdtool -y






二、下載安裝cacti

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# yum install wget gcc-y
# wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
# tar -xvf cacti-0.8.8h.tar.gz -C /usr/local/
# ln -s cacti-0.8.8h cacti
# 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;
# useradd cacti -d /usr/local/cacti
# chown -R cacti /usr/local/cacti/
# chgrp -R cacti /usr/local/cacti
# chmod -R 755 /usr/local/cacti/
# mysql -ucacti -p cacti </usr/local/cacti/cacti.sql
Enter password:
###################################################################
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload
###################################################################
# 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>
# systemctl restart httpd.service
# vi /etc/cron.d/cacti
*/5 * * * *    cacti   /usr/bin/php /usr/local/cacti/poller.php > /dev/null 2>&1





訪問web頁設置

1
http://10.0.0.103/cacti/install/






三、下載安裝spine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz
# tar zxvf cacti-spine-0.8.8h.tar.gz
# cd cacti-spine-0.8.8h
# ./configure
# make
# make install
# cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
# vi /usr/local/spine/etc/spine.conf
DB_Host         localhost
DB_Database   cacti
DB_User         cacti
DB_Pass         cacti
DB_Port         3306
# /usr/local/spine/bin/spine
09/02/2016 04:58:04 PM - SPINE: Poller FATAL: Unable to read configuration file! (Spine init)
# cp /usr/local/spine/etc/spine.conf /etc/spine.conf
# /usr/local/spine/bin/spine
SPINE: Using spine config file
SPINE: Version 0.8.8h starting
SPINE: Time: 0.0961 s, Threads: 5, Hosts: 2





其他
1.查看文件屬於那個包

1
# yum provides snmpwalk







nagios
1.安裝相關依賴包

1
# yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip -y




2.創建用戶和組

1
2
3
4
# useradd nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache





3.下載nagios和nagios-plugins

1
2
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
# wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz




4.解壓安裝nagios

1
2
3
4
5
6
7
8
9
# tar zxvf nagios-4.1.1.tar.gz
# cd nagios-4.1.1
# ./configure --with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf




5.修改httpd.conf文件

1
2
3
4
# vi /etc/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html,index.php
</IfModule>





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

1
2
3
4
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin





7.安裝nagios-plugins

1
2
3
4
5
# tar xf nagios-plugins-2.1.1.tar.gz
# cd nagios-plugins-2.1.1
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
# make all
# make install





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

1
2
3
4
5
6
# systemctl start httpd.service
# systemctl enable httpd.service
# service nagios start
# chkconfig nagios on
# chkconfig nagios --list
nagios         0:off1:off2:on3:on4:on5:on6:off





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

1
2
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --reload






10.訪問驗證

1
http://10.0.0.103/nagios/






页: [1]
查看完整版本: Centos7安裝cacti 和nagios