Skip to content

Instantly share code, notes, and snippets.

@nu11secur1ty
Last active February 4, 2016 00:39
Show Gist options
  • Save nu11secur1ty/8ff6a54213b6d1602242 to your computer and use it in GitHub Desktop.
Save nu11secur1ty/8ff6a54213b6d1602242 to your computer and use it in GitHub Desktop.
Install Nagios 4.x on CentOs 6.5
#!/bin/bash
######################################
# copyright@nu11secur1ty #
######################################
# Stop iptables
/etc/init.d/iptables stop
yum install wget
cd ~
# you can change if you want!
wget http://nchc.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.2/nagios-4.0.2.tar.gz
yum remove nginx -y
# install packages
yum install -y httpd php gd gd-devel gcc glibc glibc-common openssl perl perl-devel make
# create the user and group for Nagios installation
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
# extract
cd ~
tar -xvzf nagios-4.0.2.tar.gz
# Going to directory and configure
cd nagios-4.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
# copy the eventhandlers directory into /usr/local/nagios/libexec/
cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
# configuration change in nagios.cfg file
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# username and password
echo "Please provide password for user 'nagiosadmin'"
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Start the httpd and nagios service
/etc/init.d/nagios start
/etc/init.d/httpd start
# run in runlevel 3,4,5
chkconfig nagios on
chkconfig httpd on
# Change the permission
chmod 777 /usr/local/nagios/var/rw/nagios.cmd
chmod 777 /usr/local/nagios/var/rw/nagios.qh
# Install Nagios plugin
cd ~
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
tar -xvzf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
# Access nagios and clear
chmod -R 777 /usr/local/nagios
rm -rf /root/nagios-plugins-1.5.tar.gz
rm -rf /root/nagios-4.0.2.tar.gz
rm -rf /root/nagios-4.0.2
rm -rf /root/nagios-plugins-1.5
# reboot system
echo "enjoy yourself with nagios :)";
echo "do not press any key, just wait!"
sleep 3
reboot
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment