groupadd nagcmd
#添加与nagios运行相关服务的组
useradd -m nagios
#添加nagios用户
usermod -a -G nagcmd nagios
#将nagios用户追加附加组
usermod -a -G nagcmd apache
#将apache用户追加nagcmd组使之工作时具有足够的权限
2.编译安装nagios 3.3.1
tar xvf nagios-3.3.1.tar.gz
cd nagios
# ./configure --with-command-group=nagcmd --enable-event-broker
#默认安装路径在/usr/local/nagios/
make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf
#安装主程序、添加初始化程序、生成配置文件、生成web配置文件
make install-webconf的作用:在/etc/httpd/conf.d/nagios.conf生成web相关配置文件,用于定义nagios使用的CGI选项,web的身份认证等
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagios
#为nagios的web页面创建账号密码,对访问进行身份认证
service httpd restart
chkconfig httpd on
#启动httpd,并设置开机启动
tar xvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql
#添加mysql依赖
make && make install
#编译并安装
Ps:作者在安装nagios-cn-3.2.3.tar过程中,在此处编译完成发现mysql关联库文件本跳过。经分析原因是由于在编译nagios时修改了nagios的默认安装路径(非/usr/local/nagios)。 解决办法:
vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
#将这一行注释去掉
2.修改用来定义windows的配置文件
vim /usr/local/nagios/etc/objects/windows.cfg
define host{
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.0.72 ; windowsIP
}
#修改IP,此ip为windows主机IP
配置监控Linux主机
1.编译安装nrpe
tar xvf nrpe-2.12.tar
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/lib/
make all && make install-plugin
vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
#在主配置文件指明linux主机的配置文件路径
Windows 监控端配置
安装NSClient,进入安装目录修改配置文件NSC.ini,将[module]下所有库文件的注释删去。运行nsclient。
Linux 监控端配置
1.添加nagios用户
useradd nagios
2.编译安装nagios-plugin
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
3.编译安装nrpe
yum install openssl-devel
#先安装openssl解决依赖
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12.tar.gz
./configure --enable-ssl --with-ssl-lib=/usr/lib/
make all && make install-plugin && make install-daemon && make install-daemon-config
#编译安装
4.配置并启用nrpe
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.1.1
#监控端的IP
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
#开启进程