In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
Nginx logs are written to a file by default, and in order to distinguish between logs under each domain, we usually store them separately. Even so, the file will become larger and larger, making it very inconvenient to view and analyze. Usually we do statistics on a daily basis, so let's talk about separating Nginx logs by date.
Configuration
Write a script
#! / bin/bash# initialize LOGS_PATH=/usr/local/nginx/logsYESTERDAY=$ (date-d "yesterday" +% Y%m%d) # cut daily log mv ${LOGS_PATH} / bbs.52itstyle.com.access.log ${LOGS_PATH} / bbs.52itstyle.com.access_$ {YESTERDAY} .logmv ${LOGS_PATH} / blog.52itstyle.com.access.log ${LOGS_PATH} / blog.52itstyle.com.access_$ {YESTERDAY} .log # send USR1 signal to nginx main process Reopen the log file, otherwise you will continue to write data to the file after mv. The reason is that in linux systems, the kernel looks for files based on file descriptors. Failure to do so causes log cutting to fail. Kill-USR1 `ps axu | grep "nginx: master process" | grep-v grep | awk'{print $2}'`# delete the log cd ${LOGS_PATH} find 7 days ago. -mtime + 7-name "* 20 [1-9] [3-9] *" | xargs rm-fexit 0
Write task
# execute the command crontab-e# to write to the file and save 0 0 * / home/scripts/cut_del_nginx_logs.sh
Crontab
Crond is a daemon used under linux to periodically execute certain tasks or wait for certain events to be handled. Similar to the scheduled tasks under windows, when the installation of the operating system is completed, this service tool is installed by default, and the crond process is automatically started. The crond process periodically checks whether there is a task to be executed every minute, and automatically executes the task if there is a task to be executed. Task scheduling under Linux is divided into two categories: system task scheduling and user task scheduling.
System task scheduling: the work that the system periodically performs, such as writing cached data to the hard disk, log cleaning, etc. There is a crontab file in the / etc directory, which is the configuration file for system task scheduling.
Crontab service installation
Install crontab:
Yum install crontabs
Service operation description:
Service crond start / / start service service crond stop / / close service service crond restart / / restart service service crond reload / / reload configuration
View the status of the crontab service:
Service crond status
Start the crontab service manually:
Service crond start
Check to see if the crontab service is set to boot and execute the command:
Ntsysv
Join the boot and start automatically:
Chkconfig-level 35 crond on
Crontab format description
In the crontab file created by the user, each line represents a task, and each field on each line represents a setting. Its format is divided into six fields. The first five paragraphs are the time setting section, and the sixth paragraph is the command segment to be executed. The format is as follows:
The following special characters can also be used in each of the above fields:
Asterisk (*): represents all possible values. For example, if the day field is an asterisk, it means that the command operation is performed every day after the constraints of other fields are met. Comma (,): you can specify a list range with values separated by commas, for example, the bar (-): you can use the middle bar between integers to represent a range of integers. For example, "2-6" means "2pens 3pens 4pens 6" forward slash (/): you can specify the interval frequency of time with a forward slash, for example, "0-23jump 2" means that it is executed every two hours. At the same time, a forward slash can be used with an asterisk, such as * / 10, which, if used in the minute field, means that it is executed every ten minutes.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.