{"id":2037,"date":"2020-11-23T19:32:39","date_gmt":"2020-11-23T19:32:39","guid":{"rendered":"https:\/\/linuxways.net\/?p=2037"},"modified":"2020-11-23T19:46:50","modified_gmt":"2020-11-23T19:46:50","slug":"how-to-install-and-configure-nagios-on-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-install-and-configure-nagios-on-linux\/","title":{"rendered":"How to install and configure Nagios on Linux"},"content":{"rendered":"<p>Nagios is a popular and open-source application that is used for continuous monitoring of systems, networks, services, and applications. It constantly monitors the status of machines and various services. In case any of any issue, it provides early warning so that administrator can take required actions. Nagios performs all checks on local and host machines using the external programs-known as plugins. It also provides you with a web interface that allows viewing the status of hosts and services, history, logs, and generating reports.<\/p>\n<p>In this post, we will be explaining how to install and configure Nagios on Linux and monitor other Linux servers&#8217; health. We will be using the two Debian 10 (Buster) servers; both on the same network. On the monitoring server, we will install the Nagios core, Nagios plugin, and check_nrpe plugin. While on the remote host, we will install the Nagios plugin and NRPE.<\/p>\n<h2>Terminologies<\/h2>\n<p>Let\u2019s understand some terminologies which help you to understand the configurations:<\/p>\n<p><strong>Host<\/strong>: It is a device that needs to be monitored such as a physical machine, workstation, or network device.<\/p>\n<p><strong>Service<\/strong>: It is the service or resource being monitored on the host such as HTTP, SMTP, POP, DNS, number of logged-in users, memory usage, etc.<\/p>\n<p><strong>Nagios Plugin: <\/strong>These are scripts that check the status of a host or service and verify whether they are working correctly. There are some predefined plugins that can check basic resources such as processor load, disk usage, ping rates, etc. Plugins are usually located in <strong>\/usr\/local\/nagios\/libexec<\/strong> directory.<\/p>\n<p><strong>NRPE (Nagios Remote Plugin Executor) add-on: <\/strong>NRPE add-on executes the plugins on the remote Linux hosts which then allows Nagios to keep an eye on local resources (disk space, memory usage, etc). NRPE add-on comprises of:<\/p>\n<ul>\n<li><strong>NRPE daemon<\/strong>&#8211; It runs on remote Linux\/Unix hosts which needs to be monitored<\/li>\n<li><strong>check_nrpe plugin<\/strong>&#8211; It is used by the Nagios monitoring server<\/li>\n<\/ul>\n<p>\u00a0You must have sudo privileges on both the servers. The details of our machines are as follows:<\/p>\n<p><strong>Nagios Monitoring Server:<\/strong><\/p>\n<ul>\n<li>Hostname: nagios-server,<\/li>\n<li>IP address: 192.168.72.158<\/li>\n<\/ul>\n<p><strong>Nagios Host:<\/strong><\/p>\n<ul>\n<li>Hostname: client<\/li>\n<li>IP address: 192.168.72.159<\/li>\n<\/ul>\n<h2>Step 1 &#8211; Installing Nagios Core on Monitoring Server<\/h2>\n<p>On the Nagios monitoring server, follow the below steps to download and install the Nagios core.<\/p>\n<h3>1. Installing Prerequisites<\/h3>\n<p>First, we will need to install Prerequisites on the Nagios monitoring server. To do so, update the packages list using the below command in Terminal:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>Then install the required packages:<\/p>\n<pre>$ sudo apt install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.4 libgd-dev openssl libssl-dev<\/pre>\n<h3>2. Download the Nagios Source<\/h3>\n<p>Navigate to the <strong>\/tmp<\/strong> directory:<\/p>\n<pre>$ cd \/tmp<\/pre>\n<p>Then download the Nagios source code using the <strong>wget<\/strong> command. We will download the currently available latest version of Nagios that is <strong>4.4.6<\/strong>. You can visit the Nagios <a href=\"http:\/\/www.nagios.org\/download\/core-stay-informed\">Downloads<\/a> to look for the current stable release.<\/p>\n<pre>$ wget -O nagios.tar.gz <a href=\"https:\/\/github.com\/NagiosEnterprises\/nagioscore\/archive\/nagios-4.4.6.tar.gz\">https:\/\/github.com\/NagiosEnterprises\/nagioscore\/archive\/nagios-4.4.6.tar.gz<\/a><\/pre>\n<p>The downloaded file will be saved as <strong>nagios.tar.gz<\/strong> in the <strong>\/tmp<\/strong> directory.<\/p>\n<h3>3. Compile Source<\/h3>\n<p>Extract the downloaded archive <strong>nagios.tar.gz <\/strong>using the below command<strong>:<\/strong><\/p>\n<pre>$ tar -xzf nagios.tar.gz<\/pre>\n<p>Move into the extracted folder using the <strong>cd<\/strong> command:<\/p>\n<pre>$ cd nagioscore-nagios-4.4.6\/<\/pre>\n<p>Run the <strong>configure<\/strong> script and specifies the path to the Apache server configuration directory:<\/p>\n<pre>$ .\/configure --with-httpd-conf=\/etc\/apache2\/sites-enabled<\/pre>\n<p>Once the configure script is executed, you will see the below summary at the end of the output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"650\" class=\"wp-image-2038\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-612.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-612.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-612-300x254.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>Your <strong>configure<\/strong> script may fail in case of any pre-requisite missing. In that case, install the missing pre-requisites and again run the script.<\/p>\n<p>Now compile Nagios using the below command:<\/p>\n<pre>$ make all<\/pre>\n<h3>4. Create User and Group<\/h3>\n<p>Now create user and group for Nagios.<\/p>\n<pre>$ sudo make install-groups-users <\/pre>\n<p>The above command will create a system user and group Nagios.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"90\" class=\"wp-image-2039\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-613.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-613.png 926w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-613-300x29.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-613-768x75.png 768w\" sizes=\"auto, (max-width: 926px) 100vw, 926px\" \/><\/p>\n<p>We will also need to add user \u201c<strong>www-data<\/strong>&#8221; to the <strong>nagios<\/strong> group.<\/p>\n<pre>$ sudo usermod -a -G nagios www-data<\/pre>\n<h3>5. Installing Binaries<\/h3>\n<p>Then to install binaries, use the below command:<\/p>\n<pre>$ sudo make install<\/pre>\n<h3>6. Install Service \/ Daemon<\/h3>\n<p>To install service files, use the below command:<\/p>\n<pre>$ sudo make install-daemoninit<\/pre>\n<h3>7. Install Command Mode<\/h3>\n<p>To install and configures the external command file, use the below command:<\/p>\n<pre>$ sudo make install-commandmode<\/pre>\n<h3>8. Install Configuration Files<\/h3>\n<p>Then to install the sample Nagios configuration, use the below command:<\/p>\n<pre>$ sudo make install-config<\/pre>\n<h3>9. Install Apache Config Files<\/h3>\n<p>This installs the Apache configuration files, use the below command:<\/p>\n<pre>$ sudo make install-webconf<\/pre>\n<p>Now enable the Apache modules using the below commands:<\/p>\n<pre>$ sudo a2enmod rewrite<\/pre>\n<pre>sudo a2enmod cgi<\/pre>\n<h4>Create Nagiosadmin User Account for the Web Interface:<\/h4>\n<p>Now we will create an Apache user account that can access the Nagios web interface.<\/p>\n<pre>$ sudo htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/pre>\n<p>Now set the password for the <strong>nagiosadmin<\/strong> user account. This password will be used to access the Nagios\u2019 web interface.<\/p>\n<p>Then restart Apache for the configuration changes to take effect:<\/p>\n<pre>$ sudo systemctl restart apache2<\/pre>\n<p>Now we have successfully installed the Nagios core engine.<\/p>\n<h2>Step 2 &#8211; Installing the Nagios Plugin on Monitoring Server<\/h2>\n<p>For the Nagios core to work properly, you will need to install the Nagios plugin.<\/p>\n<h3>Download Nagios Plugin<\/h3>\n<p>On the Nagios server, Navigate to the <strong>\/tmp<\/strong> directory:<\/p>\n<pre>$ cd \/tmp<\/pre>\n<p>Then download the Nagios plugin source code using the <strong>wget<\/strong> command. We will download the currently available latest version of the Nagios plugin that is <strong>2.3.3.<\/strong> You can visit the <a href=\"https:\/\/github.com\/nagios-plugins\/nagios-plugins\/releases\">Github<\/a> page to find the recent stable release.<\/p>\n<pre>$ wget -O Nagios-plugins.tar.gz <a href=\"https:\/\/github.com\/nagios-plugins\/nagios-plugins\/releases\/download\/release-2.3.3\/nagios-plugins-2.3.3.tar.gz\">https:\/\/github.com\/nagios-plugins\/nagios-plugins\/releases\/download\/release-2.3.3\/nagios-plugins-2.3.3.tar.gz<\/a><\/pre>\n<p>The downloaded file will be saved as <strong>Nagios-plugins.tar.gz<\/strong> in the <strong>\/tmp<\/strong> directory.<\/p>\n<h3>Compile<\/h3>\n<p>Extract the downloaded archive <strong>Nagios-plugins.tar.gz<\/strong> using the below command<strong>:<\/strong><\/p>\n<pre>$ tar zxf nagios-plugins.tar.gz<\/pre>\n<p>Navigate to the extracted folder using the <strong>cd<\/strong> command:<\/p>\n<pre>$ cd nagios-plugins-2.3.3\/<\/pre>\n<p>Run the <strong>configure<\/strong> script:<\/p>\n<pre>$ sudo .\/configure<\/pre>\n<p>Now compile the Nagios plugin using the below command:<\/p>\n<pre>$ sudo make <br \/>$ sudo make install<\/pre>\n<h2>Step 3 &#8211; Installing the check_nrpe Plugin on Monitoring Server<\/h2>\n<p>Now we will install <strong>check_nrpe<\/strong> plugin on our Nagios server.<\/p>\n<h3>Download Plugin Source<\/h3>\n<p>On the Nagios server, Navigate to the <strong>\/tmp<\/strong> directory:<\/p>\n<pre>$ cd \/tmp<\/pre>\n<p>Then download the check_nrpe source code using the wget command. We will download the recent available version of check_nrpe that is 4.0.3. You can visit the <a href=\"https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\">Github<\/a> page to find the recent stable release.<\/p>\n<pre>$ wget -O Nagios-nrpe.tar.gz https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/download\/nrpe-4.0.3\/nrpe-4.0.3.tar.gz<\/pre>\n<p>The downloaded file will be saved as <strong>Nagios-nrpe.tar.gz<\/strong> in the <strong>\/tmp<\/strong> directory.<\/p>\n<h3>Compiling the Source<\/h3>\n<p>Extract the downloaded archive <strong>nagios.tar.gz <\/strong>using the below command<strong>:<\/strong><\/p>\n<pre>$ tar -xzf Nagios-nrpe.tar.gz<\/pre>\n<p>Navigate to the extracted folder using the <strong>cd<\/strong> command:<\/p>\n<pre>$ cd nrpe-4.0.3\/<\/pre>\n<p>Run the <strong>configure<\/strong> script:<\/p>\n<pre>$ sudo .\/configure<\/pre>\n<p>Now compile the<strong> check_nrpe<\/strong> using the below command:<\/p>\n<pre>$ sudo make check_nrpe<br \/><br \/>$ sudo make install-plugin<\/pre>\n<h2>Step 4 &#8211; Configuring Nagios<\/h2>\n<p>Now, we will configure the Nagios main configuration file. Edi the Nagios configuration file <strong>nagios.cfg<\/strong> using the below command:<\/p>\n<pre>$ sudo nano \/usr\/local\/nagios\/etc\/nagios.cfg<\/pre>\n<p>Now find the below line in the file and uncomment it by removing the <strong>#<\/strong> character from the beginning of the line.<\/p>\n<pre>#cfg_dir=\/usr\/local\/nagios\/etc\/servers<\/pre>\n<p>The above line specifies the directory which contains a configuration file for all the hosts that the Nagios server will monitor. Now save and close the configuration file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"369\" class=\"wp-image-2040\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-614.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-614.png 794w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-614-300x139.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-614-768x357.png 768w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/p>\n<p>Now we will create the directory in the path defined above:<\/p>\n<pre>$ sudo mkdir \/usr\/local\/nagios\/etc\/servers<\/pre>\n<h3>Configure E-mail Contacts<\/h3>\n<p>Now we will configure the contacts that should be notified in case of any event. Edit the Nagios contacts configuration using the below command:<\/p>\n<p>In order to receive alerts from the Nagios monitoring server, you will need to configure the contacts. Open the <strong>contacts <\/strong>configuration file, and specify the email address you would like to receive the emails from Nagios:<\/p>\n<pre>$ sudo nano \/usr\/local\/nagios\/etc\/objects\/contacts.cfg<\/pre>\n<p>In the email directive, replace nagios@<strong>localhost<\/strong> with your own email address and then save and close the file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1052\" height=\"287\" class=\"wp-image-2041\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-615.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-615.png 1052w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-615-300x82.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-615-1024x279.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-615-768x210.png 768w\" sizes=\"auto, (max-width: 1052px) 100vw, 1052px\" \/><\/p>\n<h3>Configure check_nrpe<\/h3>\n<p>Now in order to use <strong>check_nrpe<\/strong> plugin, we will add a new command in the <strong>command <\/strong>configuration file. Edit the command configuration file <strong>commands.cfg <\/strong>using the below command:<\/p>\n<pre><strong>$ sudo nano \/usr\/local\/nagios\/etc\/objects\/commands.cfg <\/strong><\/pre>\n<p>Append the following lines to the end of the <strong>commands.cfg<\/strong> file and then save and close it:<\/p>\n<pre>define command{<br \/><br \/>command_name check_nrpe<br \/><br \/>command_line $USER1$\/check_nrpe -H $HOSTADDRESS$ -c $ARG1$<br \/><br \/>}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"286\" class=\"wp-image-2042\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-616.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-616.png 953w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-616-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-616-768x230.png 768w\" sizes=\"auto, (max-width: 953px) 100vw, 953px\" \/><\/p>\n<p>Now start Nagios service:<\/p>\n<pre>$ sudo systemctl start Nagios.service<\/pre>\n<h2>Step 5 &#8211; Accessing the Nagios Web Interface<\/h2>\n<p>Now access the Nagios web interface by visiting the below address in any web browser:<\/p>\n<pre><a href=\"http:\/\/nagios-server-ip\/nagios\">http:\/\/nagios-server-ip\/nagios<\/a><\/pre>\n<p>In our scenario, it would be:<\/p>\n<pre>http:\/\/192.168.72.158\/nagios<\/pre>\n<p>In the <strong>Authentication Required<\/strong> dialog, type <strong>nagiosadmin<\/strong> as the username and password you have set earlier.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"429\" class=\"wp-image-2043\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-617.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-617.png 1000w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-617-300x129.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-617-768x329.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/p>\n<p>Once logged in to the web nterface, you will see the default Nagios web page. Go to the <strong>Hosts<\/strong> tab from the left sidebar to view the monitored hosts.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1197\" height=\"517\" class=\"wp-image-2044\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-618.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-618.png 1197w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-618-300x130.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-618-1024x442.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-618-768x332.png 768w\" sizes=\"auto, (max-width: 1197px) 100vw, 1197px\" \/><\/p>\n<p>At present, you will see only one host \u201c<strong>localhost<\/strong>&#8221; which is the Nagios server itself. In order to monitor other hosts, you will need to install <strong>the NRPE<\/strong> daemon on them.<\/p>\n<h2>Step 6 &#8211; Remote Host Setup<\/h2>\n<p>Now you will have to install <strong>the Nagios plugin<\/strong> and <strong>NRPE<\/strong> on the hosts that need to be monitored on the Nagios server.<\/p>\n<h3>1. Install Nagios Plugin on Remote Host<\/h3>\n<p>In the remote host (client) that needs to be monitored, follow the below steps to install Nagios plugin.<\/p>\n<p>1. First, update the apt:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>2. Then issue the below command to install the required packages:<\/p>\n<pre>$ sudo apt install autoconf gcc libmcrypt-dev make libssl-dev dc build-essential gettext<\/pre>\n<p>3. Now, Navigate to <strong>\/tmp<\/strong> and download the Nagios plugin.<\/p>\n<pre>$ cd \/tmp<\/pre>\n<pre>$ wget -O Nagios-plugins.tar.gz https:\/\/github.com\/nagios-plugins\/nagios-plugins\/releases\/download\/release-2.3.3\/nagios-plugins-2.3.3.tar.gz<\/pre>\n<p>4. Extract the downloaded archive:<\/p>\n<pre>$ tar -zxf nagios-plugins.tar.gz<\/pre>\n<p>5. Move into extracted folder and run the <strong>configure<\/strong> script:<\/p>\n<pre>$ cd nagios-plugins-2.3.3\/\/ <br \/>$ sudo .\/configure<\/pre>\n<p>6. Compile the plugin:<\/p>\n<pre>$ sudo make <br \/>$ sudo make install<\/pre>\n<h3>2. Install NRPE Daemon on Remote Host<\/h3>\n<p>Follow the below steps to install NRPE on the remote host.<\/p>\n<p>1. First, update the apt:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>2. Issue the below command to install the pre-requisites:<\/p>\n<pre>$ sudo apt install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev<\/pre>\n<p>3. Now Navigate to <strong>\/tmp<\/strong> and download NRPE.<\/p>\n<pre>$ cd \/tmp <br \/>$ wget -O nrpe.tar.gz <a href=\"https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/download\/nrpe-4.0.3\/nrpe-4.0.3.tar.gz\">https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/download\/nrpe-4.0.3\/nrpe-4.0.3.tar.gz<\/a><\/pre>\n<p>4. Extract the downloaded archive:<\/p>\n<pre>$ tar xzf nrpe.tar.gz<\/pre>\n<p>5. \u00a0Move into the extracted folder and run the configure script:<\/p>\n<pre>$ sudo .\/configure --enable-command-args<\/pre>\n<p>6. Compile the NRPE with the following commands:<\/p>\n<pre>$ sudo make all<\/pre>\n<pre>$ make install-groups-users<br \/><br \/>$ sudo make install<br \/><br \/>$ sudo make install-config<br \/><br \/>$ sudo make install-init<\/pre>\n<h3>3. Configure Firewall<\/h3>\n<p>Now if a firewall is running on your remote host, you will need to open port 5666 (used by NRPE) through it.<\/p>\n<pre>$ sudo ufw allow 5666\/tcp<\/pre>\n<h3>4. Update NRPE Configuration<\/h3>\n<p>Now open the NRPE configuration file in the remote host:<\/p>\n<pre>$ sudo nano \/usr\/local\/nagios\/etc\/nrpe.cfg<\/pre>\n<p>You will need to find and modify the below entries:<\/p>\n<p>Add client IP address:<\/p>\n<pre>server_address=192.168.72.159<br \/><br \/>Add Nagios server IP address:<br \/><br \/>allowed_hosts=127.0.0.1,192.168.72.158<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"255\" class=\"wp-image-2045\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-619.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-619.png 781w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-619-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-619-768x251.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/p>\n<p>Also, replace <strong>\/dev\/vda1<\/strong> with your root file system:<\/p>\n<pre>command[check_disk]=\/usr\/local\/nagios\/libexec\/check_disk -w 20% -c 10% -p \/dev\/sda1<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"976\" height=\"320\" class=\"wp-image-2046\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-620.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-620.png 976w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-620-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-620-768x252.png 768w\" sizes=\"auto, (max-width: 976px) 100vw, 976px\" \/><\/strong><\/p>\n<p>Then start the NRPE service:<\/p>\n<pre>$ sudo systemctl start nrpe.service<\/pre>\n<p>Now check if the NRPE service is properly running:<\/p>\n<pre>$ sudo systemctl status nrpe.service<\/pre>\n<p>The active (running) in the below output shows that the service is successfully running without any issues. You can also see the NRPE is allowing connection from <strong>192.168.72.158<\/strong> which is the IP address of the Nagios server.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"415\" class=\"wp-image-2047\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-621.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-621.png 975w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-621-300x128.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-621-768x327.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/p>\n<p>Now to check if the <strong>check_nrpe<\/strong> <strong>on the Nagios server<\/strong> can communicate with the <strong>NRPE on the remote host<\/strong>, issue this command on the <strong>Nagios server<\/strong>:<\/p>\n<pre>$ \/usr\/local\/nagios\/libexec\/check_nrpe -H remote_host_ip<\/pre>\n<p>You should receive the following similar output (NRPE version number).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2048\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-622.png\" alt=\"How to install Nagios on Linux\" width=\"893\" height=\"69\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-622.png 893w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-622-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-622-768x59.png 768w\" sizes=\"auto, (max-width: 893px) 100vw, 893px\" \/><\/p>\n<h3>Step 7 &#8211; Add Host Configuration to the Nagios Server<\/h3>\n<p>Now in the Nagios monitoring server, you will need to create separate configuration files in the <strong>\/usr\/local\/nagios\/etc\/servers<\/strong>\/ for all remote hosts that you need to monitor.<\/p>\n<p>For our host machine, we will create a new configuration file <strong>client.cfg<\/strong>:<\/p>\n<pre>$ sudo nano \/usr\/local\/nagios\/etc\/servers\/client.cfg<\/pre>\n<p>Replace <strong>client<\/strong> with the name of your host:<\/p>\n<p>Now add <strong>host definition<\/strong> to the new configuration file replacing the value of <strong>host_name<\/strong> with the remote hostname, <strong>alias<\/strong> with a short description, and the <strong>address<\/strong> with IP address of the remote host.<\/p>\n<p>This configuration will check if the host machine is up or down.<\/p>\n<pre>define host {<br \/><br \/>use linux-server<br \/><br \/>host_name client<br \/><br \/>alias client machine<br \/><br \/>address 192.168.72.159<br \/><br \/>max_check_attempts 5<br \/><br \/>}<\/pre>\n<p>Now add <strong>service definition<\/strong> to the configuration file for monitoring the remote host. Replace the value of <strong>host_name<\/strong> with the remote hostname.<\/p>\n<p><strong>Note:<\/strong> These service definitions will use the commands preconfigured in the<strong> \/usr\/local\/nagios\/etc\/nrpe.cfg <\/strong>file on the remote host.<\/p>\n<p>Add the following service block to monitor the <strong>CPU load<\/strong> on the remote host<\/p>\n<pre>define service {<br \/><br \/>use generic-service<br \/><br \/>host_name client<br \/><br \/>service_description CPU Load<br \/><br \/>check_command check_nrpe!check_load<br \/><br \/>}<br \/><br \/><br \/>c on the remote host:<\/pre>\n<pre>define service{<br \/><br \/>use generic-service<br \/><br \/>host_name client<br \/><br \/>service_description Total Processes<br \/><br \/>check_command check_nrpe!check_total_procs<\/pre>\n<p>}<\/p>\n<p>Add the following service block to monitor <strong>disk usage<\/strong> on the remote host:<\/p>\n<pre>define service { <br \/>use generic-service\u00a0\u00a0\u00a0\u00a0\u00a0<br \/><br \/>host_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 client <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 service_description\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Check Disk <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 check_command\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check_nrpe!check_disk<\/pre>\n<p>}<\/p>\n<p>Add the following service block to monitor <strong>the number of users<\/strong> <strong>currently logged in <\/strong>on the remote host:<\/p>\n<pre>define service { <br \/>use generic-service\u00a0\u00a0\u00a0\u00a0\u00a0<br \/><br \/>host_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 client <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 service_description\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Current Users <br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 check_command\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check_nrpe!check_users<br \/><br \/>}<\/pre>\n<p>Now save and close the configuration file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2049\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-623.png\" alt=\"How to install Nagios on Linux\" width=\"733\" height=\"481\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-623.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-623-300x197.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<p>Restart the Nagios service to apply the configuration changes:<\/p>\n<pre>$ sudo systemctl restart Nagios<\/pre>\n<p>Now access the web interface using the <a href=\"http:\/\/nagios-server-ip\/nagios.Wait\">http:\/\/nagios-server-ip\/nagios.<\/a> Wait for a while and your remote host will be added to the Nagios web interface.<\/p>\n<p>Go to <strong>Hosts<\/strong> from the left navigation bar and you will see your remote host listed there.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2050\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-624.png\" alt=\"How to install Nagios on Linux\" width=\"1283\" height=\"530\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-624.png 1283w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-624-300x124.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-624-1024x423.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-624-768x317.png 768w\" sizes=\"auto, (max-width: 1283px) 100vw, 1283px\" \/><\/p>\n<p>Then go to <strong>the Services<\/strong> tab, and you will see the status of all the services for a host you have configured for monitoring.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2051\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625.png\" alt=\"How to install Nagios on Linux\" width=\"1681\" height=\"718\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625.png 1681w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625-300x128.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625-1024x437.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625-768x328.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/11\/word-image-625-1536x656.png 1536w\" sizes=\"auto, (max-width: 1681px) 100vw, 1681px\" \/><\/p>\n<p>In this post, we have explained how to install and configure the Nagios monitoring solution on Linux. We have also explained how to setup remote hosts for monitoring. Now you can easily monitor the health of Linux hosts and the services running on them.<\/p>\n<p><a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-and-configure-zabbix-monitoring-server-on-linux\/\"><strong>Click here if you are interested in monitoring your servers with Zabbix.<\/strong><\/a><\/p>\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Nagios is a popular and open-source application that is used for continuous monitoring of systems, networks, services, and applications. It constantly monitors the status of machines and various&hellip;<\/p>","protected":false},"author":4,"featured_media":2060,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,84],"class_list":["post-2037","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-10","tag-nagios-monitoring-server"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2037"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2037\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2060"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}