2013-08-04

Prolong life of SD card on Raspberry Pi by sending all logs to my NAS via syslog

You can read a lot about how your SD card in the Raspberry Pi can become broken if you write too much to it. I don't know if it is still applicable for modern SD cards.
However I have tried to reduce writing log events to the SD card and instead sending them to my NAS.
You need to edit a few text files. I'm used to emacs and have installed that. You can use whichever editor that you feel comfortable with.
This is what I did:

  1. Set the host name of the Raspberry Pi to something unique. This is the host name that will show up for each log on the NAS.
    $ sudo emacs /etc/hostname
    Replace raspberrypi with the host name you would like to use. Save the file and exit the editor.
  2. Then open the next file:
    $ sudo emacs /etc/hosts
    Replace all instancied of raspberrypi with the new host name. Save the file and exit the editor.
  3. You have to restart a process or reboot your Raspberry Pi. To restart process type
    $ sudo /etc/init.d/hostname.sh start
  4. To redirect all syslog logs to a NAS open the syslog config file:
    $ sudo emacs /etc/rsyslog.conf
    Under the RULES sections add the following line:
    *.* @11.22.33.44
    You need to change 11.22.33.44 with the IP number to your NAS server.
    Then you have to comment out all log directives to log files by setting a # before each row.
    Save the file and exit the editor.
  5. Now you need to restart the rsyslog daemon mto make it reread the config file:
    $ sudo service rsyslog restart
    Now you can watch the logs come to your NAS instead of to the SD card.

1 comment:

  1. Hi, Niklas! That info is exactly what I was looking for. Thanks for sharing it! Best wishes from Brazil.

    ReplyDelete