How to Configure Remote Syslog Logging: Difference between revisions

From RidgeRun Developer Wiki
mNo edit summary
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== General Information ==
<seo title="How to Configure Remote Syslog Logging | Busybox Syslogd" titlemode="replace" keywords="GStreamer, Linux SDK, Linux BSP,  Embedded Linux, Device Drivers, Nvidia, Xilinx, TI, NXP, Freescale, Embedded Linux driver development, Linux Software development, Embedded Linux SDK, Embedded Linux Application development, GStreamer Multimedia Framework."  description="We provide a basic procedure for configuring a remote syslog server and a client. Easily configure remote syslog logging with our experts at RidgeRun."></seo>


'''syslogd''' is the Linux system logging utility that take care of filling up your files in /var/log when it is asked to.
= General Information =


On a standard system, logging is only done on the local drive. But syslog can be configured to receive logging from a remote client, or to send logging to a remote syslog server.
'''sysklogd''' is the Linux system logging utility that take manages files in the <tt>/var/log</tt> directory.


This ''How to'' gives the basic procedure need it for configuring a remote syslog server (in your PC) and client (in your board with our SDK filesystem structure).
On a typical desktop system, logging produced by local application and is saved to files on the local drive. But syslog can also be configured to receive logging from a remote client, or to send logging information to a remote syslog server.


=== Configuring BusyBox for setting up the syslogd server ===
This ''How to'' gives the basic procedure for configuring a remote syslog server (e.g. your Ubuntu desktop PC) and a client (e.g. your target hardware running a RidgeRun SDK produced file system).


The changes on this side are minimal. Basically you have to tell syslogd to listen for remote messages. To enable this you have to go and edit the following file in your host machine:
Commands to be run on the <span style="background:#FFFFC0">Ubuntu host</span> have a yellow background. Commands to be run on the <span style="background:#C0FFFF">Ubuntu target</span> have an aqua background. 


<pre>
== References ==
host$ sudo <Prefer text editor>/etc/default/syslogd
 
* http://techtots.blogspot.com/2011/12/rsyslog-enabling-remote-logging-service.html
 
= Configuring host PC =
 
If you are using an older version of Ubuntu, you are likely running syslogd.  Newer versions use rsyslog.
 
<pre style="background:#FFFFC0">
sudo apt-get install rsyslog
</pre>
</pre>


Make sure in this file SYSLOGD is set to:
== syslogd server  ==
 
The changes on this side are minimal. Basically you have to tell syslogd to listen for remote messages. To enable your host computer's syslogd server to accept log data from a remote client, you need to edit the file <tt>/etc/default/syslogd</tt> and set


<pre style="background:#FFFFC0">
SYSLOGD="-r"  
SYSLOGD="-r"  
</pre>


Save the file and restart '''syslogd''' by doing:


Save the file and restart '''syslogd''' by doing:  
<pre style="background:#FFFFC0">
sudo service sysklogd restart
</pre>
 
You host syslogd server will now accept remove log messages.
 
== rsyslog server ==
 
in the <tt>/etc/rsyslog.conf</tt> file, enable the following:
 
<pre style="background:#FFFFC0">
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
</pre>
 
Then start or restart the server as needed
 
<pre style="background:#FFFFC0">
sudo service rsyslog start
</pre>
 
or
 
<pre style="background:#FFFFC0">
sudo service rsyslog restart
</pre>
 
= Configuring Busybox syslogd to send messages to remote logging service =
 
Busybox supports several useful system logging utilities.
 
{| border=2
| syslogd || Utility used to record logs of all the significant events that occur on a system. Every message that is logged records the date and time of the event, and will generally also record the name of the application that generated the message. When used in conjunction with klogd, messages from the Linux kernel can also be recorded.
|-
| logger || Utility allowing you to send arbitrary text messages to the system log (i.e. the ''syslogd'' utility) so the messages can be logged. This is generally used to help locate problems that occur within programs and scripts. 
|-
| klogd || Utility which intercepts and logs all messages from the Linux kernel and sends the messages out to the ''syslogd'' utility so they can be logged.
|}
 
= Enable Busybox logging utilities =
 
Use the SDK configuration tool to enable Busybox logging utilities ''syslogd'', ''logger'', and ''klogd''.
 
<pre  style="background:#FFFFC0">
make -C $DEVDIR config
</pre>


<pre>
<pre>
host$ sudo /etc/init.d/syslogd restart
  -> File System Configuration
    -> Select target's file system software     
        -> busybox-1.14.2
          -> Busybox configuration
              -> System Logging Utilities
</pre>
</pre>


=== Configuring BusyBox for setting up the syslogd remote feature using our SDK FileSystem structure in the board===
You can verify these have been enabled by checking the contents of the bspconfig file:


This can be done in two ways.
<pre  style="background:#FFFFC0">
grep -E '(CONFIG_SYSLOGD|CONFIG_KLOGD|CONFIG_LOGGER)' $DEVDIR/bsp/mach/bspconfig
</pre>


1) The first one, it can be done when the board has boot up and Linux is also running up. Our file system initializes a default configuration for '''syslogd''', then for add the remote feature you have to stop this process and configure a new one following this steps:
Expected output


<pre>
<pre>
target# ps aux | grep syslogd
CONFIG_SYSLOGD=y
CONFIG_KLOGD=y
CONFIG_LOGGER=y
</pre>
</pre>


If there is a '''syslogd''' process running then kill it.
Then rebuild Busybox.


<pre>
<pre  style="background:#FFFFC0">
target# killall -9 syslogd
make -C $DEVDIR fs
</pre>
 
 
= Manual steps to verify local logging =
 
On your target hardware verify ''syslogd'' and ''klogd'' are not running:
 
<pre  style="background:#C0FFFF">
killall -9 syslogd
killall -9 klogd
</pre>
 
Manually start ''syslogd'' and ''klogd'' to enable logging:
 
<pre style="background:#C0FFFF">
syslogd -O /var/log/messages
klogd
</pre>
 
Check <tt>/var/log/messages</tt> for the bootup Linux console messages:
 
<pre style="background:#C0FFFF">
cat/var/log/messages
</pre>
</pre>


Create a new process of '''syslogd''' enabling the remote feature:
= Manual steps to verify remote logging =


<pre>
On your target hardware verify ''syslogd'' and ''klogd'' are not running:
target#  /sbin/syslogd -R <serverip>:<port using by UDP (default PORT=514/UDP)> -L (this save the messages in the server and the client. Optional) -O <PATH where you want to send the log messages>
 
<pre  style="background:#00FFFF">
killall -9 syslogd
</pre>
</pre>


Example:
Manually start ''syslogd'' and ''klogd'' to enable logging:
 
<pre style="background:#00FFFF">
REMOTE_LOGGING_SERIVCE=10.111.0.3
PORT=514


<pre>
syslogd -R $REMOTE_LOGGING_SERIVCE:$PORT -L -O /var/log/messages
target#  /sbin/syslogd -R 10.251.101.60  -L -O /var/log/messages                                          
klogd     
</pre>
</pre>




2) For the second way to this, the work should be done if you are familiar with our SDK build system and has to be set it before you create the images of the kernel and file system with it. If not just follow the first case, is the easy way to do this.  
= Automatically starting remote logging =
 
You can configure your system to automatically start the remote logging service be editing the file <tt>$DEVDIR/fs/overlay/etc/init.d/syslogd</tt>:


Generally we have an script in our file system that initializes '''syslogd''' when the board boot up the kernel and the file system customized by us.  For setting up the''' syslogd''' remote edit this file in the host side:
<pre style="background:#FFFFC0">
#!/bin/sh


<pre>
REMOTE_LOGGING_SERIVCE=10.111.0.3
host$ <Prefer text editor> $(DEVDIR)/fs/overlay/etc/init.d/ syslogd
PORT=514
 
mkdir -p /var/log
syslogd -R $REMOTE_LOGGING_SERIVCE:$PORT -L -O /var/log/messages         
klogd
</pre>
</pre>


As the first way described above, add the following line:
Create a symbolic link so the ''init'' daemon runs the script.
 
<pre style="background:#FFFFC0">
cd $DEVDIR/fs/overlay/etc/rc.d
ln -s ../init.d/syslogd S10syslogd
</pre>


<pre>
= Verifying proper operation =
/sbin/syslogd  -R <serverip>:<port using by UDP (default PORT=514/UDP)>  -L (this save the messages in the server and the client. Optional) -O <PATH where you want to send the log messages>
</pre>


Save the file and build and install the images create it by our SDK build system.
A simple way to add a log message every few seconds is using the Busybox logger utility.  You man need to reconfigure your SDK to enable the building of the Busybox logger utility.


This will automatically execute the syslogd with the remote feature anytime the board is boot up and the file system loads.


You can check it by doing:
On the target, start a simple script that add a message to the log every two seconds.


<pre>
<pre style="background:#C0FFFF">
target# ps aux | grep syslogd
( while sleep 2 ; do date ; done | logger -t "DATE:" ) &
</pre>
</pre>


== Logging on target hardware ==


For checking configuration has successfully done, try the following:
If you used the <tt>-L</tt> option with syslogd on the target hardware, then you can verify local logging is occurring as expected.


<pre>
<pre style="background:#C0FFFF">
target# while sleep 2 ; do date ; done | logger -t "DATE:"
tail -f /var/log/messages
target# tail -f <PATH (Default:/var/log/messages)>
</pre>
</pre>
== Logging on host PC  ==


To check the messages are been sent to the server:
To check the messages are been sent to the server:


