Monitoring and logging are critical aspects of managing a CentOS 7 server. In this blog post, we will discuss setting up monitoring and logging solutions on CentOS 7, focusing on Nagios for monitoring and the ELK stack (Elasticsearch, Logstash, and Kibana) for logging.

Monitoring with Nagios.

Step 1: Install Nagios.
Install Nagios from the EPEL repository:-
# [sudo yum install epel-release]
# [sudo yum install nagios]

Step 2: Configure Nagios.
Edit the Nagios configuration file /etc/nagios/nagios.cfg to define the email address for the Nagios admin:-
# [sudo VI /etc/nagios/nagios.cfg]
  
...
# Definitions for contact groups
define contact {
    
contact_name    nagiosadmin
       ...

    
email           your_email@example.com
}
...

 Step 3: Start Nagios.
Start the Nagios service and enable it to start automatically on boot:-
# [sudo systemctl start nagios]
# [sudo systemctl enable nagios]

Step 4: Access the Nagios Web Interface.
Access the Nagios web interface in a browser by navigating to 'http://your_server_ip/nagios'. Log in using the default credentials (username: 'nagiosadmin, password: nagiosadmin').

Step 5: Add Hosts and Services.
Configure Nagios to monitor hosts and services by editing the configuration files in '/etc/nagios/conf.d/'.

Logging with ELK Stack

Step 1: Install Java.
ELK Stack requires Java. Install Java on CentOS 7:-
# [sudo yum install java-1.8.0-openjdk]

Step 2: Install Elasticsearch.
Install Elasticsearch and start the service:-
# [sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch]
# [sudo yum install elasticsearch]
# [sudo systemctl start elasticsearch]
# [sudo systemctl enable elasticsearch]

Step 3: Install Logstash.
Install Logstash and start the service:-
# [sudo yum install logstash]
# [sudo systemctl start logstash]
# [sudo systemctl enable logstash]

Step 4: Install Kibana.
Install Kibana and start the service:-
# [sudo yum install kibana]
# [sudo systemctl start kibana]
# [sudo systemctl enable kibana]

Step 5: Access Kibana.
Access the Kibana web interface in a browser by navigating to http://your_server_ip:5601. Configure Kibana to connect to Elasticsearch and Install Apache in Centos 7.

Step 6: Configure Logstash.
Create Logstash configuration files in '/etc/logstash/conf.d/' to define input, filter, and output settings for log files.

Step 7: Send Logs to Logstash.
Configure your applications and servers to send logs to Logstash using Filebeat, a lightweight log shipper.

Conclusion: - Monitoring and logging are essential for maintaining the health and security of your CentOS 7 server. By setting up Nagios for monitoring and the ELK stack for logging, you can gain valuable insights into your server's performance and troubleshoot issues effectively.