Open Source Logging Tools for Linux - Printable Version +- Sick Gaming (https://www.sickgaming.net) +-- Forum: Computers (https://www.sickgaming.net/forum-86.html) +--- Forum: Linux, FreeBSD, and Unix types (https://www.sickgaming.net/forum-88.html) +--- Thread: Open Source Logging Tools for Linux (/thread-86747.html) |
Open Source Logging Tools for Linux - xSicKxBot - 10-05-2018 Open Source Logging Tools for Linux <div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/open-source-logging-tools-for-linux.jpg" width="776" height="369" title="" alt="" /></div><div><div><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/open-source-logging-tools-for-linux.jpg" class="ff-og-image-inserted" /></div> <p>If you’re a Linux systems administrator, one of the first tools you will turn to for troubleshooting are log files. These files hold crucial information that can go a long way to help you solve problems affecting your desktops and servers. For many sysadmins (especially those of an old-school sort), nothing beats the command line for checking log files. But for those who’d rather have a more efficient (and possibly modern) approach to troubleshooting, there are plenty of options. </p> <p>In this article, I’ll highlight a few such tools available for the Linux platform. I won’t be getting into logging tools that might be specific to a certain service (such as Kubernetes or Apache), and instead will focus on tools that work to mine the depths of all that magical information written into <em>/var/log</em>. </p> <p>Speaking of which…</p> <h3>What is /var/log?</h3> <p>If you’re new to Linux, you might not know what the<em> </em><em>/var/log</em><em> </em>directory contains. However, the name is very telling. Within this directory is housed all of the log files from the system and any major service (such as Apache, MySQL, MariaDB, etc.) installed on the operating system. Open a terminal window and issue the command cd /var/log. Follow that with the command ls and you’ll see all of the various systems that have log files you can view (Figure 1).</p> <p>Say, for instance, you want to view the syslog log file. Issue the command <em>less syslog</em> and you can scroll through all of the gory details of that particular log. But what if the standard terminal isn’t for you? What options do you have? Plenty. Let’s take a look at few such options.</p> <h3>Logs</h3> <p>If you use the GNOME desktop (or other, as Logs can be installed on more than just GNOME), you have at your fingertips a log viewer that mainly just adds the slightest bit of GUI goodness over the log files to create something as simple as it is effective. Once installed (from the standard repositories), open Logs from the desktop menu, and you’ll be treated to an interface (Figure 2) that allows you to select from various types of logs (Important, All, System, Security, and Hardware), as well as select a boot period (from the top center drop-down), and even search through all of the available logs.</p> <p>Logs is a great tool, especially if you’re not looking for too many bells and whistles getting in the way of you viewing crucial log entries, so you can troubleshoot your systems.</p> <h3>KSystemLog</h3> <p>KSystemLog is to KDE what Logs is to GNOME, but with a few more features to add into the mix. Although both make it incredibly simple to view your system log files, only KSystemLog includes colorized log lines, tabbed viewing, copy log lines to the desktop clipboard, built-in capability for sending log messages directly to the system, read detailed information for each log line, and more. KSystemLog views all the same logs found in GNOME Logs, only with a different layout.</p> <p>From the main window (Figure 3), you can view any of the different log (from System Log, Authentication Log, X.org Log, Journald Log), search the logs, filter by Date, Host, Process, Message, and select log priorities.</p> <p>If you click on the Window menu, you can open a new tab, where you can select a different log/filter combination to view. From that same menu, you can even duplicate the current tab. If you want to manually add a log to a file, do the following:</p> <ol> <li> <p>Open KSystemLog.</p> </li> <li> <p>Click File > Add Log Entry.</p> </li> <li> <p>Create your log entry (Figure 4).</p> </li> <li> <p>Click OK</p> </li> </ol> <p>KSystemLog makes viewing logs in KDE an incredibly easy task.</p> <h3>Logwatch</h3> <p>Logwatch isn’t a fancy GUI tool. Instead, logwatch allows you to set up a logging system that will email you important alerts. You can have those alerts emailed via an SMTP server or you can simply view them on the local machine. Logwatch can be found in the standard repositories for almost every distribution, so installation can be done with a single command, like so:</p> <pre> sudo apt-get install logwatch</pre> <p>Or:</p> <pre> sudo dnf install logwatch</pre> <p>During the installation, you will be required to select the delivery method for alerts (Figure 5). If you opt to go the local mail delivery only, you’ll need to install the <em>mailutils </em>app (so you can view mail locally, via the <em>mail </em>command).</p> <p>All Logwatch configurations are handled in a single file. To edit that file, issue the command sudo nano /usr/share/logwatch/default.conf/logwatch.conf. You’ll want to edit the MailTo = option. If you’re viewing this locally, set that to the Linux username you want the logs sent to (such as MailTo = jack). If you are sending these logs to an external email address, you’ll also need to change the MailFrom = option to a legitimate email address. From within that same configuration file, you can also set the detail level and the range of logs to send. Save and close that file. <br class="kix-line-break" />Once configured, you can send your first mail with a command like:</p> <pre> logwatch --detail Med --mailto ADDRESS --service all --range today Where ADDRESS is either the local user or an email address. </pre> <p>For more information on using Logwatch, issue the command <em>man logwatch</em>. Read through the manual page to see the different options that can be used with the tool.</p> <h3>Rsyslog</h3> <p>Rsyslog is a convenient way to send remote client logs to a centralized server. Say you have one Linux server you want to use to collect the logs from other Linux servers in your data center. With Rsyslog, this is easily done. Rsyslog has to be installed on all clients and the centralized server (by issuing a command like <em>sudo apt-get install rsyslog</em>). Once installed, create the <em>/etc/rsyslog.d/server.conf</em> file on the centralized server, with the contents:</p> <pre> # Provide UDP syslog reception $ModLoad imudp $UDPServerRun 514 # Provide TCP syslog reception $ModLoad imtcp $InputTCPServerRun 514 # Use custom filenaming scheme $template FILENAME,"/var/log/remote/%HOSTNAME%.log" *.* ?FILENAME $PreserveFQDN on</pre> <p>Save and close that file. Now, on every client machine, create the file <em>/etc/rsyslog.d/client.conf</em><em> </em>with the contents:</p> <pre> $PreserveFQDN on $ActionQueueType LinkedList $ActionQueueFileName srvrfwd $ActionResumeRetryCount -1 $ActionQueueSaveOnShutdown on *.* @@SERVER_IP:514</pre> <p>Where SERVER_IP is the IP address of your centralized server. Save and close that file. Restart rsyslog on all machines with the command:</p> <pre> sudo systemctl restart rsyslog</pre> <p>You can now view the centralized log files with the command (run on the centralized server):</p> <pre> tail -f /var/log/remote/*.log</pre> <p>The <em>tail</em> command allows you to view those files as they are written to, in real time. You should see log entries appear that include the client hostname (Figure 6).</p> <p>Rsyslog is a great tool for creating a single point of entry for viewing the logs of all of your Linux servers. </p> <h3>More where that came from</h3> <p>This article only scratched the surface of the logging tools to be found on the Linux platform. And each of the above tools is capable of more than what is outlined here. However, this overview should give you a place to start your long day’s journey into the Linux log file.</p> <p><em>Learn more about Linux through the free <a href="https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux">“Introduction to Linux” </a>course from The Linux Foundation and edX.</em></p> </div> |