{"id":5628,"date":"2018-12-11T15:58:23","date_gmt":"2018-12-11T15:58:23","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=5628"},"modified":"2018-12-28T20:05:28","modified_gmt":"2018-12-28T20:05:28","slug":"how-to-install-and-configure-nagios-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/11\/how-to-install-and-configure-nagios-on-centos-7\/","title":{"rendered":"How To Install and Configure Nagios on CentOS 7"},"content":{"rendered":"<p>Nagios is one of the most popular open source monitoring systems. Nagios keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running. In case of failure or suboptimal performance Nagios will send notification alerts via various methods.<\/p>\n<p>This tutorial describes how to install and configure Nagios Core on a CentOS 7 server.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Before continuing with this tutorial, make sure you are logged in as a <a href=\"\/post\/create-a-sudo-user-on-centos\/\">user with sudo privileges<\/a>.<\/p>\n<p>Disable SELinux or set in permissive mode as instructed <a href=\"\/post\/how-to-disable-selinux-on-centos-7\/\">here<\/a>.<\/p>\n<p>Update your CentOS system and install <a href=\"\/post\/how-to-install-apache-on-centos-7\/\">Apache<\/a>, <a href=\"\/post\/install-php-7-on-centos-7\/\">PHP<\/a> and all the packages necessary to download and compile the Nagios main application and Nagios plugins:<\/p>\n<p>sudo yum update<br \/>\nsudo yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget<br \/>\nsudo yum install make gettext autoconf net-snmp-utils epel-release perl-Net-SNMP postfix unzip automake<\/p>\n<h2>Installing Nagios on CentOS<\/h2>\n<p>Perform the following steps to install the latest version of Nagios Core from source.<\/p>\n<h3>1. Downloading Nagios<\/h3>\n<p>We\u2019ll download Nagios source in the \/usr\/src directory which is the common location to place source files.<\/p>\n<p>Navigate to the directory with:<\/p>\n<p>Download the latest version of Nagios from the <a href=\"https:\/\/github.com\/NagiosEnterprises\/nagioscore\/releases\">project Github repository<\/a> using the following <a href=\"\/post\/wget-command-examples\/\">wget command<\/a>:<\/p>\n<p>sudo wget https:\/\/github.com\/NagiosEnterprises\/nagioscore\/archive\/nagios-4.4.2.tar.gz<\/p>\n<p>Once the download is complete <a href=\"\/post\/how-to-create-and-extract-archives-using-the-tar-command-in-linux\/\">extract the tar file<\/a> with:<\/p>\n<p>sudo tar zxf nagios-*.tar.gz<\/p>\n<p>Before continuing with the next steps, make sure you change to the Nagios source directory by typing:<\/p>\n<h3>2. Compiling Nagios<\/h3>\n<p>To start the build process run the configure script which will perform a number of checks to make sure all of the dependencies on your system are present:<\/p>\n<p>Upon successful completion, the following message will be printed on your screen:<\/p>\n<p>*** Configuration summary for nagios 4.4.2 2018-08-16 ***:<\/p>\n<p>General Options:<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nNagios executable: nagios<br \/>\nNagios user\/group: nagios,nagios<br \/>\nCommand user\/group: nagios,nagios<br \/>\nEvent Broker: yes<br \/>\nInstall $: \/usr\/local\/nagios<br \/>\nInstall $: \/usr\/local\/nagios\/include\/nagios<br \/>\nLock file: \/run\/nagios.lock<br \/>\nCheck result directory: \/usr\/local\/nagios\/var\/spool\/checkresults<br \/>\nInit directory: \/lib\/systemd\/system<br \/>\nApache conf.d directory: \/etc\/httpd\/conf.d<br \/>\nMail program: \/sbin\/sendmail<br \/>\nHost OS: linux-gnu<br \/>\nIOBroker Method: epoll<\/p>\n<p>Web Interface Options:<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nHTML URL: http:\/\/localhost\/nagios\/<br \/>\nCGI URL: http:\/\/localhost\/nagios\/cgi-bin\/<br \/>\nTraceroute (used by WAP): \/bin\/traceroute<\/p>\n<p>Review the options above for accuracy. If they look okay,<br \/>\ntype &#8216;make all&#8217; to compile the main program and CGIs.<\/p>\n<p>Start the compilation process using the make command:<\/p>\n<p>The compilation may take some time, depending on your system. Once the build process is completed, the following message will be printed on your screen:<\/p>\n<p>&#8230;.<br \/>\n*** Compile finished ***<br \/>\n&#8230;<br \/>\nFor more information on obtaining support for Nagios, visit:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"XgjbITWLzL\"><p><a href=\"https:\/\/support.nagios.com\/\">Nagios Support Home<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Nagios Support Home&#8221; &#8212; Nagios Support\" src=\"https:\/\/support.nagios.com\/embed\/#?secret=AbPY8qJfMP#?secret=XgjbITWLzL\" data-secret=\"XgjbITWLzL\" width=\"525\" height=\"296\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>*************************************************************<\/p>\n<p>Enjoy.<\/p>\n<h3>3. Creating Nagios User And Group<\/h3>\n<p>Create a new system nagios user and group by issuing:<\/p>\n<p>sudo make install-groups-users<\/p>\n<p>The output will look something like below:<\/p>\n<p>groupadd -r nagios<br \/>\nuseradd -g nagios nagios<\/p>\n<p>Add the Apache apache user to the nagios group:<\/p>\n<p>sudo usermod -a -G nagios apache<\/p>\n<h3>4. Installing Nagios Binaries<\/h3>\n<p>Run the following command to install Nagios binary files, CGIs, and HTML files:<\/p>\n<p>You should see the following output:<\/p>\n<p>&#8230;<br \/>\n*** Main program, CGIs and HTML files installed ***<br \/>\n&#8230;<\/p>\n<h3>5. Creating External Command Directory<\/h3>\n<p>Nagios can process commands from external applications. Create the external command directory and set the proper permissions by typing:<\/p>\n<p>sudo make install-commandmode*** External command directory configured ***<\/p>\n<h3>6. Install Nagios Configuration Files<\/h3>\n<p>Install the sample Nagios configuration files with:<\/p>\n<p>&#8230;<br \/>\n*** Config files installed ***<\/p>\n<p>Remember, these are *SAMPLE* config files. You&#8217;ll need to read<br \/>\nthe documentation for more information on how to actually define<br \/>\nservices, hosts, etc. to fit your particular needs.<\/p>\n<h3>7. Install Apache Configuration Files<\/h3>\n<p>Run the command below to install the Apache web server configuration files:<\/p>\n<p>sudo make install-webconf&#8230;<br \/>\n*** Nagios\/Apache conf file installed ***<\/p>\n<h3>8. Creating Systemd Unit File<\/h3>\n<p>The following command installs a systemd unit file and also configure the nagios service to start on boot.<\/p>\n<p>sudo make install-daemoninit&#8230;<br \/>\n*** Init script installed ***<\/p>\n<h3>9. Creating User Account<\/h3>\n<p>To be able to access the Nagios web interface wel\u2019ll create an admin user called nagiosadmin<\/p>\n<p>Run the following htpasswd command to create a user called nagiosadmin<\/p>\n<p>sudo htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/p>\n<p>You will be prompted to enter and confirm the user\u2019s password.<\/p>\n<p>New password:<br \/>\nRe-type new password:<br \/>\nAdding password for user nagiosadmin<\/p>\n<p>Restart the Apache service for changes to take effect:<\/p>\n<p>sudo systemctl restart httpd<\/p>\n<p>Configure the Apache service to start on boot.<\/p>\n<p>sudo systemctl enable httpd<\/p>\n<h3>10. Configuring Firewall<\/h3>\n<p>The firewall will secure your server against unwanted traffic.<\/p>\n<p>If you don\u2019t have a firewall configured on your server, you can check our guide about <a href=\"\/post\/how-to-setup-a-firewall-with-firewalld-on-centos-7\/\">how to setup a firewall with firewalld on centos<\/a><\/p>\n<p>Open the Apache ports by running the following commands:<\/p>\n<p>sudo firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=http<br \/>\nsudo firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=https<br \/>\nsudo firewall-cmd &#8211;reload<\/p>\n<h2>Installing Nagios Plugins<\/h2>\n<p>Switch back to the \/usr\/src directory:<\/p>\n<p>Download the latest version of the Nagios Plugins from the <a href=\"https:\/\/github.com\/nagios-plugins\/nagios-plugins\/\">project Github repository<\/a>:<\/p>\n<p>sudo wget -O nagios-plugins.tar.gz https:\/\/github.com\/nagios-plugins\/nagios-plugins\/archive\/release-2.2.1.tar.gz<\/p>\n<p>When the download is complete extract the tar file:<\/p>\n<p>sudo tar zxf nagios-plugins.tar.gz<\/p>\n<p>Change to the plugins source directory:<\/p>\n<p>cd nagios-plugins-release-2.2.1<\/p>\n<p>Run the following commands one by one to compile and install the Nagios plugins:<\/p>\n<p>sudo .\/tools\/setup<br \/>\nsudo .\/configure<br \/>\nsudo make<br \/>\nsudo make install<\/p>\n<h2>Starting Nagios<\/h2>\n<p>Now that both Nagios and its plugins are installed, start the Nagios service with:<\/p>\n<p>sudo systemctl start nagios<\/p>\n<p>To verify that Nagios is running, check the service status with the following command:<\/p>\n<p>sudo systemctl status nagios<\/p>\n<p>The output should look something like bellow indicating that Nagios service is active and running.<\/p>\n<p>nagios.service &#8211; Nagios Core 4.4.2<br \/>\nLoaded: loaded (\/usr\/lib\/systemd\/system\/nagios.service; enabled; vendor preset: disabled)<br \/>\nActive: active (running) since Sat 2018-12-08 14:33:35 UTC; 3s ago<br \/>\nDocs: https:\/\/www.nagios.org\/documentation<br \/>\nProcess: 22217 ExecStart=\/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)<br \/>\nProcess: 22216 ExecStartPre=\/usr\/local\/nagios\/bin\/nagios -v \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)<br \/>\nMain PID: 22219 (nagios)<br \/>\nCGroup: \/system.slice\/nagios.service<\/p>\n<h2>Accessing the Nagios Web Interface<\/h2>\n<p>To access the Nagios web interface open your favorite browser and type your server\u2019s domain name or public IP address followed by \/nagios:<\/p>\n<p>http(s):\/\/your_domain_or_ip_address\/nagios<\/p>\n<p>Enter the nagiosadmin user login credentials and you will be redirected to the default Nagios home page as shown on the image below:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/lxer.com\/post\/how-to-install-and-configure-nagios-on-centos-7\/install-nagios-centos.jpg\" alt=\"\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>You have successfully installed the latest Nagios version from source on your CentOS system.<\/p>\n<p>You should now check the <a href=\"https:\/\/www.nagios.org\/documentation\/\">Nagios Documentation<\/a> and learn more about how to configure and use Nagios.<\/p>\n<p>If you hit a problem or have a feedback, leave a comment below.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=263670\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nagios is one of the most popular open source monitoring systems. Nagios keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running. In case of failure or suboptimal performance Nagios will send notification alerts via various methods. This tutorial describes how to install and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/11\/how-to-install-and-configure-nagios-on-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Install and Configure Nagios on CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5628","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=5628"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5628\/revisions"}],"predecessor-version":[{"id":6254,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5628\/revisions\/6254"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=5628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=5628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=5628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}