Thursday, 16 April 2009

Rebuilding a Zoneminder system after a Crash

The Zoneminder system setup using this link has had a hard disk crash. Not much of the system could be saved. So we chose to rebuild from scratch.

This time we installed a 160GB disk for the system itself and swap, and a seperate 500GB disk for events and backups of the system.

The start of the guide still applies, but we also did the following:
using fdisk created a 6GB for backups and a 482GB partition for events

Formated both as EXT3 and added the following to /etc/fstab:
/dev/sda1 /backups ext3 defaults,errors=remount-ro 0 1
/dev/sda2 /var/cache/zoneminder/events ext3 defaults,errors=remount-ro 0 1

Set correct permissions for the events dir:
sudo chown www-data:www-data /var/cache/zoneminder/events/

Added a time sync script:
sudo nano /etc/cron.daily/timesync

And added:
#!/bin/sh

ntpdate 0.nl.pool.ntp.org

Then:
sudo chmod 755 /etc/cron.daily/timesync

Fix Video permissions:
chmod 4755 /usr/bin/zmfix

Added a MySQL backup script I also use on our main Linux server:
sudo nano /etc/cron.daily/DB_backup

Added:
#!/bin/sh

mv /backups/MySQL_Backup/Daily6.sql /backups/MySQL_Backup/Daily7.sql
mv /backups/MySQL_Backup/Daily5.sql /backups/MySQL_Backup/Daily6.sql
mv /backups/MySQL_Backup/Daily4.sql /backups/MySQL_Backup/Daily5.sql
mv /backups/MySQL_Backup/Daily3.sql /backups/MySQL_Backup/Daily4.sql
mv /backups/MySQL_Backup/Daily2.sql /backups/MySQL_Backup/Daily3.sql
mv /backups/MySQL_Backup/Daily1.sql /backups/MySQL_Backup/Daily2.sql
mv /backups/MySQL_Backup/Daily.sql /backups/MySQL_Backup/Daily1.sql

mysqldump -r /backups/MySQL_Backup/Daily.sql --all-databases

Then ran:
sudo chmod 755 /etc/cron.daily/DB_backup
sudo mkdir /backups/MySQL_Backup

Set up main backup system using Rsnapshot:

sudo apt-get install rsnapshot

sudo nano /etc/rsnapshot.conf (Watch for tabs instead of spaces!!!)

Contents of config file: (used cat /etc/rsnapshot.conf | grep -v -e ^# to get this output btw)
(ALL SPACES MUST BE TABS!!)
config_version 1.2
snapshot_root /backups/
cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger
cmd_du /usr/bin/du
cmd_rsnapshot_diff /usr/bin/rsnapshot-diff
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 6
verbose 2
loglevel 3
logfile /var/log/rsnapshot.log
lockfile /var/run/rsnapshot.pid
rsync_short_args -a
rsync_long_args --delete --numeric-ids --relative --delete-excluded
exclude /backups
exclude /dev
exclude /media
exclude /proc
exclude /tmp
exclude /mnt
exclude /sys
exclude /proc
exclude /var/cache/zoneminder/events
backup / localhost/

Then add this to /etc/crontab:
0 */4 * * * root /usr/bin/rsnapshot hourly
50 23 * * * root /usr/bin/rsnapshot daily
40 23 1,8,15,22 * * root /usr/bin/rsnapshot weekly
30 23 1 * * root /usr/bin/rsnapshot monthly

Installed X and setup autologin and auto script run:
sudo apt-get install gdm

sudo apt-get install xorg

On the machine itself (not SSH) ran:

sudo startx

sudo gdmsetup

In gdmsetup I set the user 'zoneminder' as autologin, and set the default session to run the Xclient script.

Create the Xscript:
nano /home/zoneminder/.xsession

And insert:
#!/bin/sh

while ( true )
do
/usr/sbin/xlib_shm-script
sleep 1
done


Then run:
chmod 755
/home/zoneminder/.xsession

Set the correct screen resolution:
sudo apt-get install
displayconfig-gtk
sudo displayconfig-gtk

I set this to 800x600, this suits the cameras best

Stop screen blanking by adding this to the /etc/X11/xorg.conf file:
Section "ServerFlags"
Option "blank time" "0"
Option "standby time" "0"
Option "suspend time" "0"
Option "off time" "0"
EndSection

Create, setup & install the Xlib_shm Zoneminder raw viewing script:
Check the version numbers! not all Xlib_shm version is compatible with each version of Zonderminder!

sudo wget http://dig.hopto.org/xlib_shm/xlib_shm-0.6.3.tgz

sudo tar xfz xlib_shm-0.6.3.tgz

sudo apt-get install libxv-dev

sudo apt-get install build-essentials

sudo apt-get install libmysqlclient15-dev

sudo nano xlib_shm.c

And changed /usr/local/etc/zm.conf into /etc/zm/zm.conf

sudo make all

Place the binary xlib_shm in /usr/sbin/

sudo chown root.root /usr/sbin/xlib_shm
sudo chmod +s /usr/sbin/xlib_shm

For the actual auto starting of xlib_shm I first created a new shell script:
sudo nano /usr/sbin/xlib_shm-script

And added this:
#!/bin/sh
xlib_shm -m 1 -m 23 -m 11 -m 12 -k 0x07a6d0000 -d 40000


Then:
sudo chmod 755 /usr/sbin/xlib_shm-script




No comments: