Home Operation and Maintenance Linux Operation and Maintenance Log management and monitoring skills for building a web server on CentOS

Log management and monitoring skills for building a web server on CentOS

Aug 05, 2023 am 08:33 AM
build Log management Monitoring skills

Log management and monitoring skills for building web servers on CentOS

Web servers are an important part of modern Internet applications, and server log management and monitoring are the key to ensuring stable server operation and troubleshooting. This article will introduce how to build a web server on the CentOS operating system, and provide some log management and monitoring techniques.

1. Build a Web server

  1. Install Apache

Apache is a popular open source Web server software. Installing Apache on CentOS is very simple, just enter the following command in the terminal:

sudo yum install httpd
Copy after login
  1. Configuring Apache

After installing Apache, you need to do some basic things on it configuration. The configuration file is located at /etc/httpd/conf/httpd.conf. You can open the file using an editor such as vi or nano.

For example, you can change the root directory of the default website:

DocumentRoot "/var/www/html"
Copy after login
  1. Start Apache

After completing the configuration, you can start Apache. Enter the following command:

sudo systemctl start httpd
Copy after login

2. Log management

  1. Log file location

Apache generates various types of files in the /var/log/httpd/ directory Log files. The following are some common log files:

  • access_log: records information about all HTTP requests;
  • error_log: records information about server errors;
  • ssl_access_log: records Information on all HTTPS requests;
  • ssl_error_log: records error information on HTTPS requests.
  1. Log file cutting

Since the log files generated by Apache can easily grow to very large sizes, you may need to periodically cut the log files for easier management. Linux provides a tool called logrotate that can easily cut and compress log files.

First, install logrotate:

sudo yum install logrotate
Copy after login

Then, create a log cutting configuration file named httpd:

sudo nano /etc/logrotate.d/httpd
Copy after login

In this file, you can specify the log file cutting rule. Here is an example configuration:

/var/log/httpd/access_log {
    rotate 7
    daily
    missingok
    compress
    delaycompress
    notifempty
    create 640 root root
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}
Copy after login

In this configuration, the log files will be rotated daily and backups of the last 7 days will be retained. The cut files will be compressed and archived.

  1. Analysis log

The log file contains rich information and is very helpful for server analysis and monitoring. You can use some tools to analyze logs, such as Awstats, Webalizer, and ELK Stack.

Awstats and Webalizer are two tools for generating detailed website statistics reports. You can install them using the yum command:

sudo yum install awstats webalizer
Copy after login

After the installation is complete, you need to configure them to analyze Apache's log files. Please refer to the respective official documentation for specific configuration methods.

ELK Stack is a powerful log management and analysis platform, which consists of three open source tools: Elasticsearch, Logstash and Kibana. You can use ELK Stack to centrally store, analyze, and visualize Apache log data.

3. Monitoring skills

  1. Use monitoring tools

In order to discover and solve server faults and problems in a timely manner, you can use some monitoring tools, such as Nagios, Zabbix and Prometheus, etc.

Nagios is a widely used infrastructure monitoring tool that can monitor various services and applications and provide alerting and reporting functions. You can install Nagios on CentOS and configure it to monitor the running status of Apache.

Zabbix is ​​a powerful network monitoring tool that supports real-time monitoring of server performance and resources. You can use Zabbix to monitor key metrics of Apache, such as CPU usage, memory usage, and network traffic.

Prometheus is a recently popular monitoring system that provides rich built-in indicators and flexible query language. You can use Prometheus to monitor Apache performance metrics and visualize them using tools such as Grafana.

  1. Custom monitoring script

In addition to using existing monitoring tools, you can also write your own monitoring scripts to monitor Apache.

For example, you can write a simple Bash script to regularly check the running status of Apache and send alert emails to the administrator:

#!/bin/bash

# 检查Apache是否运行
if ! pgrep -x "httpd" > /dev/null
then
    # 发送警报邮件
    echo "Apache is not running" | mail -s "Apache Alert" admin@example.com
fi
Copy after login

Save the above script as check_apache.sh and use The cron scheduled task executes it:

*/5 * * * * /path/to/check_apache.sh
Copy after login

This script will run every 5 minutes and check whether Apache is running. If Apache is not running, the script will send an alert email to the administrator.

Summary:

This article introduces the steps to build a web server on the CentOS operating system, and provides some log management and monitoring techniques. By properly configuring log files and using monitoring tools, you can better manage and maintain your web server, ensure its stable operation and find and solve problems in a timely manner. By customizing monitoring scripts, you can flexibly monitor the running status of Apache. Hope these tips are helpful to you.

The above is the detailed content of Log management and monitoring skills for building a web server on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to quickly build a statistical chart system under the Vue framework How to quickly build a statistical chart system under the Vue framework Aug 21, 2023 pm 05:48 PM

