Prerequisites
Before installing Nagios, make sure you have:
- A dedicated monitoring VPS (recommended)
- Root or sudo privileges
- Apache/Nginx and PHP
Step 1: Install Dependencies
Connect to your monitoring server:
ssh hxroot@MONITOR_IP -p 22
sudo apt update
sudo apt install -y autoconf gcc make libc6-dev libgd-dev libssl-dev apache2 php libapache2-mod-php wget build-essential
Step 2: Download and Compile Nagios Core
cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.7/nagios-4.4.7.tar.gz
tar xzf nagios-4.4.7.tar.gz
cd nagios-4.4.7/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
sudo make install-groups-users
sudo usermod -a -G nagios www-data
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
sudo a2enmod rewrite
sudo a2enmod cgi
Step 3: Install Nagios Plugins
cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.3.3/nagios-plugins-2.3.3.tar.gz
tar xzf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
Step 4: Set Nagios Admin Password
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 5: Start Services
sudo systemctl restart apache2
sudo systemctl start nagios
sudo systemctl enable nagios
Step 6: Access Nagios Web Interface
Open http://YOUR_MONITOR_IP/nagios and log in with nagiosadmin.
Step 7: Configure Host to Monitor
Edit /usr/local/nagios/etc/objects/hosts.cfg and add your VPS.
Restart Nagios after changes:
sudo systemctl restart nagios
✅ Nagios installed. Configure hosts and services to monitor your VPS.