- How To View and Configure Linux Logs on Ubuntu and Centos
- Introduction
- Default Log File Location
- Viewing Log File Contents
- The rsyslog Daemon
- The rsyslog Configuration File
- Creating and Testing Your Own Log Messages
- Rotating Log Files
- The logrotate Configuration File
- Testing the Rotation
- Last Words
- Confluence Support
- Get started
- Knowledge base
- Products
- Jira Software
- Jira Service Management
- Jira Core
- Confluence
- Bitbucket
- Resources
- Documentation
- Community
- System Status
- Suggestions and bugs
- Marketplace
- Billing and licensing
- Viewport
- Confluence
- How to enable command line audit logging in linux
- Related content
- Still need help?
- Purpose
- Solution
How To View and Configure Linux Logs on Ubuntu and Centos
Published on December 17, 2013
Introduction
Linux system administrators often need to look at log files for troubleshooting purposes. In fact, this is the first thing any sysadmin would do.
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.
In this tutorial, we will have a look at different parts of the Linux logging mechanism.
The commands in this tutorial were tested in plain vanilla installations of CentOS 6.4, Ubuntu 12 and Debian 7.
Default Log File Location
The default location for log files in Linux is /var/log.
You can view the list of log files in this directory with a simple ls -l /var/log command.
This is what I see in my CentOS system:
Viewing Log File Contents
Here are some common log files you will find under /var/log:
maillog or mail.log
auth.log or secure
The wtmp and utmp files keep track of users logging in and out of the system. You cannot directly read the contents of these files using cat– there are specific commands for that.
We will now use some of these commands.
To see who is currently logged in to the Linux server, simply use the who command. This command gets its values from the /var/run/utmp file (for CentOS and Debian) or /run/utmp (for Ubuntu).
Here is an example from CentOS:
In this particular case, I am the sole user of the system. I was running the server from an Oracle VirtualBox and accessing it as root from both the console and an SSH session. Two other user accounts (sysadmin and joebolg) were also accessing the system.
The last command tells us the login history of users:
In this example, I am trying to find the login history of the user sysadmin. As you can see, there were couple of instances where he managed to crash the system.
To find out when was the system last rebooted, we can run the following command:
The result may look like this
To see when did someone last log in to the system, use lastlog:
In my system, the output looked like this:
For other text-based log files, you can use cat, head or tail commands to read the contents.
In the example below, I am trying to look at the last ten lines of /var/log/messages file in a Debian box:
The rsyslog Daemon
At 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.
The rsyslog Configuration File
The rsyslog daemon gets its configuration information from the rsyslog.conf file. The file is located under the /etc directory.
Basically, the rsyslog.conf file tells the rsyslog daemon where to save its log messages. This instruction comes from a series of two-part lines within the file.
This file can be found at rsyslog.d/50-default.conf on ubuntu.
The two part instruction is made up of a selector and an action. The two parts are separated by white space.
The selector part specifies what’s the source and importance of the log message and the action part says what to do with the message.
The selector itself is again divided into two parts separated by a dot (.). The first part before the dot is called *acility (the origin of the message) and the second part after the dot is called priority (the severity of the message).
Together, the facility/priority and the action pair tell rsyslog what to do when a log message matching the criteria is generated.
Here is excerpt from a CentOS rsyslog.conf file:
To understand what this all means, let’s consider the different types of facilities recognized by Linux. Here is a list:
- auth or authpriv: Messages coming from authorization and security related events
- kern: Any message coming from the Linux kernel
- mail: Messages generated by the mail subsystem
- cron: Cron daemon related messages
- daemon: Messages coming from daemons
- news: Messages coming from network news subsystem
- lpr: Printing related log messages
- user: Log messages coming from user programs
- local0 to local7: Reserved for local use
And here is a list of priorities in ascending order:
- debug: Debug information from programs
- info: Simple informational message — no intervention is required
- notice: Condition that may require attention
- warn: Warning
- err: Error
- crit: Critical condition
- alert: Condition that needs immediate intervention
- emerg: Emergency condition
So now let’s consider the following line from the file:
This just tells the rsyslog daemon to save all messages coming from the cron daemon in a file called /var/log/cron. The asterix (*) after the dot (.) means messages of all priorities will be logged. Similarly, if the facility was specified as an asterix, it would mean all sources.
Facilities and priorities can be related in a number of ways.
In its default form, when there is only one priority specified after the dot, it means all events equal to or greater than that priority will be trapped. So the following directive causes any messages coming from the mail subsystem with a priority of warning or higher to be logged in a specific file under /var/log:
This will log every message equal to or greater than the warn priority, but leave everything below it. So messages with err, crit, alert or emerg will also be recorded in this file.
Using an equal sign (=) after the dot (.) will cause only the specified priority to be logged. So if we wanted to trap only the info messages coming from the mail subsystem, the specification would be something like the following:
Again, if we wanted to trap everything from mail subsystem except info messages, the specification would be something like the following
In the first case, the mail.info file will contain everything with a priority lower than info. In the second case, the file will contain all messages with a priority above info.
Multiple facilities in the same line can be separated by commas.
Multiple sources (facility.priority) in the same line is separated by semicolon.
When an action is marked as an asterix (*), it means all users. This entry in my CentOS rsyslog.conf file is saying exactly that:
Try to see what’s the rsyslog.conf is saying in your Linux system. Here is an excerpt from the Debian server I am running:
As you can see, Debian saves all security/authorization level messages in /var/log/auth.log whereas CentOS saves it under /var/log/secure .
The configurations for rsyslog can come from other custom files as well. These custom configuration files are usually located in different directories under /etc/rsyslog.d. The rsyslog.conf file includes these directories using $IncludeConfig directive.
Here is what it looks like in Ubuntu:
The contents under the /etc/rsyslog.d directory looks like the following:
Now the destination for a log message does not necessarily have to be a log file; the message can be sent to a user’s console. In this case, the action field will contain the username. If more than one user needs to receive the message, their usernames are separated by commas. If the message needs to be broadcast to every user, it’s specified by an asterix (*) in the action field.
Because of being part of a network operating system, rsyslog daemon can not only save log messages locally, it can also forward them to another Linux server in the network or act as a repository for other systems. The daemon listens for log messages in UDP port 514. The example below will forward kernel critical messages to a server called “texas”.
Creating and Testing Your Own Log Messages
So now it’s time for us to create our own log files.
To test this, we will do the following
Add a log file specification in /etc/rsyslog.conf file
Restart the rsyslog daemon
Test the configuration using the logger utility
In the following example, I am adding two new lines in my CentOS Linux system’s rsyslog.conf file. As you can see, each of them are coming from a facility called local4 and they have different priorities.
Next, the service is restarted so the config file data is reloaded:
To generate the log message now, the logger application is called:
Looking under the /var/log directory now shows two new files:
The size of the local4info.log is non-zero. So when it’s opened, I see the message has been recorded:
Rotating Log Files
As more and more information is written to log files, they get bigger and bigger. This obviously poses a potential performance problem. Also, the management of the files become cumbersome.
Linux uses the concept of “rotating” log files instead of purging or deleting them. When a log is rotated, a new log file is created and the old log file is renamed and optionally compressed. A log file can thus have multiple old versions remaining online. These files will go back over a period of time and will represent the backlog. Once a certain number of backlogs have been generated, a new log rotation will cause the oldest log file to be deleted.
The rotation is initiated through the logrotate utility.
The logrotate Configuration File
Like rsyslog, logrotate also depends on a configuration file and the name of this file is logrotate.conf. It’s located under /etc.
Here is what I see in the logrotate.conf file of my Debian server:
The lines are fairly self-explanatory. By default, log files are to be rotated weekly with four backlogs remaining online at any one time. When the program runs, a new, empty log file will be generated and optionally the old ones will be compressed.
The only exception is for wtmp and btmp files. wtmp keeps track of system logins and btmp keeps track of bad login attempts. Both these log files are to be rotated every month and no error is returned if any previous wtmp or btmp file can be found.
Custom log rotation configurations are kept under etc/logrotate.d directory. These are also inluded in the logrotate.conf with the include directive. The Debian installation shows me the content of this directory:
The contents of the rsyslog shows how to recycle a number of log files:
As you can see, the syslog file will be reinitialized every day with seven days’ worth of logs being kept online. Other log files are rotated every week.
Also worth noting is the postrotate directive. This specifies the action that happens after the whole log rotation has completed.
Testing the Rotation
Logrotate can be manually run to recycle one or more files. And to do that, we simply specify the relevant configuration file as an argument to the command.
To see how this works, here is a partial list of log files under /var/log directory in my test CentOS server:
The partial contents of the logrotate.conf file looks like this:
Next we run the logrotate command:
Messages scroll over as new files are generated, errors are encountered etc. When the dust settles, we try to check for new mail, secure or messages files:
As we can see, all three new log files have been created. The maillog and secure files are still empty, but the new messages file already has some data in it.
Last Words
Hopefully this tutorial has given you some ideas about Linux logging. You can try to look into your own development or test systems to have a better idea. Once you are familiar with the location of the log files and their configuration settings, use that knowledge for supporting your production systems. And then maybe you can create some aliases to point to these files to save some typing time as well.
Источник
Confluence Support
Get started
Knowledge base
Products
Jira Software
Project and issue tracking
Jira Service Management
Service management and customer support
Jira Core
Manage any business project
Confluence
Bitbucket
Git code management
Resources
Documentation
Usage and admin help
Community
Answers, support, and inspiration
System Status
Cloud services health
Suggestions and bugs
Feature suggestions and bug reports
Marketplace
Billing and licensing
Frequently asked questions
Viewport
Confluence
How to enable command line audit logging in linux
Related content
Still need help?
The Atlassian Community is here for you.
The content on this page relates to platforms which are not supported. Consequently, Atlassian Support cannot guarantee providing any support for it. Please be aware that this material is provided for your information only and using it is done so at your own risk.
Purpose
This KB article contains information that is outside of the Atlassian Support Offerings and is provided as a suggestion to achieve the mentioned goal.
This is not intended as a complete solution nor as a recommendation to use on production instances.
As this involves security concerns, the administrator should work in conjunction with their security team to understand the best solution available to their company.
To record all commands entered into the shell in a linux environment to a log file. This can be useful for auditing user actions or for security audits.
This is not specific to Confluence or any product, but it will audit command line actions including those things related to Confluence. Service restarts, all inputs from bash, and user actions should all be logged using this method.
As an alternative you may consider Snoopy:
Snoopy is a small library that logs all program executions on your Linux/BSD system.
Solution
Login to the linux box and assume root
Edit /etc/profile and add the following lines to the bottom of the file:
Edit /etc/rsyslog.conf and add the following lines to the bottom of the file:
Either restart the rsyslog service, or restart the whole machine to release all user sessions — forcing a reload of the bash profile and enacting the changes
The audit logging will be visible under /var/log/syslog and /var/log/cmdline and will look like this:
Источник