How to quickly build a statistical chart system under the Vue framework. In modern web applications, statistical charts are an essential component. As a popular front-end framework, Vue.js provides many convenient tools and components that can help us quickly build a statistical chart system. This article will introduce how to use the Vue framework and some plug-ins to build a simple statistical chart system. First, we need to prepare a Vue.js development environment, including installing Vue scaffolding and some related plug-ins. Execute the following command in the command line

How to use the Hyperf framework for log management How to use the Hyperf framework for log management Oct 25, 2023 am 09:15 AM

How to use the Hyperf framework for log management Introduction: Hyerpf is a high-performance, highly flexible coroutine framework based on the PHP language, with rich components and functions. Log management is an essential part of any project. This article will introduce how to use the Hyperf framework for log management and provide specific code examples. 1. Install the Hyperf framework First, we need to install the Hyperf framework. It can be installed through Composer, open the command line tool and enter the following command

How to manage logs of C++ code? How to manage logs of C++ code? Nov 03, 2023 pm 02:38 PM

With the continuous development of software development, log management has become an indispensable part of the code development process. As a relatively complex programming language, C++ also requires log management during code development. This article will introduce the log management principles and specific implementation of C++ code, hoping to be helpful to readers. 1. Log management principles determine the log level. The log level represents the importance and urgency of the log information. In C++ development, log levels are divided into DEBUG, INFO, WARN, ERROR and F

Can buildings be built in the wild in Mistlock Kingdom? Can buildings be built in the wild in Mistlock Kingdom? Mar 07, 2024 pm 08:28 PM

Players can collect different materials to build buildings when playing in the Mistlock Kingdom. Many players want to know whether to build buildings in the wild. Buildings cannot be built in the wild in the Mistlock Kingdom. They must be within the scope of the altar. . Can buildings be built in the wild in Mistlock Kingdom? Answer: No. 1. Buildings cannot be built in the wild areas of the Mist Lock Kingdom. 2. The building must be built within the scope of the altar. 3. Players can place the Spirit Fire Altar by themselves, but once they leave the range, they will not be able to construct buildings. 4. We can also directly dig a hole in the mountain as our home, so we don’t need to consume building materials. 5. There is a comfort mechanism in the buildings built by players themselves, that is to say, the better the interior, the higher the comfort. 6. High comfort will bring attribute bonuses to players, such as

Network security reinforcement techniques for building web servers under CentOS 7 Network security reinforcement techniques for building web servers under CentOS 7 Aug 05, 2023 pm 01:12 PM

Network security reinforcement techniques for building web servers under CentOS7 The web server is an important part of the modern Internet, so it is very important to protect the security of the web server. By hardening network security, you can reduce risks and avoid potential attacks. This article will introduce network security reinforcement techniques commonly used when building web servers on CentOS7, and provide corresponding code examples. Update your system and software First, make sure your system and software are up to date. You can use the following command to update

How to use Docker for application monitoring and log management How to use Docker for application monitoring and log management Nov 07, 2023 pm 04:58 PM

Docker has become an essential technology in modern applications, but using Docker for application monitoring and log management is a challenge. With the continuous enhancement of Docker network functions, such as ServiceDiscovery and LoadBalancing, we increasingly need a complete, stable, and efficient application monitoring system. In this article, we will briefly introduce the use of Docker for application monitoring and log management and give specific code examples. Use P

How to build an account matrix? What are the functions of matrix construction? How to build an account matrix? What are the functions of matrix construction? Mar 23, 2024 pm 06:46 PM

In today's information-rich era, social media platforms have become the main way for people to obtain and share information. For individuals and enterprises, establishing an effective account network to achieve maximum dissemination of information and enhance influence has become an urgent challenge that needs to be solved. 1. How to build an account matrix? 1. Clarify the target audience. Before building an account matrix, the key is to clearly define the target audience and gain an in-depth understanding of their needs, interests, and consumption habits, so that a more targeted content strategy can be developed. 2. Choose the appropriate platform. According to the characteristics of the target group, choose the appropriate social media platform for layout. Currently, the mainstream social media platforms include Weibo, WeChat, Douyin, Kuaishou, etc. Each platform has its own unique user groups and communication characteristics, and the selection needs to be based on the actual situation.

Best practices and precautions for building a web server under CentOS 7 Best practices and precautions for building a web server under CentOS 7 Aug 25, 2023 pm 11:33 PM

Best practices and precautions for building web servers under CentOS7 Introduction: In today's Internet era, web servers are one of the core components for building and hosting websites. CentOS7 is a powerful Linux distribution widely used in server environments. This article will explore the best practices and considerations for building a web server on CentOS7, and provide some code examples to help you better understand. 1. Install Apache HTTP server Apache is the most widely used w

See all articles