Setting Up a Master and Remote Server with Nagios on CentOS 7 Using Vagrant – Part 1
This guide will walk you through setting up a Nagios monitoring system on CentOS 7 using Vagrant and VirtualBox. We’ll configure a master server to monitor remote servers in a private network environment.
Vagrant Configuration
First, let’s define our virtual machines (VMs) using a Vagrantfile. This file contains the configuration for creating the VMs using Vagrant and VirtualBox.
Vagrant.configure("2") do |config|
config.vm.define "master" do |master|
master.vm.hostname = "master"
master.vm.box = "centos/7"
master.vm.network "private_network", ip: "192.100.10.10"
master.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end
config.vm.define "remote" do |remote|
remote.vm.hostname = "remote"
remote.vm.box = "centos/7"
remote.vm.network "private_network", ip: "192.100.10.20"
remote.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end
end
Explanation:
Example: After writing the above configuration, run vagrant up in your terminal to create and start the VMs. This command brings up both VMs based on the configuration defined in the Vagrantfile.
Configuring the Master Server
Once your VMs are up, SSH into the master server and begin setting it up.
vagrant ssh master
Update and Upgrade the System
Start by updating the system to ensure you have the latest packages:
sudo yum update
sudo yum upgrade
Explanation:
Example: Always perform a system update before installing new software to ensure compatibility and security.
Install Required Packages
Next, install the necessary software packages for Nagios:
sudo yum install httpd php php-cli gcc unzip wget glibc glibc-common gd gd-devel net-snmp -y
sudo yum install glibc-common make openssl-devel xinetd vim -y
Explanation:
Example: If you encounter dependency issues, use sudo yum clean all to clear the cache and try reinstalling.
Start the Apache Server
sudo service httpd start
Explanation:
Create Nagios User and Group
sudo useradd nagios
sudo passwd nagios
password
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache
Explanation:
Example: Use the same commands to create additional users if needed, substituting “nagios” with the desired username.
Download and Install Nagios
cd /opt/
sudo wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
sudo tar xzf nagios-4.4.5.tar.gz
cd nagios-4.4.5
sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-daemoninit
sudo make install-config
sudo make install-commandmode
sudo make install-exfoliation
sudo make install-webconf
Explanation:
Example: After installation, you can verify it by running sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg.
Setting Up Nagios Web Interface
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
password
sudo service httpd restart
Explanation:
Example: Visit https://192.100.10.10/nagios/ in your browser to access the Nagios web interface.
Additional Configuration (Optional)
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
sudo systemctl restart httpd
sudo systemctl restart nagios
sudo systemctl enable httpd
sudo systemctl enable nagios
Explanation:
Example: Use sudo systemctl status nagios to check if Nagios is running correctly.
Installing Nagios Plugins
cd /opt
sudo wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
sudo tar xzf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install
Explanation:
Example: To verify, run sudo /usr/local/nagios/libexec/check_nrpe -H localhost.
Final Steps
Ensure everything is working by starting the Nagios service:
sudo service nagios start
Access the Nagios web interface using your browser and log in with the credentials you created.