<\/span><\/h2>\n\n\n\nFirst, log in to your Ubuntu 20.04 server via SSH as the root user:<\/p>\n\n\n\n
ssh root@IP_Address -p Port_number<\/pre>\n\n\n\nYou will need to replace ‘IP_Address’ and ‘Port_number’ with your server\u2019s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the admin account if necessary.<\/p>\n\n\n\n
Before starting, you have to make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:<\/p>\n\n\n\n
apt-get update -y\napt-get upgrade -y<\/pre>\n\n\n\n<\/span>Step 2: Install Required Dependencies<\/span><\/h2>\n\n\n\nBefore starting, you will need to install some dependencies required to install Nagios in your system. You can install all of them with the following command:<\/p>\n\n\n\n
apt-get install autoconf bc gawk dc build-essential gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gettext -y<\/pre>\n\n\n\nOnce all the dependencies are installed, you can proceed to download the Nagios 4 core.<\/p>\n\n\n\n
<\/span>Step 3: Download and Install Nagios 4<\/span><\/h2>\n\n\n\nFirst, download the latest version of Nagios 4 from its official website using the following command:<\/p>\n\n\n\n
wget https:\/\/assets.nagios.com\/downloads\/nagioscore\/releases\/nagios-4.4.6.tar.gz<\/pre>\n\n\n\nOnce the download is completed, extract the downloaded file with the following command:<\/p>\n\n\n\n
tar -xvzf nagios-4.4.6.tar.gz<\/pre>\n\n\n\nNext, change the directory to the extracted directory and configure it with the following command:<\/p>\n\n\n\n
cd nagios-4.4.6\n.\/configure --with-httpd-conf=\/etc\/apache2\/sites-enabled<\/pre>\n\n\n\nYou should get the following output:<\/p>\n\n\n\n
Nagios user\/group: nagios,nagios\n Command user\/group: nagios,nagios\n Event Broker: yes\n Install ${prefix}: \/usr\/local\/nagios\n Install ${includedir}: \/usr\/local\/nagios\/include\/nagios\n Lock file: \/run\/nagios.lock\n Check result directory: \/usr\/local\/nagios\/var\/spool\/checkresults\n Init directory: \/lib\/systemd\/system\n Apache conf.d directory: \/etc\/apache2\/sites-enabled\n Mail program: \/bin\/mail\n Host OS: linux-gnu\n IOBroker Method: epoll\n\n Web Interface Options:\n ------------------------\n HTML URL: http:\/\/localhost\/nagios\/\n CGI URL: http:\/\/localhost\/nagios\/cgi-bin\/\n Traceroute (used by WAP): \n\n\nReview the options above for accuracy. If they look okay,\ntype 'make all' to compile the main program and CGIs.\n<\/pre>\n\n\n\nNext, build the Nagios with the following command:<\/p>\n\n\n\n
make all<\/pre>\n\n\n\nNext, create a Nagios user and group and add it to the www-data group with the following command:<\/p>\n\n\n\n
make install-groups-users\nusermod -a -G nagios www-data<\/pre>\n\n\n\nNext, run the following command to install Nagios binaries, daemon and command mode:<\/p>\n\n\n\n
make install\nmake install-daemoninit\nmake install-commandmode<\/pre>\n\n\n\nNext, install sample script config and Apache web configuration using the following command:<\/p>\n\n\n\n
make install-config\nmake install-webconf<\/pre>\n\n\n\nNext, enable the rewrite and cgi module with the following command:<\/p>\n\n\n\n
a2enmod rewrite cgi<\/pre>\n\n\n\nNext, restart the Apache service to apply the changes:<\/p>\n\n\n\n
systemctl restart apache2<\/pre>\n\n\n\n<\/span>Step 4: Create a Nagios Admin User<\/span><\/h2>\n\n\n\nNext, you will need to create a Nagios user to access the Nagios web interface. You can create it with the following command:<\/p>\n\n\n\n
htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/pre>\n\n\n\nYou will be asked to set a password as shown below:<\/p>\n\n\n\n
New password: \nRe-type new password: \nAdding password for user nagiosadmin\n<\/pre>\n\n\n\n