One-Click Nagios Setup: Execute Setup Script

ยท

2 min read

Setting Up Nagios Master Server

  • Create a .sh file on your server, give it execute permissions

    (chmod +x setup_nagios.sh), and copy the following content into it. Replace nagios-4.5.0 with your desired Nagios version

  • This .sh file will ask to enter password which will use to sign in to Nagios

#!/bin/bash

# Update package lists
sudo apt-get update

# Install prerequisites
sudo apt-get install -y wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev

# Download Nagios Core
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.0.tar.gz

# Extract Nagios Core
tar zxvf nagios-4.5.0.tar.gz
cd nagios-4.5.0

# Configure Nagios Core
sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

# Add Nagios users and groups
sudo make install-groups-users
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data


# Copy event handlers
sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

# Install Apache configuration
sudo make install-webconf

# Create Nagios admin user
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# Enable Apache modules
sudo a2enmod cgi rewrite

# Restart Apache service
sudo systemctl restart apache2

# Install Nagios plugins
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-2.4.4.tar.gz
tar -zxvf nagios-plugins-2.4.4.tar.gz
cd nagios-plugins-2.4.4
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
sudo make
sudo make install
#!/bin/bash

# Update package lists
sudo apt-get update

# Install prerequisites
sudo apt-get install -y wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev

# Download Nagios Core
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.0.tar.gz

# Extract Nagios Core
tar zxvf nagios-4.5.0.tar.gz
cd nagios-4.5.0

# Configure Nagios Core
sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

# Add Nagios users and groups
sudo make install-groups-users
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data

# Copy event handlers
sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

# Install Apache configuration
sudo make install-webconf

# Enable Apache modules
sudo a2enmod cgi rewrite

# Restart Apache service
sudo systemctl restart apache2

# Install Nagios plugins
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-2.4.4.tar.gz
tar -zxvf nagios-plugins-2.4.4.tar.gz
cd nagios-plugins-2.4.4
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
sudo make
sudo make install

# Make the following directory
sudo mkdir /usr/local/nagios/etc/servers

# Create Nagios admin user
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# Verify the configuration before starting Nagios.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

# Start Nagios service
sudo systemctl start nagios
sudo systemctl enable nagios

# Configure Nagios to monitor servers
sudo sed -i 's/#cfg_dir=\/usr\/local\/nagios\/etc\/servers/cfg_dir=\/usr\/local\/nagios\/etc\/servers/' /usr/local/nagios/etc/nagios.cfg

# Access Nagios Web Interface
echo "Access Nagios at http://server-ip/nagios/"
echo "Username: nagiosadmin"
echo "Password: (set during 'htpasswd' configuration)"
  • Access Nagios with http://server-ip/nagios/

  • username => nagiosadmin

  • password => configured by you (when prompted to enter password)

Did you find this article valuable?

Support AyushDabhi by becoming a sponsor. Any amount is appreciated!

ย