第一步 : 安装 nagios
首先禁用 AppArmor
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
aptitude remove apparmor apparmor-utils
安装必须库 和 更新系统
aptitude -y install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev postfix
# aptitude update -> GCC编译器与开发库
# postfix -> 邮件apt-get update
apt-get upgrade
设置 用户和组
useradd -m -s /bin/bash nagios
passwd nagios
usermod -G nagios nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
下载/解压nagios与其插件
cd /downloads
wget http://prdownloads.sourceforge.net/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar -zxf /downloads/nagios-3.2.3.tar.gz
或 tar jxvf /downloads/nagios-3.2.3.tar.bz2
tar -zxf /downloads/nagios-plugins-1.4.15.tar.gz
安装 nagios
cd /downloads/nagios-3.2.3
./configure –with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
nagios密码(没理解到)
This is the password you will need to look at the nagios pages. If you install Nagios to a different directory please change this command to where the Nagios etc. folder will be.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
重启apache2
/etc/init.d/apache2 restart
第二步 安装nagios插件
cd /downloads/nagios-plugins-1.4.15/
./configure
make
make install
现在把 nagios加入启动
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
修改默认nagios admin email
nano /usr/local/nagios/etc/objects/contacts.cfg
修改
nagios@localhost 到 You@yourdomain.com
检验nagios配置文件是否正常,可以有警告,但是不能有任意一个错误.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
正常的话 就可以启动了
/etc/init.d/nagios start
现在你可以通过 http://yourserver/nagios/ 查看界面了
第三步 配置一个需监控的windows机器
下载 NSClient++
http://sourceforge.net/projects/nscplus/files/latest/download
安装脚本:
#!/bin/bash # # AUTHOR : rbishop # DATE : 01.27.2011 # # PROG.-NAME : nagios-setup.sh # # FUNCTION : Installing Nagios on your System # # ####################################################################### ####################################################################### ## ## ## Configurable Settings for this Script ## ## WWWGROUP=www-data WWWUSER=www-data NAGIOSROOT=/usr/local/nagios DOWNLOADS=/downloads NAGIOSADMIN=nagiosadmin POSTFIXETC=/etc/postfix NAGIOSIP= MAILSERVERDOMAIN= MAILSERVERUSER= MAILSERVERPASS= ## ## ## END Configurable Settings for Script ## ## ## ####################################################################### time { set -e echo "***** Starting Nagios Quick-Install: *****" echo "" echo `date` echo "*******************************************" echo "*******************************************" echo "** **" echo "** Disabling AppArmor **" echo "** **" echo "*******************************************" echo "*******************************************" /etc/init.d/apparmor stop update-rc.d -f apparmor remove aptitude remove apparmor apparmor-utils echo "*******************************************" echo "*******************************************" echo "** **" echo "** Adding Required Folders for Install **" echo "** **" echo "*******************************************" echo "*******************************************" mkdir ${DOWNLOADS} echo "*******************************************" echo "*******************************************" echo "** **" echo "** Updating Software Packages on Server **" echo "** **" echo "*******************************************" echo "*******************************************" aptitude -y install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev postfix aptitude update aptitude -y safe-upgrade echo "*******************************************" echo "*******************************************" echo "** **" echo "** Adding Nagios user login for nagios **" echo "** **" echo "*******************************************" echo "*******************************************" useradd -m -s /bin/bash nagios passwd nagios usermod -G nagios nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www-data echo "*******************************************" echo "*******************************************" echo "** **" echo "** Downloading and Unzipping Nagios **" echo "** **" echo "*******************************************" echo "*******************************************" cd ${DOWNLOADS} wget http://prdownloads.sourceforge.net/nagios/nagios-3.2.3.tar.gz wget http://prdownloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.15.tar.gz tar -zxvf ${DOWNLOADS}/nagios-3.2.3.tar.gz tar -zxvf ${DOWNLOADS}/nagios-plugins-1.4.15.tar.gz cd ${DOWNLOADS}/nagios-3.2.3 echo "*******************************************" echo "*******************************************" echo "** **" echo "** Configuring nagios and installing **" echo "** **" echo "*******************************************" echo "*******************************************" read -p "Press Enter to continue..." ./configure --with-command-group=nagcmd echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Nagios Make All Command **" echo "** **" echo "*******************************************" echo "*******************************************" make all echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Nagios Make Install Command **" echo "** **" echo "*******************************************" echo "*******************************************" make install echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Make Install-Init Command **" echo "** **" echo "*******************************************" echo "*******************************************" make install-init echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Make Install-Config Command **" echo "** **" echo "*******************************************" echo "*******************************************" make install-config echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Make Install-CommandMode **" echo "** **" echo "*******************************************" echo "*******************************************" make install-commandmode echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running Make Install-Webconf **" echo "** **" echo "*******************************************" echo "*******************************************" make install-webconf echo "*******************************************" echo "*******************************************" echo "** **" echo "** Adding htpasswd login for nagiosadmin **" echo "** **" echo "*******************************************" echo "*******************************************" htpasswd -c ${NAGIOSROOT}/etc/htpasswd.users ${NAGIOSADMIN} echo "*******************************************" echo "*******************************************" echo "** **" echo "** Restarting Apache **" echo "** **" echo "*******************************************" echo "*******************************************" /etc/init.d/apache2 restart echo "********************************************" echo "********************************************" echo "** **" echo "** Configuring Nagios-Plugins for Install **" echo "** **" echo "********************************************" echo "********************************************" cd ${DOWNLOADS}/nagios-plugins-1.4.15/ ./configure --with-nagios-user=nagios --with-nagios-group=nagios echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running NagiosPlugin Make Command **" echo "** **" echo "*******************************************" echo "*******************************************" make echo "*******************************************" echo "*******************************************" echo "** **" echo "** Running NagiosPlugin Make Install **" echo "** **" echo "*******************************************" echo "*******************************************" make install echo "*******************************************" echo "*******************************************" echo "** **" echo "** Adding Nagios to Start on BootUp **" echo "** **" echo "*******************************************" echo "*******************************************" ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios echo "*******************************************" echo "*******************************************" echo "** **" echo "** Checking Nagios Configuration **" echo "** **" echo "*******************************************" echo "*******************************************" ${NAGIOSROOT}/bin/nagios -v ${NAGIOSROOT}/etc/nagios.cfg echo "*******************************************" echo "*******************************************" echo "** **" echo "** Starting Nagios **" echo "** **" echo "*******************************************" echo "*******************************************" /etc/init.d/nagios start echo "*******************************************" echo "*******************************************" echo "** **" echo "** Configuring Postfix **" echo "** **" echo "*******************************************" echo "*******************************************" postconf -e 'relayhost =${MAILSERVERDOMAIN}' postconf -e 'smtp_sasl_auth_enable = yes' postconf -e 'smtp_sasl_password_maps = hash:${POSTFIXETC}/sasl_passwd' postconf -e 'smtp_sasl_security_options =' echo "${MAILSERVERDOMAIN} ${MAILSERVERUSER}:${MAILSERVERPASS}" > ${POSTFIXETC}/sasl_passwd chown root:root ${POSTFIXETC}/sasl_passwd chmod 600 ${POSTFIXETC}/sasl_passwd postmap ${POSTFIXETC}/sasl_passwd echo "${MAILSERVERDOMAIN}" > ${POSTFIXETC}/sasl_passwd echo "nagios nagios@${MAILSERVERDOMAIN}" > ${POSTFIXETC}/canonical echo "canonical_maps = hash:${POSTFIXETC}/canonical" >> ${POSTFIXETC}/main.cf postmap ${POSTFIXETC}/canonical /etc/init.d/postfix restart echo "*****************************************" echo "* *" echo "* Ending Nagios Quick-Install: *" echo "* *" echo "*****************************************" echo "*******************************************" echo "*******************************************" echo "** **" echo "** Now go to ${NAGIOSIP}/nagios/ **" echo "** **" echo "*******************************************" echo "*******************************************" }
.