{"id":6724,"date":"2019-10-01T09:45:45","date_gmt":"2019-10-01T14:45:45","guid":{"rendered":"https:\/\/www.poweradmin.com\/blog\/?p=6724"},"modified":"2019-10-07T14:28:57","modified_gmt":"2019-10-07T19:28:57","slug":"how-to-manage-linux-logs","status":"publish","type":"post","link":"https:\/\/www.poweradmin.com\/blog\/how-to-manage-linux-logs\/","title":{"rendered":"How to Manage Linux Logs"},"content":{"rendered":"<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><strong><span style=\"font-family: 'Arial',sans-serif;\">By Des Nnochiri<\/span><\/strong><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Log files in Linux often contain information that can assist in tracking down the cause of issues hampering system or network performance. If you have multiple servers or levels of IT architecture, the number of logs you generate can soon become overwhelming. In this article, we\u2019ll be looking at some ways to ease the burden of managing your Linux logs.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2><span style=\"font-family: 'Arial',sans-serif;\">Centralizing Linux Logs<\/span><\/h2>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">One of the best practices for managing Linux logs is to aggregate or centralize them in a single location. This is particularly useful if your IT infrastructure involves multiple servers, many layers of storage architecture, or sites in geographically-dispersed locations. The same wisdom applies for any organization that uses a mixture of on-premises servers and cloud services.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Centralizing your logs in a single location makes it much easier to search through them for any useful information they might contain. Instead of trying to guess which server has the particular Linux file you want, you can simply refer to your central repository of logging data to search for relevant events. This makes it easier and quicker to troubleshoot problems or resolve production issues. In many cases, engineers may be able to resolve issues without directly accessing systems.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Most Linux systems use an on-board syslog daemon to centralize logs. Syslog is a service which collects log files from services and applications running on a host. It can write these logs to file or forward them on to another server via the syslog protocol. There are a number of variants including Rsyslog, a lightweight daemon installed on most common Linux distributions, and syslog-n, the second most popular syslog daemon for Linux.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Large management solutions for Linux logging use centralization as a key feature, since it enables them to analyze, parse, and index logs before storing them at a central hub. Centralization allows for logs to be backed up in a separate location, protecting them against accidental loss or if your on-site servers go down. <\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; tab-stops: 198.45pt; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Besides reducing the overall amount of disk space required for keeping log files, having them stored at a single location also saves on computing resources, which might otherwise have to be wasted on complex searches using SSH or inefficient grep commands.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2><span style=\"font-family: 'Arial',sans-serif;\">Managing Log Rotation<\/span><\/h2>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Log files on Linux systems automatically roll over. The system maintains only a fixed number of the rolled-over logs. Rotation may occur quite frequently, and when it occurs, the current log is given a slightly different file name, and a new log file is established. <\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">The example illustrated below shows rotation for the syslog file, which typically stores your normal system messages:<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\"> <a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/syslog-file-rotation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6727\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/syslog-file-rotation-300x92.png\" alt=\"\" width=\"450\" height=\"138\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/syslog-file-rotation-300x92.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/syslog-file-rotation.png 622w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin-bottom: .0001pt; text-align: center; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">(Image Source <\/span><a href=\"https:\/\/www.networkworld.com\/article\/3428361\/how-to-manage-logs-in-linux.html%20\" rel=\"nofollow\" target=\"_blank\"><span style=\"font-family: 'Arial',sans-serif; color: blue;\">NetworkWorld<\/span><img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><span style=\"font-family: 'Arial',sans-serif;\">)<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Older syslog files roll over at midnight each night and are kept for a week, after which the oldest is deleted. So in the example above, the syslog.7.gz file will be deleted from the system, and syslog.6.gz will be renamed syslog.7.gz. The rest of the log files will follow the same pattern until syslog becomes syslog.1 and a new syslog file is created. In general, you\u2019ll never see more than eight of these log files at a time, giving you just over a week to review any data they collect.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">The number of files a Linux system maintains for any particular log file depends on the log file itself. For some, the number of files included may be as many as 13. Older files\u2014both for syslog and dpkg\u2014are typically compressed or g-zipped to save space. You can use gunzip to expand any older files that you\u2019re particularly interested in.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Note that log files may be rotated based on age and size, so you should keep this in mind when you examine them. You can look at files like \/etc\/rsyslog.conf and \/etc\/logrotate.conf for details on how to configure rotation on your system.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2><span style=\"font-family: 'Arial',sans-serif;\">Using Log Files<\/span><\/h2>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Knowing how to pull information from log files can be very beneficial when you want to get a sense of how well your Linux system is working or if you need to track down a particular problem. To do this effectively, you\u2019ll need to get a general idea of what kind of information is stored in each file and what that data can tell you about your system\u2019s performance and any problems it might have encountered.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">The screenshot below gives some typical examples:<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\"> <a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/dpkg-log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6729\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/dpkg-log-300x44.png\" alt=\"\" width=\"450\" height=\"66\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/dpkg-log-300x44.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/dpkg-log.png 619w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin-bottom: .0001pt; text-align: center; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">(Image Source <\/span><a href=\"https:\/\/www.networkworld.com\/article\/3428361\/how-to-manage-logs-in-linux.html%20\" rel=\"nofollow\" target=\"_blank\"><span style=\"font-family: 'Arial',sans-serif; color: blue;\">NetworkWorld<\/span><img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><span style=\"font-family: 'Arial',sans-serif;\">)<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">There are also Linux commands that you can run to extract information from your log files. For example, to view a list of system reboots, you can use a command like this:<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; text-align: center; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/last-reboot-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6731\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/last-reboot-command-300x44.png\" alt=\"\" width=\"450\" height=\"66\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/last-reboot-command-300x44.png 300w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2019\/10\/last-reboot-command.png 619w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\"><\/a><\/span><\/p>\n<p>\u00a0<\/p>\n<p style=\"margin-bottom: .0001pt; text-align: center; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Image Source <\/span><a href=\"https:\/\/www.networkworld.com\/article\/3428361\/how-to-manage-logs-in-linux.html%20\" rel=\"nofollow\" target=\"_blank\"><span style=\"font-family: 'Arial',sans-serif; color: blue;\">NetworkWorld<\/span><img class=\"extlink-icon\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/plugins\/external-links-nofollow-open-in-new-tab-favicon\/images\/extlink.png\"><\/a><span style=\"font-family: 'Arial',sans-serif;\">)<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<h2><span style=\"font-family: 'Arial',sans-serif;\">Using Advanced Log Managers<\/span><\/h2>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">Though you can write scripts to make it easier to find relevant information in your log files, there are sophisticated tools available for log file analysis. Some advanced log managers can correlate information from multiple sources to give a fuller picture of what\u2019s happening on your network. Others can provide real-time monitoring. Among the top commercial tools are SolarWinds Log &amp; Event Manager and PRTG Network Monitor.<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">\u00a0<\/span><\/p>\n<p style=\"margin-bottom: .0001pt; line-height: 150%; text-autospace: none;\"><span style=\"font-family: 'Arial',sans-serif;\">There are also free log management tools if you need to handle your Linux logging on a budget. For instance, Logwatch is a program that scans system logs for lines that might indicate certain kinds of activity, and the Logcheck utility is a system log analyzer and reporter.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Des Nnochiri \u00a0 Log files in Linux often contain information that can assist in tracking down the cause of issues hampering system or network performance. If you have multiple servers or levels of IT architecture, the number of logs you generate can soon become overwhelming. In this article, we\u2019ll be looking at some ways [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":6735,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,447,9],"tags":[893,883,884,888,269,778,653,398,526,821,885,892,891,882,420,895,894,59,606,889,873,886,887,890],"class_list":["post-6724","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general-it","category-how-to","category-linux","category-technical","tag-advanced-log-manager","tag-centralization","tag-centralize-linux-logs","tag-centralize-logs","tag-data-storage","tag-disk-storage","tag-dpkg","tag-linux","tag-linux-command","tag-linux-distribution","tag-linux-file","tag-linux-file-storage","tag-linux-logging","tag-linux-logs","tag-linux-network","tag-logcheck","tag-logwatch","tag-monitoring","tag-network-monitoring","tag-rsyslog","tag-solar-winds","tag-syslog","tag-syslog-daemon","tag-syslog-n"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/comments?post=6724"}],"version-history":[{"count":5,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6724\/revisions"}],"predecessor-version":[{"id":6754,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/6724\/revisions\/6754"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media\/6735"}],"wp:attachment":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media?parent=6724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/categories?post=6724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/tags?post=6724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}