{"id":825,"date":"2018-06-26T21:19:40","date_gmt":"2018-06-26T21:19:40","guid":{"rendered":"http:\/\/orissawebhosting.in\/blog\/?p=825"},"modified":"2019-06-27T15:31:15","modified_gmt":"2019-06-27T15:31:15","slug":"how-to-view-logs-on-centos7","status":"publish","type":"post","link":"https:\/\/orissawebhosting.in\/blog\/how-to-view-logs-on-centos7\/","title":{"rendered":"How To View Logs on Centos7"},"content":{"rendered":"<h4>View and Configure Linux Logs on Centos7<\/h4>\n<p>Linux and the applications that run on it can generate all different types of messages, which are recorded in various log files. Linux uses a set of configuration files, directories, programs, commands and daemons to create, store and recycle these log messages. Knowing where the system keeps its log files and how to make use of related commands can therefore help save valuable time during troubleshooting.<\/p>\n<p><strong>Default Log File Location<\/strong><br \/>\nThe default location for log files in Linux is \/var\/log.<\/p>\n<p>You can view the list of log files in this directory by below commands<\/p>\n<pre><strong># ls -l \/var\/log<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-828 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log1.jpg\" alt=\"\" width=\"736\" height=\"287\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log1.jpg 736w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log1-300x117.jpg 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/p>\n<p><strong>who<\/strong><\/p>\n<p>To see who is currently logged in to the Linux server, simply use the who command.<\/p>\n<pre><strong># who<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-829 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log2.jpg\" alt=\"\" width=\"572\" height=\"52\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log2.jpg 572w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log2-300x27.jpg 300w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/p>\n<p>In this particular case, I am the sole user of the system. I am accessing it as root via SSH session.<\/p>\n<p><strong>The last command tells us the login history of users<\/strong><\/p>\n<pre><strong># last | grep root<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-830 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log3.jpg\" alt=\"\" width=\"712\" height=\"326\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log3.jpg 712w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log3-300x137.jpg 300w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/p>\n<p>In this example, I am trying to find the login history of the user root. As you can see, there were couple of instances where he managed to crash the system.<\/p>\n<p>To find out when was the system last rebooted, we can run the following command.<\/p>\n<pre><strong># last reboot<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-831 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log4.jpg\" alt=\"\" width=\"644\" height=\"211\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log4.jpg 644w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log4-300x98.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/p>\n<p>To see when did someone last log in to the system, use lastlog<\/p>\n<pre><strong># lastlog<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-832 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log5.jpg\" alt=\"\" width=\"670\" height=\"577\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log5.jpg 670w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log5-300x258.jpg 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/p>\n<p>For other text-based log files, you can use cat, head or tail commands to read the contents.<\/p>\n<p>In the example below, I am trying to look at the last lines of \/var\/log\/messages file.<\/p>\n<pre><strong># tail \/var\/log\/messages<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-834 size-full\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log6-1.jpg\" alt=\"\" width=\"1346\" height=\"361\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log6-1.jpg 1346w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log6-1-300x80.jpg 300w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log6-1-768x206.jpg 768w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log6-1-1024x275.jpg 1024w\" sizes=\"(max-width: 1346px) 100vw, 1346px\" \/><\/p>\n<p><strong>The rsyslog Daemon<\/strong><br \/>\nAt the heart of the logging mechanism is the rsyslog daemon. This service is responsible for listening to log messages from different parts of a Linux system and routing the message to an appropriate log file in the \/var\/log directory. It can also forward log messages to another Linux server.<\/p>\n<p>The rsyslog daemon gets its configuration information from the\u00a0<code>rsyslog.conf<\/code>\u00a0file. The file is located under the \/etc directory.<\/p>\n<p>Here is excerpt from a CentOS rsyslog.conf file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-837 size-large\" src=\"http:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log7-1-1024x522.jpg\" alt=\"\" width=\"640\" height=\"326\" srcset=\"https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log7-1-1024x522.jpg 1024w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log7-1-300x153.jpg 300w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log7-1-768x392.jpg 768w, https:\/\/orissawebhosting.in\/blog\/wp-content\/uploads\/2018\/06\/log7-1.jpg 1326w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>These are the ways to find the logs in centOS 7.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>View and Configure Linux Logs on Centos7 Linux and the applications that run on it can generate all different types of messages, which are recorded in various log files. Linux uses a set of configuration files, directories, programs, commands and daemons to create, store and recycle these log messages. Knowing where the system keeps its log files and how to make use of related commands can therefore help save valuable time during troubleshooting. Default Log File Location The default location for log files in Linux is \/var\/log. You can view&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/825"}],"collection":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=825"}],"version-history":[{"count":6,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/825\/revisions"}],"predecessor-version":[{"id":1067,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/825\/revisions\/1067"}],"wp:attachment":[{"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/orissawebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}