• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Automatische Installation von Nagios unter Debian

Hallo!

Ich habe mir (uns) ein Script geschrieben mit welchem man Nagios 3.0.5 fast vollautomatisch installieren kann.
Da ich mir nicht ganz sicher war, wo es besser aufgehoben ist, hier oder bei Nagios selber, habe ich es einmal hier veroeffentlicht, kann gerne weiter angepasst werden!
Manche Dateien muss man noch manuell uebertragen, da ein ersetzen der Varibalen mit vi nicht ganz hingehauen hat ( config.php, sources.list, htpasswd.users und 001-nagios ).
Wird aber noch nachgereicht, sobald ich den Dreh heraussen habe.

Code sieht schrecklich aus, da es keine Funktionen gibt, aber das wird, wie gesagt, alles noch nachgereicht!

Code:
#!/bin/bash 

#######################################
#
# Variable
#
ip_addr=`ifconfig eth0 | grep "inet addr:" | awk '{ print $2 }' | awk -F ':' '{ print $2 }'`
NAGIOS_INSTALL="/opt/nagios-3.0.5"
NAGIOS_PLUGIN="/opt/nagios-plugins-1.4.13"
NAGIOS_HOME="/home/nagios"
ROOT_PASSWD_FOR_CACTI="cacti" # if changed you will have to configure config.php as well at the moment
#
#
#######################################

echo ""
echo -e "\033[1;31m/etc/apt/source.list wird angepasst"
echo "-----------------------------------"
echo -e "\033[0m"
echo ""

mv /etc/apt/sources.list /etc/apt/sources.list_bck

cp $NAGIOS_HOME/sources.list /etc/apt/

echo -e "\033[1;31mLet us update everything"
echo "------------------------"
echo -e "\033[0m"

apt-get update
apt-get upgrade

apt-get install apache2 build-essential libgd2-dev << !
Y
!

echo ""
echo -e "\033[1;31mDo you want to install postfix?"
echo "-----------------------------"
echo -e "\033[0m"

echo "Yes or No"
read input

if test "$input" == "Yes" ; then
apt-get install postfix << !
Y
!
fi	

sleep 3 

groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd www-data

cd
mkdir downloads

mv $NAGIOS_HOME/nagios-3.0.5.tar.gz /opt
mv $NAGIOS_HOME/nagios-plugins-1.4.13.tar.gz /opt

cd /opt/ 
gzip -d nagios-3.0.5.tar.gz
tar -xvf nagios-3.0.5.tar

echo ""
echo -e "\033[1;31mInstalling gcc compiler"
echo "-----------------------"
echo -e "\033[0m"

apt-get install gcc << !
Y
!

cd $NAGIOS_INSTALL && ./configure --with-command-group=nagcmd
cd $NAGIOS_INSTALL && make all
cd $NAGIOS_INSTALL && make install
cd $NAGIOS_INSTALL && make install-init
cd $NAGIOS_INSTALL && make install-config
cd $NAGIOS_INSTALL && make install-commandmode

cp $NAGIOS_HOME/htpasswd.users /usr/local/nagios/etc/

cd /opt/ && gzip -d nagios-plugins-1.4.13.tar.gz

cd /opt && tar -xvf nagios-plugins-1.4.13.tar

cd $NAGIOS_PLUGIN/ && ./configure --with-nagios-user=nagios --with-nagios-group=nagios
cd $NAGIOS_PLUGIN/ && make
cd $NAGIOS_PLUGIN/ && make install

ln -s /etc/init.d/nagios /etc/rc2.d/S98nagios

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

echo ""
echo -e "\033[1;31mAre there any mistakes to see?"
echo "Yes or No"
echo -e "\033[0m"

read input_mistake

if [ $input_mistake = "Yes" ]
then
	echo ""
	echo "Please do all necessary steps from new on or look for it by yourself!!"
	echo "Bye"
	echo ""
	exit
fi

/etc/init.d/nagios start 

mv $NAGIOS_HOME/nagios /etc/apache2/sites-available/nagios

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/nagios /etc/apache2/sites-enabled/001-nagios

cd /etc/init.d
apache2 -k restart

echo ""
echo "Please ignore the error message!!"
echo ""

echo "Nagios should be installed correctly now"
echo "Please go to http://$ip_addr/nagios"
echo "-----------------------------------------"

sleep 3

echo ""
echo "Cacti installation will be done now"
echo "------------------------------------"
echo ""

sleep 3

echo ""
echo "Password for root in mysql db is $ROOT_PASSWD_FOR_CACTI"
echo "-----------------------------" 

cp $NAGIOS_HOME/cacti-0.8.7b.tar.gz /var/www/cacti-0.8.7b.tar.gz

apt-get install libapache2-mod-php5 php5 php5-cli php5-mysql php5-gd php5-snmp mysql-client mysql-server libmysqlclient15-dev snmp snmpd rrdtool << !
Y
!

groupadd cacti
useradd -g cacti cacti

cd /var/www/  && gzip -d cacti-0.8.7b.tar.gz
cd /var/www/  && tar -xvf cacti-0.8.7b.tar

mysql -u root << !
SET PASSWORD FOR root@localhost = PASSWORD ("$ROOT_PASSWD_FOR_CACTI");
CREATE DATABASE cacti;
GRANT ALL ON cacti.* TO cacti_user@localhost IDENTIFIED BY "ROOT_PASSWD_FOR_CACTI";
quit
!

cd /var/www/cacti-0.8.7b/ && mysql -u root -p$ROOT_PASSWD_FOR_CACTI -Dcacti < cacti.sql
chown -R cacti rra/ log/

cp $NAGIOS_HOME/config.php /var/www/cacti-0.8.7b/include/

/etc/init.d/apache2 restart

echo ""
echo -e "\033[1;31mPlease go to http://$ip_addr/cacti-0.8.7b/"
echo "In order to use cacti, you have to log in using username: admin, password: admin"
echo -e "\033[0m"
echo ""

config.php

Code:
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "root";
$database_password = "cacti";
$database_port = "3306";

sources.list

Code:
deb http://ftp.us.debian.org/debian/ etch main contrib non-free
deb-src http://ftp.us.debian.org/debian/ etch main contrib non-free

htpasswd.users

Code:
nagiosadmin:jP2vbcwAARctk

001-nagios

Code:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
Alias /nagios "/usr/local/nagios/sbin"
 
Danke dir. :up:
Bring es doch auch noch in der Wiki unter, da ist es noch besser aufgehoben. ;)

http://wiki.linux-club.de/opensuse/Hauptseite
 
Oben