Home Operation and Maintenance Linux Operation and Maintenance How to configure Debian Apache log rotation

How to configure Debian Apache log rotation

Apr 13, 2025 am 09:15 AM
apache tool ai red

How to configure Debian Apache log rotation

This article introduces how to configure Apache log rotation in the Debian system, mainly using the logrotate tool.

Step 1: Verify that logrotate is installed

Check with the following command:

 logrotate --version
Copy after login

If not installed, execute:

 sudo apt-get update
sudo apt-get install logrotate
Copy after login

Step 2: Locate the Apache log rotation configuration file

The configuration file is usually located in the /etc/logrotate.d/ directory, and the file name may be apache2 or httpd . Use the following command to find:

 ls /etc/logrotate.d/apache2 # or ls /etc/logrotate.d/httpd
Copy after login

Step 3: Edit the Apache log rotation configuration file

Open the configuration file using a text editor such as nano or vim :

 sudo nano /etc/logrotate.d/apache2 # or sudo nano /etc/logrotate.d/httpd
Copy after login

Step 4: Configure logrotate parameters

In the configuration file, you can customize the log rotation frequency, the number of retained log files, the compression method, etc. Here is a sample configuration:

 <code>/var/log/apache2/*.log { daily missingok rotate 7 compress delaycompress notifempty create 640 root adm sharedscripts postrotate if [ -x /usr/sbin/invoke-rc.d ]; then /usr/sbin/invoke-rc.d apache2 reload >/dev/null 2>&1 fi endscript }</code>
Copy after login

Parameter description:

  • daily : daily rotation.
  • missingok : No error is reported when the log file is missing.
  • rotate 7 : Keep 7 log files.
  • compress : Compress old logs.
  • delaycompress : Delay compression until the next rotation.
  • notifempty : The empty log file does not rotate.
  • create 640 root adm : Create a new log file with permissions of 640, belongs to the main root, belongs to the group adm.
  • sharedscripts : When multiple log files are used, the postrotate script is executed only once.
  • postrotate ... endscript : The script executed after log rotation, reload the Apache configuration here. (Use more general if [ -x ... ] to check if the script exists)

Step 5: Test the configuration

Test the configuration with the following command:

 sudo logrotate -d /etc/logrotate.d/apache2 # -d parameter is test mode and will not be actually executed
Copy after login

The -d parameter is used for testing mode, and does not actually perform rotation, and only checks whether the configuration syntax is correct. If there is no error, then execute sudo logrotate /etc/logrotate.d/apache2 for actual rotation.

Step 6: Confirm the timing task

logrotate is usually automatically executed by the system cron task. You can check the /etc/cron.daily/logrotate file to make sure it exists and is configured correctly.

After completing the above steps, your Debian system Apache log rotation configuration is completed. If you have any questions, please check the configuration file syntax and permission settings.

The above is the detailed content of How to configure Debian Apache log rotation. 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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months 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)

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Choosing Between NGINX and Apache: The Right Fit for Your Needs Choosing Between NGINX and Apache: The Right Fit for Your Needs Apr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Apache's Legacy: What Made It Famous? Apache's Legacy: What Made It Famous? Apr 15, 2025 am 12:19 AM

Apachebecamefamousduetoitsopen-sourcenature,modulardesign,andstrongcommunitysupport.1)Itsopen-sourcemodelandpermissiveApacheLicenseencouragedwidespreadadoption.2)Themodulararchitectureallowedforextensivecustomizationandadaptability.3)Avibrantcommunit

What underlying technologies does Docker use? What underlying technologies does Docker use? Apr 15, 2025 am 07:09 AM

Docker uses container engines, mirror formats, storage drivers, network models, container orchestration tools, operating system virtualization, and container registry to support its containerization capabilities, providing lightweight, portable and automated application deployment and management.

How to define header files for vscode How to define header files for vscode Apr 15, 2025 pm 09:09 PM

How to define header files using Visual Studio Code? Create a header file and declare symbols in the header file using the .h or .hpp suffix name (such as classes, functions, variables) Compile the program using the #include directive to include the header file in the source file. The header file will be included and the declared symbols are available.

What platform Docker uses to manage public images What platform Docker uses to manage public images Apr 15, 2025 am 07:06 AM

The Docker image hosting platform is used to manage and store Docker images, making it easy for developers and users to access and use prebuilt software environments. Common platforms include: Docker Hub: officially maintained by Docker and has a huge mirror library. GitHub Container Registry: Integrates the GitHub ecosystem. Google Container Registry: Hosted by Google Cloud Platform. Amazon Elastic Container Registry: Hosted by AWS. Quay.io: By Red Hat

Docker uses macvlan Docker uses macvlan Apr 15, 2025 am 06:57 AM

macvlan in Docker is a Linux kernel module that allows containers to have their own MAC address, enabling network isolation, performance improvement and direct interaction with the physical network. Using macvlan requires: 1. Install the kernel module; 2. Create a macvlan network; 3. Assign IP address segments; 4. Specify the macvlan network when container creation; 5. Verify the connection.

Docker application log storage location Docker application log storage location Apr 15, 2025 am 06:45 AM

Docker logs are usually stored in the /var/log directory of the container. To access the log file directly, you need to use the docker inspect command to get the log file path, and then use the cat command to view it. You can also use the docker logs command to view the logs and add the -f flag to continuously receive the logs. When creating a container, you can use the --log-opt flag to specify a custom log path. In addition, logging can be recorded using the log driver, LogAgent, or stdout/stderr.

See all articles