In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB Log switching (Rotate Log Files) Guid
MongoDB does not automatically switch log rotation by default, which will cause the log to grow day by day. Under the busy business, the log growth is very large. With such a large log file, it is not convenient to view the log of one day. Therefore, you need to switch between the mongodb log files.
Log switching behavior
-- logRotate
Default value: rename
What's new in version 3.0.0: specify logRotate behavior.
Specify as rename or reopen.
Rename renames the log file.
Reopen closes and reopens the log file following the typical Linux/Unix log switching behavior. When using the Linux/Unix logrotate tool, use reopen to avoid log loss.
If you specify reopen, you must also use-logappend
Default log switching behavior
By default, MongoDB uses the-- logRotate rename behavior. Use rename,mongod or mongos to rename the current log file by adding a UTC (GMT) timestamp to the end of the file name, then open the new log file, close the previous old log file, and send all new log information to the new log file.
1. Start the mongod instance.
Mongod-v-logpath / var/log/mongodb/server1.log
You can also explicitly specify-- logRotate rename
two。 List the log files.
In another terminal, list the matching files:
Ls / var/log/mongodb/server1.log*
The result will contain a log file, server1.log.
3. Toggles log files.
Under mongo shell, run the logRotate command from the admin database to switch log files:
Use admin db.runCommand ({logRotate:1})
4. View the new log file.
List the new log file to view the newly created log:
Ls / var/log/mongodb/server1.log*
Two log files should be listed: server1.log, which is created by mongod or mongos when the log file is reopened, and the original log file renamed by server1.log.,.
Switching log files does not modify the old switch log files. When you switch logs, you will rename the server1.log file by attaching a timestamp, and a new empty server1.log file will receive all new log inputs.
Use-- logRotate reopen to switch logs
New features in version 3.0.0.
Use-- logRotate reopen to switch logs, and close and open log files to follow typical Linux/Unix log switching behavior.
1. Start the mongod instance and specify the-- logRotate parameter value as reopen.
Mongod-v-logpath / var/log/mongodb/server1.log-logRotate reopen-logappend
You must use the-- logappend option with the-- logRoate reopen parameter.
two。 List the log files.
At the other terminal, list the matching files:
Ls / var/log/mongodb/server1.log*
The result contains a log file, server1.log.
3. Toggles log files.
In mongo shell, execute the logRotate command from the admin database to perform the log file switch:
Use admin db.runCommand ({logRotate:1})
You should use an external process to rename log files and follow the typical Linux/Unix log switching behavior.
Switch logs via syslog
New features in version 2.2.
By switching logs through syslog, mongod sends log data to syslog instead of writing to a file.
1. Start the mongod instance using the-- syslog option
Mongod-syslog
Do not include-- logpath. Because-- syslog tells mongod to send log data to syslog, specifying-- logpath will cause an error.
To specify the device level used to log information to syslog, use the-- syslogFacility option or the systemLog.syslogFacility configuration setting.
two。 Use the system's default log switching mechanism to store and switch log output.
Use SIGUSR1 to force log switching
For Linux/Unix systems, you can use SIGUSR1 signals to switch logs for a single process, as follows:
Kill-SIGUSR1
Reference:
Rotate Log Files: http://docs.mongodb.org/manual/tutorial/rotate-log-files/
LogRotate: http://docs.mongodb.org/manual/reference/command/logRotate/
Rotate Agent Log Files: https://docs.mms.mongodb.com/tutorial/rotate-agent-log-files/
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: 273
*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.