Installer Nagios Core 4.3.2

Un script pour installer Nagios Core sur un serveur Debian 8

#!/bin/bash

# Installation et configuration de nagios server
# Source : https://blog.jolos.fr/2015/09/installer-nagios-4-sur-debian-8/
# Source : https://www.digitalocean.com/community/tutorials/how-to-install-nagios-4-and-monitor-your-servers-on-ubuntu-14-04#install-nagios-4

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

echo "Auteur : Tommy Gingras"
echo "Date : 2017-07-18"
echo "But : Installer et configurer Nagios Server."
echo "Version : 1.0.0"

read -s -p "Entrer le mot de passe pour accéder à nagios web: " password
echo
ip -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {gsub("/", " "); print $2" "$4}'
read -p "Quelle est l'adresse IP privée du serveur ?" privateip
echo

apt-get update
apt-get install -y build-essential libgd2-xpm-dev openssl libssl-dev xinetd apache2-utils apache2 unzip php5

echo -e "${GREEN}Téléchargement des fichiers sources depuis le site de Nagios.${NC}"
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.2.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

echo -e "${GREEN}Création de l'usager Nagios.${NC}"
useradd nagios
mkdir /home/nagios
chown nagios:nagios /home/nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

echo -e "${GREEN}Décompression des fichiers sources de Nagios.${NC}"
tar zxvf nagios-4.3.2.tar.gz
tar zxvf nagios-plugins-2.2.1.tar.gz

cd nagios-4.3.2

echo -e "${GREEN}Installation du système Nagios.${NC}"
./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/conf-available
make all
make install
make install-commandmode
make install-init
make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
usermod -G nagcmd www-data
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

echo -e "${GREEN}Configuration du site avec Apache.${NC}"
a2enmod rewrite
a2enmod cgi

echo -e "${GREEN}Création du service Nagios.${NC}"
echo "[Unit]" > /etc/systemd/system/nagios.service
echo "Description=Nagios" >> /etc/systemd/system/nagios.service
echo "BindTo=network.target" >> /etc/systemd/system/nagios.service
echo "" >> /etc/systemd/system/nagios.service
echo "" >> /etc/systemd/system/nagios.service
echo "[Install]" >> /etc/systemd/system/nagios.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/nagios.service
echo "" >> /etc/systemd/system/nagios.service
echo "[Service]" >> /etc/systemd/system/nagios.service
echo "User=nagios" >> /etc/systemd/system/nagios.service
echo "Group=nagios" >> /etc/systemd/system/nagios.service
echo "Type=simple" >> /etc/systemd/system/nagios.service
echo "ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg" >> /etc/systemd/system/nagios.service

systemctl enable /etc/systemd/system/nagios.service
service apache2 restart

echo -e "${GREEN}Création de l'usager pour accéder à Nagios Web Interface.${NC}"
htpasswd -b -c /usr/local/nagios/etc/htpasswd.users nagiosadmin $password

echo -e "${GREEN}Installation des plugins Nagios.${NC}"
cd /tmp/nagios-plugins-2.2.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

a2ensite nagios

sed -i "/interval_length/cinterval_length=10" /usr/local/nagios/etc/nagios.cfg


service nagios start
service apache2 restart


echo -e "${GREEN}Installation de NRPE.${NC}"

cd /tmp
wget https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

tar xvf nrpe-*.tar.gz
cd nrpe-*

./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

make all
make install
make install-xinetd
make install-daemon-config

sed -i "/only_from*/c\\\tonly_from\t= 127.0.0.1,$privateip" /etc/xinetd.d/nrpe

service xinetd restart

sed -i "s|#cfg_dir=/usr/local/nagios/etc/servers|cfg_dir=/usr/local/nagios/etc/servers|" /usr/local/nagios/etc/nagios.cfg

mkdir -p /usr/local/nagios/etc/servers

sed -i "/email*/c\\\temail root;" /usr/local/nagios/etc/objects/contacts.cfg

echo 'define command{' >> /usr/local/nagios/etc/objects/commands.cfg
echo '        command_name check_nrpe' >> /usr/local/nagios/etc/objects/commands.cfg
echo '        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$' >> /usr/local/nagios/etc/objects/commands.cfg
echo '}' >> /usr/local/nagios/etc/objects/commands.cfg

echo -e "${GREEN}Installation et configuration terminée.${NC}"
echo -e "${RED}Il est fortement recommandé de redémarrer la machine.${NC}"


 

 

Laisser un commentaire