Skip to content

Instantly share code, notes, and snippets.

@jamesboehmer
Forked from boardstretcher/install_nagios.sh
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesboehmer/81e1be8f420fe1885445 to your computer and use it in GitHub Desktop.
Save jamesboehmer/81e1be8f420fe1885445 to your computer and use it in GitHub Desktop.
# install nagios 4.0.8 on centos 6.5
# update VPS
yum -y update
yum -y install gd gd-devel wget httpd php gcc perl
# users and groups
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios apache
# working directory
pushd /tmp
# get archives
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# install nagios
tar xf nagios-4.0.8.tar.gz
pushd nagios-4.0.8/
./configure --with-command-group=nagcmd
make all && make install && \
make install-init && make install-config && \
make install-commandmode && make install-webconf
# configure email and htuser
sed -i 's/nagios@localhost/youremail@yourdomain/g' /usr/local/nagios/etc/objects/contacts.cfg
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
popd
# install plugins
tar xf nagios-plugins-2.0.3.tar.gz
pushd nagios-plugins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
# add/enable nagios service
chkconfig --add nagios
chkconfig nagios on
# create initial config
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# some bug fixes
touch /var/www/html/index.html
echo "Redirect 301 / /nagios" > /var/www/html/.htaccess
sed -i 's/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
chown nagios.nagcmd /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
# init bug fix
sed -i '/$NagiosBin -d $NagiosCfgFile/a (sleep 10; chmod 666 \/usr\/local\/nagios\/var\/rw\/nagios\.cmd) &' /etc/init.d/nagios
# 4G swap space (this is a digitalocean VPS)
dd if=/dev/zero of=/swap bs=1024 count=4000000
mkswap /swap
swapon /swap
echo /swap swap swap defaults 0 0 >> /etc/fstab
echo vm.swappiness = 0 >> /etc/sysctl.conf
sysctl -p
# start services
service nagios start
chkconfig httpd on
service httpd restart
# remove gcc
yum remove gcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment