Tuesday, September 6, 2011

ZFS Volumes not showing up on reboot?

If you're using ZFS on FreeBSD and your ZFS volumes do not appear after rebooting the system, verify that your rc.conf file has zfs_enable="YES". This allows /etc/rc.d/zvol to run, which executes an undocumented 'zfs volinit' command to create the /dev/zvol/... device entries. The script also adds swap space volumes if the ZFS volume has org.freebsd:swap=on set.

Friday, September 2, 2011

Apache syslogging on FreeBSD

If you need to use Syslog to send Apache log output there are plenty of examples already on the Internet. The first hit on google was the O'Reilly Sysadmin blog, which is very useful. However, the page is a bit old and the perl script they provide for Syslogging access logs is in need of updating. My modified version is below. To summarize the process..

  1. Put the following script in /usr/local/bin/apache_syslog.


    #!/usr/bin/perl

    # $Id$
    #
    # A wrapper script that logs apache access via syslog. Copied from an example
    # at http://oreilly.com/pub/a/sysadmin/2006/10/12/httpd-syslog.html
    # Script requires sysutils/p5-Sys-Syslog from FreeBSD ports.
    #

    use Sys::Syslog qw( :DEFAULT setlogsock );

    # Excluded, per the rules of Sys:Syslog
    # http://search.cpan.org/~saper/Sys-Syslog-0.29/Syslog.pm#THE_RULES_OF_SYS::SYSLOG
    #setlogsock('unix');
    openlog('httpd', "cons, pid", 'local2');

    while ($log = ) {
    syslog('notice', $log);
    }

    closelog;

  2. Install sysutils/p5-Sys-Syslog from ports (FreeBSD).
  3. In your Apache config replace your ErrorLog directive with "ErrorLog syslog:local1".
  4. Replace your CustomLog directive (for access logs) with "CustomLog |/usr/local/bin/apache_syslog combined".
  5. Edit /etc/syslog.conf, adding the following lines
    !httpd
    local1.* /var/log/httpd-error.log
    local2.* /var/log/httpd-access.log
    !*
  6. Create the log files with "touch /var/log/httpd-error.log /var/log/httpd-access.log".
  7. Edit /etc/newsyslog.conf, adding the following lines
    /var/log/httpd-error.log 640 14 * @T00 J
    /var/log/httpd-access.log 640 14 * @T00 J
  8. (Re)start syslogd and apache.
  9. Profit.