Nagios服务端安装

 

 

目录

1 准备工作... 1

1.1 准备3台服务器或VM虚拟机... 1

2 开始安装... 1

步骤1:配置yum..2

步骤2:配置profile.2

步骤3:关闭防火墙...2

步骤4:配置时间同步 config time sync. 2

步骤5:安装gcc、lamp、env、etc.2

步骤6:添加nagios用户和组...3

步骤7:下载和安装nagios.3

步骤8:配置web认证(config web auth)3

步骤9:安装nagios插件...3

步骤10:安装nrpe.4

步骤11:启动nagios服务并检查...4

1) 启动nagios服务... 4

2) 进入nagios服务端... 4

 

 

 

 

 

 

 

 

 

1 准备工作

 

准备3台服务器或VM虚拟机

 

 

1.1 准备3台服务器或VM虚拟机

 

nagios服务器及客户端服务器

 

管理IP地址

角色

备注

192.168.1.19

Nagios监控服务器

 

192.168.1.18

Lamp服务器

被监控的客户端服务器

192.168.1.17

Lnmp服务器

被监控的客户端服务器

 

 

2 开始安装

 

 

 

 

步骤1:配置yum

 

 

 

 

[root@nagios ~]# cd /etc/yum.repos.d/

[root@nagiosyum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-6.repo

 

 

 



 

 

 

 

步骤2:配置profile

 

[root@nagios yum.repos.d]# echo 'exportLC_ALL=C'>> /etc/profile

[root@nagios yum.repos.d]# source /etc/profile

[root@nagios yum.repos.d]#

 

 

步骤3:关闭防火墙

 

[root@nagios yum.repos.d]#

[root@nagiosyum.repos.d]# /etc/init.d/iptables stop

[root@nagiosyum.repos.d]# chkconfig iptables off

[root@nagios yum.repos.d]#

[root@nagios yum.repos.d]#

[root@nagiosyum.repos.d]# setenforce 0

[root@nagiosyum.repos.d]# vi /etc/selinux/config

 

 

# This file controls the state of SELinux on thesystem.

# SELINUX= can take one of these three values:

#    enforcing - SELinux security policy is enforced.

#    permissive - SELinux prints warnings instead of enforcing.

#     disabled- No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#    targeted - Targeted processes are protected,

"/etc/selinux/config" 13L, 457C written

[root@nagios yum.repos.d]#

 

 

步骤4:配置时间同步 config time sync

 

 

[root@nagios ~]#

[root@nagios~]# /usr/sbin/ntpdate pool.ntp.org

[root@nagios~]# echo '#time sync by oldboy at 2015-07-01'>>/var/spool/cron/root

[root@nagios~]# echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null2>&1'>>/var/spool/cron/root

[root@nagios~]# crontab -l

 

 

步骤5:安装gcc、lamp、env、etc

 

yum install gcc glibc glibc-common -y

yum install gd gd-devel -y

yum install httpd php php-gd -y

yum install mysql* -y

 

 

步骤6:添加nagios用户和组

 

/usr/sbin/useradd -m nagios

#/usr/sbin/useradd apache

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache

 

 

 

步骤7:下载和安装nagios

 

         编译主程序;

 

oldboy_training_nagios_soft.zip

unzip oldboy_training_nagios_soft.zip

 

[root@nagiostools]# tar xzf nagios-3.5.1.tar.gz

[root@nagiostools]# cd nagios

[root@nagiosnagios]# ./configure --with-command-group=nagcmd

[root@nagiosnagios]# make all

[root@nagiosnagios]# make install

[root@nagiosnagios]# make install-init

[root@nagiosnagios]# make install-config

[root@nagiosnagios]# make install-commandmode

[root@nagiosnagios]# make install-webconf

 

 

 

 

步骤8:配置web认证(config web auth)

 

 

[root@nagios nagios]# htpasswd -cb/usr/local/nagios/etc/htpasswd.users oldboy 888888

Adding password for user oldboy

[root@nagios nagios]#

 

 

 

 

步骤9:安装nagios插件

 

yum -y install perl-devel

tar zxf nagios-p

 

 

[root@nagiosnagios]# useradd oldboy

[root@nagiosnagios]# id oldboy

uid=501(oldboy) gid=502(oldboy) groups=502(oldboy)

[root@nagiosnagios]# htpasswd -cb /usr/local/nagios/etc/htpasswd.users oldboy 888888

Adding password for user oldboy

[root@nagiosnagios]# yum -y install perl-devel

[root@nagiostools]# tar zxf nagios-plugins-1.4.16.tar.gz

[root@nagiostools]# cd nagios-plugins-1.4.16

[root@nagiosnagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios--with-nagios-group=nagios --enable-perl-modules

[root@nagiosnagios-plugins-1.4.16]# make && make install

[root@nagiosnagios-plugins-1.4.16]# cd ../

[root@nagiostools]# ls /usr/local/nagios/libexec/|wc -l

61

 

 

 

步骤10:安装nrpe

 

 

[root@nagiostools]# tar zxvf nrpe-2.12.tar.gz

[root@nagiostools]# cd nrpe-2.12

[root@nagiosnrpe-2.12]# ./configure

[root@nagiosnrpe-2.12]# make all

[root@nagiosnrpe-2.12]# make install-plugin

[root@nagiosnrpe-2.12]# make install-daemon

[root@nagiosnrpe-2.12]# make install-daemon-config

[root@nagiosnrpe-2.12]# cd ../

[root@nagios tools]#

 

 

 

 

步骤11:启动nagios服务并检查

 

1) 启动nagios服务

 

[root@nagiostools]# /etc/init.d/nagios start

[root@nagiostools]# /etc/init.d/httpd start

[root@nagiostools]# lsof -i tcp:80

[root@nagiostools]# ps -ef|grep nagios

[root@nagiostools]# echo "NAGIOS is successfully installed."

[root@nagiostools]# echo ok

 

 

 

2) 进入nagios服务端

 

访问地址:

​         http://192.168.1.19/nagios/​

         用户名:oldboy

         密码:888888