<pre>
<pre style="background:#FFFFC0">
host# tail -f <PATH (Default:/var/log/messages)
tail -f /var/log/messages
</pre>
</pre>
= Debugging =
If remote logging is not working, use ''wireshark'' on your Ubuntu host computer to watch the network traffic to verify that the target hardware is sending the messages to the host computer.
[[Category:HowTo]][[Category:Debug]]

Latest revision as of 03:05, 4 August 2017


General Information

sysklogd is the Linux system logging utility that take manages files in the /var/log directory.

On a typical desktop system, logging produced by local application and is saved to files on the local drive. But syslog can also be configured to receive logging from a remote client, or to send logging information to a remote syslog server.

This How to gives the basic procedure for configuring a remote syslog server (e.g. your Ubuntu desktop PC) and a client (e.g. your target hardware running a RidgeRun SDK produced file system).

Commands to be run on the Ubuntu host have a yellow background. Commands to be run on the Ubuntu target have an aqua background.

References

Configuring host PC

If you are using an older version of Ubuntu, you are likely running syslogd. Newer versions use rsyslog.

sudo apt-get install rsyslog

syslogd server

The changes on this side are minimal. Basically you have to tell syslogd to listen for remote messages. To enable your host computer's syslogd server to accept log data from a remote client, you need to edit the file /etc/default/syslogd and set

SYSLOGD="-r" 

Save the file and restart syslogd by doing:

sudo service sysklogd restart 

You host syslogd server will now accept remove log messages.

rsyslog server

in the /etc/rsyslog.conf file, enable the following:

# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

Then start or restart the server as needed

sudo service rsyslog start

or

sudo service rsyslog restart

Configuring Busybox syslogd to send messages to remote logging service

Busybox supports several useful system logging utilities.

syslogd Utility used to record logs of all the significant events that occur on a system. Every message that is logged records the date and time of the event, and will generally also record the name of the application that generated the message. When used in conjunction with klogd, messages from the Linux kernel can also be recorded.
logger Utility allowing you to send arbitrary text messages to the system log (i.e. the syslogd utility) so the messages can be logged. This is generally used to help locate problems that occur within programs and scripts.
klogd Utility which intercepts and logs all messages from the Linux kernel and sends the messages out to the syslogd utility so they can be logged.

Enable Busybox logging utilities

Use the SDK configuration tool to enable Busybox logging utilities syslogd, logger, and klogd.

make -C $DEVDIR config
  -> File System Configuration
     -> Select target's file system software      
        -> busybox-1.14.2
           -> Busybox configuration 
              -> System Logging Utilities

You can verify these have been enabled by checking the contents of the bspconfig file:

grep -E '(CONFIG_SYSLOGD|CONFIG_KLOGD|CONFIG_LOGGER)' $DEVDIR/bsp/mach/bspconfig 

Expected output

CONFIG_SYSLOGD=y
CONFIG_KLOGD=y
CONFIG_LOGGER=y

Then rebuild Busybox.

make -C $DEVDIR fs


Manual steps to verify local logging

On your target hardware verify syslogd and klogd are not running:

killall -9 syslogd
killall -9 klogd

Manually start syslogd and klogd to enable logging:

syslogd -O /var/log/messages
klogd

Check /var/log/messages for the bootup Linux console messages:

cat/var/log/messages

Manual steps to verify remote logging

On your target hardware verify syslogd and klogd are not running:

killall -9 syslogd

Manually start syslogd and klogd to enable logging:

REMOTE_LOGGING_SERIVCE=10.111.0.3
PORT=514

syslogd -R $REMOTE_LOGGING_SERIVCE:$PORT -L -O /var/log/messages
klogd      


Automatically starting remote logging

You can configure your system to automatically start the remote logging service be editing the file $DEVDIR/fs/overlay/etc/init.d/syslogd:

#!/bin/sh

REMOTE_LOGGING_SERIVCE=10.111.0.3
PORT=514

mkdir -p /var/log
syslogd -R $REMOTE_LOGGING_SERIVCE:$PORT -L -O /var/log/messages           
klogd

Create a symbolic link so the init daemon runs the script.

cd $DEVDIR/fs/overlay/etc/rc.d
ln -s ../init.d/syslogd S10syslogd

Verifying proper operation

A simple way to add a log message every few seconds is using the Busybox logger utility. You man need to reconfigure your SDK to enable the building of the Busybox logger utility.


On the target, start a simple script that add a message to the log every two seconds.

( while sleep 2 ; do date ; done | logger -t "DATE:" ) &

Logging on target hardware

If you used the -L option with syslogd on the target hardware, then you can verify local logging is occurring as expected.

tail -f /var/log/messages

Logging on host PC

To check the messages are been sent to the server:

tail -f /var/log/messages

Debugging

If remote logging is not working, use wireshark on your Ubuntu host computer to watch the network traffic to verify that the target hardware is sending the messages to the host computer.