Syslog Linux
Syslog Linux
Some will generate log messages, and they will be called “devices” or “syslog
clients“.
Some will simply forward the messages received, they will be called “relays“.
Finally, there are some instances where you are going to receive and store log
data, those are called “collectors” or “syslog servers”.
Knowing those concepts, we can already state that a standalone Linux machine
acts as a “syslog client-server” on its own: it produces log data, it
is collected by rsyslog and stored right into the filesystem.
In the first design, you have one device and one collector. This is the most simple
form of logging architecture out there.
Add a few more clients to your infrastructure, and you have the basis of
a centralized logging architecture.
Multiple clients are producing data and are sending it to a centralized syslog
server, responsible for aggregating and storing client data.
Examples of relays could be Logstash instances for example, but they also could
be rsyslog rules on the client-side.
The rsyslog service sorts and writes syslog messages to the log files that do persist across
reboots in /var/log. The rsyslog service sorts the log messages to specific log files based on
the type of program that sent each message, or facility, and the priority of each syslog
message.
In addition to syslog message files, the /var/log directory contains log files from other
services on the system. The following table lists some useful files in the /var/log directory.
Listing /var/log
Using the tail command you can view the last few logs. Adding the -f
option lets you watch them in real time.
For RedHat based systems:
The rules for which logs go where are defined in the Syslog daemon’s
configuration file. For rsyslog, it is /etc/rsyslog.conf
3. View and Edit syslogs in Linux with a text editor
rsyslog is the Syslog daemon that will listen for logs from host. To check
if it’s installed, type:
$ rsyslogd -v
It will print some information if it’s installed
If it is not already installed, you can install it using the dnf command:
The file we need to modify is /etc/rsyslog.conf. You can use the editor
of your choice. I’ll be using the nano editor.
$ sudo nano /etc/rsyslog.conf
You can also group the logs by creating separate directories for separate
client systems using what rsyslog calls ‘templates’. These templates are
directives for rsyslog.
To enable grouping of logs by systems add lines 7 and 8. To enable
TCP, uncomment lines 4 and 5 by deleting the ‘#’ character at the start
of the line.
1
...
2 # Provides TCP syslog reception
3 # for parameters see http://www.rsyslog.com/doc/imtcp.html
5 input(type="imtcp" port="514")
7 $template FILENAME,"/var/log/%HOSTNAME%/syslog.log"
*.* ?FILENAME
8
...
9
By default rsyslog listens on port 514. We need to open this port using
the firewall-cmd command:
$ sudo firewall-cmd --add-port=514/tcp --zone=public --permanent
Now that we’ve made changes to the configuration file and opened the
port, we need to restart rsyslog so that it can pick up the new
configuration. We can restart rsyslog using the systemctl command:
If you want rsylog to automatically start every time you boot up, type:
We can use the netstat command to list all the open ports:
$ sudo netstat -pnlt