Centos7安裝cacti 和nagios

cacti

一、環境準備

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

[root@localhost~]#hostnamectlset-hostnamenms01[root@nms01~]#getenforceDisabled[root@nms01~]#timedatectlset-timezoneAsia/Shanghai[root@nms01~]#systemctlstopfirewalld.service[root@nms01~]#systemctldisablefirewalld.service


1.安裝httpd

[root@nms01~]#yuminstallhttpdhttpd-devel-y[root@nms01~]#systemctlenablehttpd.serviceCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/httpd.serviceto/usr/lib/systemd/system/httpd.service.[root@nms01~]#systemctlstarthttpd.service


2.安裝並設置數據庫mariadb

[root@localhost~]#yuminstallmariadbmariadb-servermariadb-devel-y[root@nms01~]#vi/etc/my.cnf.d/cacti.cnf[mysqld]bind-address=10.0.0.103default-storage-engine=innodbinnodb_file_per_tablemax_connections=4096collation-server=utf8_general_cicharacter-set-server=utf8

[root@nms01~]#systemctlenablemariadb.serviceCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/mariadb.serviceto/usr/lib/systemd/system/mariadb.service.[root@nms01~]#systemctlstartmariadb.service[root@nms01~]#mysql_secure_installation[root@nms01~]#[root@nms01~]#mysql-uroot-pEnterpassword:MariaDB[(none)]>createdatabasecacti;QueryOK,1rowaffected(0.00sec)MariaDB[(none)]>grantalloncacti.*tocacti@localhostidentifiedby'cacti';QueryOK,0rowsaffected(0.00sec)MariaDB[(none)]>flushprivileges;QueryOK,0rowsaffected(0.00sec)


3.安裝php

[root@nms01~]#yuminstallphp-mysqlphp-pearphp-commonphp-gdphp-develphpphp-mbstringphp-cli-y


4.安裝php-snmp、net-snmp

[root@nms01~]#yuminstallphp-snmpnet-snmp-utilsnet-snmp-libsnet-snmp-devel-y[root@nms01~]#systemctlenablesnmpd.serviceCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/snmpd.serviceto/usr/lib/systemd/system/snmpd.service.[root@nms01~]#systemctlstartsnmpd.service


5.安裝rrdtool

[root@nms01~]#yuminstallrrdtool-y



二、下載安裝cacti

[root@nms01~]#yuminstallwgetgcc-y[root@nms01~]#wgethttp://www.cacti.net/downloads/cacti-0.8.8h.tar.gz[root@nms01~]#tar-xvfcacti-0.8.8h.tar.gz-C/usr/local/[root@nms01local]#ln-scacti-0.8.8hcacti[root@nms01local]#vicacti/include/config.php$database_type="mysql";$database_default="cacti";$database_hostname="localhost";$database_username="cacti";$database_password="cacti";$database_port="3306";$database_ssl=false;[root@nms01local]#useraddcacti-d/usr/local/cacti[root@nms01local]#chown-Rcacti/usr/local/cacti/[root@nms01local]#chgrp-Rcacti/usr/local/cacti[root@nms01local]#chmod-R755/usr/local/cacti/[root@nms01local]#mysql-ucacti-pcacti</usr/local/cacti/cacti.sqlEnterpassword:###################################################################[root~]#firewall-cmd--permanent--zone=public--add-service=http[root~]#firewall-cmd--reload###################################################################[root@nms01local]#vi/etc/httpd/conf.d/cacti.confAlias/cacti/usr/local/cacti<Directory/usr/local/cacti/><IfModulemod_authz_core.c>#httpd2.4Requireallgranted</IfModule><IfModule!mod_authz_core.c>#httpd2.2Orderdeny,allowDenyfromallAllowfromall</IfModule></Directory>[root@nms01local]#systemctlrestarthttpd.service[root@nms01local]#vi/etc/cron.d/cacti*/5****cacti/usr/bin/php/usr/local/cacti/poller.php>/dev/null2>&1


