我用了Nagios有一年多,在日常的监控工作中他都能胜任,那大家安装一个Nagios系统是必要的,让我们来看看Nagios安装具体过程!
图-Nagios
修改yum升级服务器[root@localhost ~]# cd /etc/yum.repos.d[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak[root@localhost yum.repos.d]# wget http://centos.ustc.edu.cn/CentOS-Base.repo
---更新软件[root@localhost yum.repos.d]# yum update
---安装以下必备软件[root@localhost yum.repos.d]# yum install httpd[root@localhost yum.repos.d]# yum install gcc[root@localhost yum.repos.d]# yum install glibc glibc-common[root@localhost yum.repos.d]# yum install gd gd-devel
---添加nagios用户、nagcmd组等
- [root@localhost yum.repos.d]# cd [root@localhost ~]# useradd -m nagios[root@localhost ~]# passwd nagios ---nagios[root@localhost ~]# groupadd nagcmd[root@localhost ~]# usermod -a -G nagcmd nagios[root@localhost ~]# usermod -a -G nagcmd apache
---安装nagios
- [root@localhost ~]# mkdir -p ~/downloads[root@localhost ~]# cd ~/downloads[root@localhost downloads]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.3/nagios-3.2.3.tar.gz[root@localhost downloads]# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz[root@localhost downloads]# tar xzf nagios-3.2.3.tar.gz[root@localhost downloads]# cd nagios-3.2.3[root@localhost nagios-3.2.3]# ./configure --with-command-group=nagcmd --with-gd-lib=/usr/lib --with-gd-inc=/usr/include [root@localhost nagios-3.2.3]# make all[root@localhost nagios-3.2.3]# make install[root@localhost nagios-3.2.3]# make install-init[root@localhost nagios-3.2.3]# make install-config[root@localhost nagios-3.2.3]# make install-commandmode
- [root@localhost nagios-3.2.3]# cp /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg.bak[root@localhost nagios-3.2.3]# vi /usr/local/nagios/etc/objects/contacts.cfg ---修改nagiosadmin:email
- [root@localhost nagios-3.2.3]# make install-webconf[root@localhost nagios-3.2.3]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin ---nagios
- [root@localhost nagios-3.2.3]# service httpd restart
---安装nagios-plugins
- [root@localhost nagios-3.2.3]# cd ~/downloads[root@localhost downloads]# tar xzf nagios-plugins-1.4.15.tar.gz[root@localhost downloads]# cd nagios-plugins-1.4.15[root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[root@localhost nagios-plugins-1.4.15]# make[root@localhost nagios-plugins-1.4.15]# make install
---安装nagios-snmp-plugins
- [root@localhost nagios-plugins-1.4.15]# cd ~/downloads[root@localhost downloads]# wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz[root@localhost downloads]# tar xzf nagios-snmp-plugins.1.1.1.tgz[root@localhost downloads]# cd nagios_plugins[root@localhost nagios_plugins]# perl -MCPAN -e shell
- cpan> install Net::SNMP
- [root@localhost nagios_plugins]# ./install.sh
#p#
---其它设置
[root@localhost nagios_plugins]# cd [root@localhost ~]# chkconfig --add nagios[root@localhost ~]# chkconfig nagios on[root@localhost ~]# chkconfig httpd on[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
---检测配置
- [root@localhost ~]# service nagios start
- @localhost ~]# cp /etc/sysconfig/selinux /etc/sysconfig/selinux.bak[root@localhost ~]# vi /etc/sysconfig/selinux ---SELINUX=permissive
---安装mysql
- [root@localhost ~]# yum -y install mysql[root@localhost ~]# yum -y install mysql-server[root@localhost ~]# yum -y install mysql-devel[root@localhost ~]# yum -y install php-mysql
- [root@localhost ~]# chkconfig --levels 345 mysqld on[root@localhost ~]# service mysqld start
- [root@localhost ~]# mysqlSET PASSWORD FOR 'root'@'localhost' = PASSWORD('mysql');
- [root@localhost yum.repos.d]# yum install php
---安装cacti
- [root@localhost ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm[root@localhost ~]# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm[root@localhost ~]# yum install rrdtool[root@localhost ~]# yum install net-snmp net-snmp-utils net-snmp-devel
- [root@localhost ~]# yum install cacti ---php-mysql,php-pdo,php-snmp
- [root@localhost conf.d]# vi cacti.conf
- Alias /cacti/ /usr/local/wwwroot/cacti/ DirectoryIndex index.php Options -Indexes AllowOverride all order deny,allow allow from all AddType application/x-httpd-php .php php_flag magic_quotes_gpc on php_flag track_vars on
- [root@localhost ~]# mysql -u root -pMysql>create database cacti;Mysql>use cacti;Mysql>source /usr/local/wwwroot/cacti/cacti.sqlMysql>grant all privileges on cacti.* to cacti@localhost identified by 'cacti';Mysql>flush privileges;
---apache设置
- [root@localhost ~]# vi /var/www/cacti/include/config.php
- $database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cacti";$database_password = "cacti";$database_port = "3306";
---安装ndoutils,实现nagios采集数据写入mysql
- [root@localhost ~]# wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz[root@localhost ~]# tar zxf ndoutils-1.4b9.tar.gz[root@localhost ~]# cd ndoutils-1.4b9[root@localhost ndoutils-1.4b9]# ./configure --enable-mysql --disable-pgsql --with-mysql-lib=/usr/lib/mysql[root@localhost ndoutils-1.4b9]# make[root@localhost ndoutils-1.4b9]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
通过文章,我们对Nagios的安装都有了自己的心得,希望你们赶快去装一个Nagios,真的非常好用。
【编辑推荐】