nagios+cacti部署
nagios+cacti部署安装一、说明
闲暇之余,安装nagios+cacti,想看下最终实现效果;本文档规范网络监控系统安装流程及安装内容,供运维人员在部署新的运营环境时参考使用。
二、Nagios的安装
1、下载
#wget
http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz(nagios主程序)
#wgethttp://jaist.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz(监控插件)
#wgethttp://jaist.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz(nrpe插件)
2、需要的基础套件
#rpm-q gcc glibc glibc-common gd gd-devel openssl-devel httpd php
http://s3.运维网.com/wyfs02/M00/54/0F/wKioL1R20dnBMsF5AADzTLe5cu8524.jpg
3、创建用户和组
#useradd nagios
#mkdir /usr/local/nagios
#chown -R nagios.nagios /usr/local/nagios
4、编译安装
#./configure --prefix=/usr/local/nagios
http://s3.运维网.com/wyfs02/M02/54/0F/wKioL1R20fCgBrjFAAKaRuAVVUw188.jpg
#make all
#make install
#make install-init
#make install-commandmode
#make install-config
#make install-webconf
5、创建Apache用户验证文件
创建一个nagiosadmin账户:
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
6、常用的命令
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
7、安装nagios-plugins
#./configure--with-nagios-user=nagios--with-nagios-group=nagios
#make&& make install
8、安装nrpe(监控端)
#./configure
http://s3.运维网.com/wyfs02/M01/54/10/wKiom1R20YjwN9wnAABm5u2oVHc737.jpg
#make all && make install-plugin
9、被监控端安装
1、系统环境
http://s3.运维网.com/wyfs02/M00/54/0F/wKioL1R20iCBNCoCAAC6g6ldheA468.jpg
10、下载
#wgethttp://jaist.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz(监控插件)
#wgethttp://jaist.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz (nrpe插件)
11、创建用户
#useradd nagios
#passwd nagios
12、检查基础套件
#rpm-q gcc glibc glibc-common gd gd-devel openssl-devel
13、安装nagios-plugins
#./configure
#make && make install
14、修改目录权限
#chown nagios.nagios /usr/local/nagios
#chown -R nagios.nagios /usr/local/nagios/libexec
15、安装nrpe
#./configure
#make all
#make install-plugin安装check_nrpe
#make install-daemon
#make install-daemon-config
16、配置nrpe
#vi /usr/local/nagios/etc/nrpe.cfg 添加allowed_hosts=192.168.40.128
17、启动nrpe
#/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg -d
18、测试一下
#/usr/local/nagios/libexec/check_nrpe -H localhost
19、随机启动
#echo "/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
20、配置
1、# vi /usr/local/nagios/etc/objects/commands.cfg
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
}
参考资料:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html
至此nagios的服务端与客户端搭建完成
三、安装cacti
Cacti的运行需要LAMP(Linux+Apache + MySQL + PHP), RRDTool ,net-snmp , AMP
正确配置各主机网络参数,本实验以一台机器既为服务端也为被监测端
#vim/etc/sysconfig/network-scrip/ifcfg-eth0
在被监测端安装net-snmp软件包,net-snmp软件需要用到lm_sensors提供的硬件监视模块,安装时直接使用RHEL5系统光盘中的rpm包文件,依次安装lm_sensors、net-snmp两个软件包即可。
# cd /mnt/Server/
# rpm -ivh lm_sensors-2.10.0-3.1.i386.rpm
# rpm -ivh net-snmp-5.3.1-14.el5.i386.rpm
3、配置及启动snmpd服务,修改文件/etc/snmp/snmpd.conf第41、62、85行,设置SNMP访问权限
41行中将default修改为cacti监测服务器的IP地址本实验为192.168.4.1将public修改为共享SNMP信息的组识别字串publicsvr,62行 将systemview修改为all,85行去掉开头注释符号
41com2sec notConfigUser192.168.4.1 publicsvr
62accessnotConfigGroup "" any noauth exactall none none
iewall included.1 80
4、启动snmpd服务并设置为自启动
# service snmpd start
启动 snmpd: [确定]
# chkconfig --level 35 snmpd on
5、配置监测服务端
Cacti监测服务端需要有apache、mysql、php网站平台的支持,且需要预先安装有gd、zlib等软件包
httpd-2.2.3-6.el5
mysql-5.0.22-2.1
mysql-server-5.0.22-2.1
mysql-connector-odbc-3.51.12-2.2
php-5.1.6-5.el5
php-mysql-5.1.6-5.1.6-5.el5、
php-common-5.1.6-5.1.6-5.el5、php-pdo-5.1.6-5.el5
注:此处用源码包安装如下(也可用yum安装)
编译安装apache
# tar zxvf httpd-2.2.9.tar.gz – C /usr/src
# ./configure --prefix=/usr/local/apache2 --enable-so--enable-rewrite --enable-ssl --with-ssl=/usr/lib --enable-auth-digest--enable- cgi --enable-suexec --with-suexec-caller=daemon--with-suexec-docroot=/usr/local/apache2/htdocs
# make && make install
查看相关服务
# ls /usr/local
apache2bin etcgamesinclude liblibexecsbin sharesrc
执行启动服务
# ./apachectl start
安装mysql
# useradd -M -s /sbin/nologin mysql
# tar zxvf mysql-5.0.56.tar.gz -C /usr/src
# ./configure --prefix=/usr/local/mysql
# make & make install
# cp support-files/my-medium.cnf /etc/my.cnf
# chown -R root:mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql
# /usr/local/mysql/bin/mysql_install_db --user=mysql
# echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf
# ldconfig
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
13582
# Starting mysqld daemon with databases from /usr/local/mysql/var
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig -add mysqld
安装编译php
# tar jxvf php-5.2.6.tar.bz2 -C /usr/src
# ./configure --prefix=/usr/local/php5--with-apxs2=/usr/local/apache2/bin/apxs--with-mysql=/usr/local/mysql --enable-sockets--enable-mbstring
# make && make install
编辑文件vim/usr/local/apache2下的配置文件
AddTypeapplication/x-httpd-php .php
DirectoryIndex index.html index.php
(此处也可以用rpm包安装相关的依赖包)
# rpm -ivh perl-DBI-1.52-1.fc6.i386.rpm
# rpm -ivh mysql-5.0.22-2.1.i386.rpm
# rpm -ivh perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
# rpm -ivh mysql-server-5.0.22-2.1.i386.rpm
# rpm -ivh unixODBC-2.2.11-7.1.i386.rpm
# rpm -ivh libtool-ltdl-1.5.22-6.1.i386.rpm
# rpm -ivh libdbi-0.8.1-2.1.i386.rpm
# rpm -ivh libdbi-drivers-0.8.1a-1.2.2.i386.rpm
# rpm -ivh libdbi-dbd-mysql-0.8.1a-1.2.2.i386.rpm
#rpm-ivhmysql-connector-odbc-3.51.12-2.2.i386.rpm
# rpm -ivh php-common-5.1.6-5.el5.i386.rpm
# rpm -ivh php-cli-5.1.6-5.el5.i386.rpm
# rpm -ivh php-5.1.6-5.el5.i386.rpm
# rpm -ivh php-pdo-5.1.6-5.el5.i386.rpm
启动已安装好的httpd、mysqld服务,设置为每次开机随系统自动运行
# chkconfig --level35 mysqld on
# chkconfig --level 35 httpd on
6、安装net-snmp-utils软件包
# rpm -ivh net-snmp-utils-5.3.1-14.el5.i386.rpm
warning:net-snmp-utils-5.3.1-14.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID37017186
Preparing... ###########################################
1:net-snmp-utils
###########################################
7、安装rrdtool软件包
# mount /dev/cdrom /mnt
mount:block device /dev/cdrom is write-protected, mounting read-only
# cd /mnt/Linux-gateway/LGS-SG6
[ root@localhost LGS-SG6]# tar zxvfrrdtool-1.2.27.tar.gz
# cd rrdtool-1.2.27/
#./configure --prefix=/usr/local
# nake&& make install
8、安装cacti文件包
# cd /var/www/html
# tar zxvf/mnt/Linux-gateway/LGS-SG6/cacti-0.8.7b-cn-utf8.tar.gz
# mv cacti-0.8.7b-cn-utf8 cacti
# useradd cactiuser
# chown -R cactiuser.cactiuser cacti/rra/ cacti/log/
9、设置监测数据库、表,设置好授权访问数据库的用户和密码
# mysql -u root -p
Enterpassword:
Welcometo the MySQL monitor.Commands end with; or \g.
YourMySQL connection id is 2 to server version: 5.0.22
Type'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>create database cactidb default character set utf8;
QueryOK, 1 row affected (0.00 sec)
mysql>grant all on cactidb.* to cactiuser@localhost identified by 'pwd@123';
QueryOK, 0 rows affected (0.02 sec)
mysql>
# mysql -u cactiuser -p cactidb < cacti/cacti.sql
Enterpassword
10、调整cacti配置文件
# cd /var/www/html/cacti/
# vim include/config.php
$database_type= "mysql";
$database_default= "cactidb";
$database_hostname= "localhost";
$database_username= "cactiuser";
$database_password= "pwd@123";
$database_port= "3306";
$config['url_path']="/"
11、调整httpd设置并重新启动服务
DocumentRoot"/var/www/html/cacti"
页:
[1]