訪問web頁設置

http://10.0.0.103/cacti/install/



三、下載安裝spine

[root@nms01~]#wgethttp://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz[root@nms01~]#tarzxvfcacti-spine-0.8.8h.tar.gz[root@nms01~]#cdcacti-spine-0.8.8h[root@nms01cacti-spine-0.8.8h]#./configure[root@nms01cacti-spine-0.8.8h]#make[root@nms01cacti-spine-0.8.8h]#makeinstall[root@nms01~]#cp/usr/local/spine/etc/spine.conf.dist/usr/local/spine/etc/spine.conf[root@nms01~]#vi/usr/local/spine/etc/spine.confDB_HostlocalhostDB_DatabasecactiDB_UsercactiDB_PasscactiDB_Port3306[root@nms01~]#/usr/local/spine/bin/spine09/02/201604:58:04PM-SPINE:Poller[0]FATAL:Unabletoreadconfigurationfile!(Spineinit)[root@nms01~]#cp/usr/local/spine/etc/spine.conf/etc/spine.conf[root@nms01~]#/usr/local/spine/bin/spineSPINE:Usingspineconfigfile[/etc/spine.conf]SPINE:Version0.8.8hstartingSPINE:Time:0.0961s,Threads:5,Hosts:2


其他

1.查看文件屬於那個包

[root@nms01local]#yumprovidessnmpwalk




nagios

1.安裝相關依賴包

[root@nms01~]#yuminstallhttpdphpphp-cligccglibcglibc-commongdgd-develnet-snmpopenssl-develwgetunzip-y

2.創建用戶和組

[root@nms01~]#useraddnagios[root@nms01~]#groupaddnagcmd[root@nms01~]#usermod-a-Gnagcmdnagios[root@nms01~]#usermod-a-Gnagcmdapache


3.下載nagios和nagios-plugins

[root@nms01~]#wgethttps://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz[root@nms01~]#wgethttp://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

4.解壓安裝nagios

[root@nms01~]#tarzxvfnagios-4.1.1.tar.gz[root@nms01~]#cdnagios-4.1.1[root@nms01nagios-4.1.1]#./configure--with-command-group=nagcmd[root@nms01nagios-4.1.1]#makeall[root@nms01nagios-4.1.1]#makeinstall[root@nms01nagios-4.1.1]#makeinstall-init[root@nms01nagios-4.1.1]#makeinstall-config[root@nms01nagios-4.1.1]#makeinstall-commandmode[root@nms01nagios-4.1.1]#makeinstall-webconf

5.修改httpd.conf文件

[root@nms01~]#vi/etc/httpd/conf/httpd.conf<IfModuledir_module>DirectoryIndexindex.html,index.php</IfModule>


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

[root@nms01~]#htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadminNewpassword:Re-typenewpassword:Addingpasswordforusernagiosadmin


7.安裝nagios-plugins

[root@nms01~]#tarxfnagios-plugins-2.1.1.tar.gz[root@nms01~]#cdnagios-plugins-2.1.1[root@nms01nagios-plugins-2.1.1]#./configure--with-nagios-user=nagios--with-nagios-group=nagios--with-openssl[root@nms01nagios-plugins-2.1.1]#makeall[root@nms01nagios-plugins-2.1.1]#makeinstall


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

[root@nms01~]#systemctlstarthttpd.service[root@nms01~]#systemctlenablehttpd.service[root@nms01~]#servicenagiosstart[root@nms01~]#chkconfignagioson[root@nms01~]#chkconfignagios--listnagios0:off1:off2:on3:on4:on5:on6:off


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

[root@nms01~]#firewall-cmd--zone=public--add-port=80/tcp--permanent[root@nms01~]#firewall-cmd--reload



10.訪問驗證

http://10.0.0.103/nagios/