#!/bin/bash # # Centreon Appliance Installer Script is developed with GPL Licence 2.0 # # Installer version: Centreon 2.x and Nagios 3.x in Ubuntu Server 8.04 # # GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # # Developed by : Rodolfo Matos # # This script try to follow centreon wiki pages where aplicable. # # *** USE AT YOUR OWN RISK *** # # Jul 15, 2008 # # Just install in a bare-bones Ubuntu Server 8.04. # Include Openssh server if you want. # # Todo: # GET PROXY out of the ENV!!! # create .wgetrc and pear config proxy... # make a tee out of the output... # # MAJ by florian CRISTINA # Jan 15 2009 # Update Version of Centreon, Nagios ans Nagios Plugin to stable version. # remove webmin install # # # Ask to proceed or exit inquire(){ PROCEED="exit"; echo -n "Shall we continue? (yes, skip, quit) [y]/s/q: " read REPLY if [ -z $REPLY ]; then REPLY="y"; fi if [ $REPLY = "y" ]; then PROCEED=y fi if [ $REPLY = "s" ]; then PROCEED=n fi if [ $PROCEED = "exit" ]; then echo "Exiting." exit 0 fi } doyouwant(){ DOYOUWANT="y"; echo -n "Do you want? (yes, no) [y]/n: " read REPLY if [ -z $REPLY ]; then REPLY="y"; fi if [ $REPLY = "y" ]; then DOYOUWANT=y fi if [ $REPLY = "n" ]; then DOYOUWANT=n fi } ## # Make sure we're root if [ "$UID" != "0" ]; then echo "Error: You must be root" exit 1 fi SCRIPTVERSION=0.2 #DISTRO=Fedora #ARCH=i386 #BDIR=redhat DISTRO=ubuntu ARCH=i386 BDIR=debian BASEDIR=/usr/local/src EXTN=tar.gz NAGIURL=http://switch.dl.sourceforge.net/sourceforge/nagios NAGI=nagios-3.0.6 NPLUGURL=http://downloads.sourceforge.net/nagiosplug NPLUG=nagios-plugins-1.4.13 NDOUURL=http://surfnet.dl.sourceforge.net/sourceforge/nagios NDOU=ndoutils-1.4b7 CENTURL=http://download.centreon.com/index.php?id=100 CENT=centreon-2.0 clear echo "Centron Appliance Installer (version $SCRIPTVERSION)" echo "" echo " 1. Installation of prerequisites" inquire clear if [ $PROCEED = "y" ]; then echo "1.1. Miscellaneous" apt-get -y install sudo sysutils mailx lsb-release sharutils echo "1.2. Compiler" apt-get -y install build-essential echo "1.3. Web server and PHP5" apt-get -y install phpmyadmin apache2 php5 php5-mysql php-pear php5-ldap php5-snmp php5-gd echo "1.4. MySQL Server" apt-get -y install mysql-server-5.0 libmysqlclient15-dev echo "1.5. RRDTool" apt-get -y install rrdtool librrds-perl echo "1.6. Perl" apt-get -y install libconfig-inifiles-perl libcrypt-des-perl libdigest-hmac-perl libdigest-sha1-perl libgd-gd2-perl echo "1.7. SNMP" apt-get -y install snmp snmpd libnet-snmp-perl libsnmp-perl echo "1.8. GD-libraries" apt-get -y install libgd2-xpm libgd2-xpm-dev libpng-dev echo ">>> If no errors ocoured, the system is prepared so now we can install Nagios, the plugins, NDOUtils and centreon!" fi echo " 2. Installation of Nagios 3" inquire clear if [ $PROCEED = "y" ]; then echo "2.1. Creating the user nagios" /usr/sbin/useradd -m nagios passwd nagios echo "2.2. Creating a group to be able to use external commands" /usr/sbin/groupadd nagcmd /usr/sbin/usermod -G nagcmd,nagios nagios #if [ $DISTRO = "Fedora" ]; then # /usr/sbin/usermod -G nagcmd apache #fi #if [ $DISTRO = "Debian" ]; then /usr/sbin/usermod -G nagcmd www-data #fi #if [ $DISTRO = "OpenSuse" ]; then # /usr/sbin/usermod -G nagcmd www #fi echo "2.3. Download and Compile" cd $BASEDIR wget $NAGIURL/$NAGI.$EXTN tar -xzf $NAGI.$EXTN cd $NAGI ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep make all make install make install-init make install-commandmode make install-config echo ">>> If no error ocoured, Nagios is installed so we can continue with the installation of the plugins." fi echo " 3. Installation of Nagios plugins" inquire clear if [ $PROCEED = "y" ]; then cd $BASEDIR wget $NPLUGURL/$NPLUG.$EXTN tar -xzf $NPLUG.$EXTN cd $NPLUG ./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install echo ">>> If no error ocoured, that's it. The plugins are installed." fi echo " 4. Installation of NDOutils" inquire clear if [ $PROCEED = "y" ]; then echo "4.1. Download & make" echo "" cd $BASEDIR wget $NDOUURL/$NDOU.$EXTN tar -xzf $NDOU.$EXTN cd $BASEDIR/$NDOU echo "Do you want to read the README file? (RECOMMENDED!)" doyouwant if [ $DOYOUWANT = "y" ]; then less README fi ./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios make echo "4.2. manual installation (no make install :-()" echo "4.2.1. After creating the binaries and libraries they have to be copied " echo "" cp ./src/ndomod-*.o /usr/local/nagios/bin/ cp ./src/ndo2db* /usr/local/nagios/bin/ chmod 774 /usr/local/nagios/bin/ndo* chown nagios:nagios /usr/local/nagios/bin/ndo* echo "4.2.2. copy config files " echo "" cp ./config/ndo* /usr/local/nagios/etc/ cat ./config/nagios.cfg >> /usr/local/nagios/etc/nagios.cfg echo "4.2.3. edit nagios.cfg to select the broker module for Nagios 3.x " echo "" cd /usr/local/nagios/etc cp -u nagios.cfg nagios.cfg.bak cat nagios.cfg | sed -e 's/^broker_module\=\/usr\/local\/nagios\/bin\/ndomod-2x\.o config_file\=\/usr\/local\/nagios\/etc\/ndomod\.cfg/\#broker_module\=\/usr\/local\/nagios\/bin\/ndomod-2x\.o config_file\=\/usr\/local\/nagios\/etc\/ndomod\.cfg/' > nagios.cfg.new mv -f nagios.cfg.new nagios.cfg cat nagios.cfg | sed -e 's/^\#broker_module\=\/usr\/local\/nagios\/bin\/ndomod-3x\.o config_file\=\/usr\/local\/nagios\/etc\/ndomod\.cfg/broker_module\=\/usr\/local\/nagios\/bin\/ndomod-3x\.o config_file\=\/usr\/local\/nagios\/etc\/ndomod\.cfg/' > nagios.cfg.new mv -f nagios.cfg.new nagios.cfg cat nagios.cfg | sed -e 's/^#event_broker_options=-1/event_broker_options=-1/' > nagios.cfg.new mv -f nagios.cfg.new nagios.cfg echo "4.2.4. build database" echo "" echo "Please choose ndo@localhost mysql password: [good_password]" stty -echo read GOOD_PASSWORD stty echo if [ -z $GOOD_PASSWORD ]; then GOOD_PASSWORD="good_password"; fi echo "As MySQL root user, please " echo "CREATE DATABASE ndo DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT SELECT, INSERT, UPDATE, DELETE ON ndo.* TO ndo@localhost IDENTIFIED BY '$GOOD_PASSWORD'; FLUSH PRIVILEGES; SOURCE ./db/mysql.sql" | mysql -u root -p echo "4.2.5. make ndo2db daemon autorun (create /etc/init.d/ndo2db)" uudecode << "EOF" begin 644 ndo2db M(R$O8FEN+W-H"B,@"B,@075T:&]R(#H@1V'#JW1A;B!,=6-AB`B)$YD;U!)1"(@73L@=&AE;@H)"0EE M8VAO("(@("`@($YO(&YD;S)D8B!P&ET(#$* M"0EE;'-E"@D)"65C:&\@(B`@("`@9F]U;F0@<')O8V5S2P@ MV5X96-?<')E M9FEX?2]B:6XO;F1O,F1B"DYD;T-F9T9I;&4])'MP&5C=71A8FQE(&9I;&4@)$YD;T)I;B!N;W0@ M9F]U;F0N("!%>&ET:6YG+B(*("`@97AI="`Q"F9I"@HC($-H96-K('1H870@ M;F1O+F-F9R!E>&ES=',N"FEF(%L@(2`M9B`D3F1O0V9G1FEL92!=.R!T:&5N M"B`@(&5C:&\@(D-O;F9I9W5R871I;VX@9FEL92`D3F1O0V9G1FEL92!N;W0@ M9F]U;F0N("!%>&ET:6YG+B(*("`@97AI="`Q"F9I"B`@("`@("`@("`*(R!3 M964@:&]W('=E('=E&ET(#`*"0EE;'-E"@D)"65C:&\@(B!F86EL960N(@H)"0DD,"!S=&]P"@D) M"65X:70@,0H)"69I"@D).SL*"@ES=&]P*0H)"65C:&\@+6X@(E-T;W!P:6YG M(&YD;SH@(@H*"0EP:61?;F1O"@D):VEL;'!R;V-?;F1O"@H)"2,@;F]W('=E M(&AA=F4@=&\@=V%I="!F;W(@;F1O('1O(&5X:70@86YD(')E;6]V92!I=',* M"0DC(&]W;B!.9&]2=6Y&:6QE+"!O=&AE2!M86YN97(G"@D)96QS90H)"2`@("!E8VAO("=D;VYE+B<* M(`D)9FD*"@D)W-T87)T?'-T;W!\>> If no errors ocoured, the NDOUtils are installed, but still need some tweaks" fi echo " 5. Installation of Centreon (Beta)" inquire clear if [ $PROCEED = "y" ]; then echo "5.1. download the archive" cd $BASEDIR/ wget $CENTURL tar -xzf $CENT.$EXTN cd $CENT export PATH="$PATH:/usr/local/nagios/bin/" ./install.sh -i fi echo " 6. Web installation of Centreon (Beta)" inquire clear if [ $PROCEED = "y" ]; then echo "The installation will continue using the URL: http://SERVER_ADDRESS/centreon. You will be redirected to http://SERVER_ADDRESS/centreon/install/setup.php" echo "You have a tutorial in http://en.doc.centreon.com/Nagios3_Centreon2_Ubuntu_centreon_web" fi echo " 7. Installation of NDO (Part 2)" inquire clear if [ $PROCEED = "y" ]; then cd $BASEDIR/$CENT echo "As MySQL root user, please " echo "SOURCE $BASEDIR/$CENT/www/install/createNDODB.sql" | mysql -u root -p ndo fi echo " 8. Installation test" /etc/init.d/nagios start /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg NDOMODERROR=`grep "ndomod: Successfully connected to data sink." /usr/local/nagios/var/nagios.log|tail -1` echo $NDOMODERROR if [ -z $NDOMODERROR ]; then echo "Finished, but NOK! Check the installation, please!" fi echo "" echo "Final Note:" echo "If in the web frontend you have a \"NDO Database connection\" error do:" echo "echo \"update cfg_ndo2db set db_name=\"centreondb\",db_user=\"centreondb\",db_pass=\"your_password\" where id=1;\" \|mysql -u root -p centreondb" exit 0