Zoneminder

From Hack Sphere Labs Wiki
Jump to: navigation, search

functions.php


Clear Events

cd /var/cache/zoneminder/events/
rm -rf *

Debian Squeeze

  • Enable Backports
nano /etc/apt/sources.list

add:

deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Install other stuff:

apt-get install libfaac-dev
apt-get install libmp3lame-dev
apt-get install libogg-dev
apt-get install libjpeg-dev
apt-get install libtheora-dev
apt-get install libvorbis-dev
apt-get install libx264-dev
apt-get -t squeeze-backports install libxvidcore-dev

Install Zoneminder:

apt-get install zoneminder
ln -s /etc/zm/apache.conf    /etc/apache2/conf.d/zoneminder.conf
/etc/init.d/apache2 restart


  • zmwatch[22830]: ERR [Can't get shared memory id '7a6d0002', 2: No such file or directory]

Make shared memory key work:

Test it:

echo 167772160 >/proc/sys/kernel/shmall
echo 167772160 >/proc/sys/kernel/shmmax

Restart Zoneminder

/etc/init.d/zoneminder stop

Make it perm

nano /etc/sysctl.conf
# Increase the maximum shared memory
kernel.shmall = 167772160
kernel.shmmax = 167772160


/etc/init.d/zoneminder start

libjpeg turbo

You can use libjpeg-turbo to speed things up. This is worth it. I had a system at like 6.0 load and now it is at .10 Plus they just released a new version of libjpeg turbo.

root@hslmonitor:~# locate libjpeg
/usr/lib/libjpeg.a
/usr/lib/libjpeg.la
/usr/lib/libjpeg.so
/usr/lib/libjpeg.so.62
/usr/lib/libjpeg.so.62.0.0
/usr/share/doc/libjpeg62
/usr/share/doc/libjpeg62-dev
/usr/share/doc/libjpeg62-dev/changelog.Debian.gz
/usr/share/doc/libjpeg62-dev/changelog.gz
/usr/share/doc/libjpeg62-dev/coderules.doc.gz
/usr/share/doc/libjpeg62-dev/copyright
/usr/share/doc/libjpeg62-dev/examples
/usr/share/doc/libjpeg62-dev/examples/example.c.gz
/usr/share/doc/libjpeg62-dev/libjpeg.doc.gz
/usr/share/doc/libjpeg62-dev/README.Debian
/usr/share/doc/libjpeg62-dev/structure.doc.gz
/usr/share/doc/libjpeg62/changelog.Debian.gz
/usr/share/doc/libjpeg62/changelog.gz
/usr/share/doc/libjpeg62/copyright
/usr/share/doc/libjpeg62/README.gz
/var/cache/apt/archives/libjpeg62-dev_6b1-1_amd64.deb
/var/cache/apt/archives/libjpeg62_6b1-1_amd64.deb


replace libjpeg with libjpeg-turbo (64bit)

dpkg --remove --force-depends libjpeg62
dpkg --remove --force-depends libjpeg62-dev
wget libjpeg-turbo 64bit deb file
mv (downloaded name) to libjpeg-turbo-official_1.3.0_amd64.deb or whatever
dpkg -i libjpeg-turbo-official_1.3.0_amd64.deb
ln -s /opt/libjpeg-turbo/lib/libjpeg.a /usr/lib/libjpeg.a && \
ln -s /opt/libjpeg-turbo/include/jconfig.h /usr/include/jconfig.h && \
ln -s /opt/libjpeg-turbo/include/jerror.h /usr/include/jerror.h && \
ln -s /opt/libjpeg-turbo/include/jmorecfg.h /usr/include/jmorecfg.h && \
ln -s /opt/libjpeg-turbo/include/jpeglib.h /usr/include/jpeglib.h

  • I used (64bit):
ln -s /opt/libjpeg-turbo/lib64/libjpeg.a /usr/lib/libjpeg.a && \
ln -s /opt/libjpeg-turbo/include/jconfig.h /usr/include/jconfig.h && \
ln -s /opt/libjpeg-turbo/include/jerror.h /usr/include/jerror.h && \
ln -s /opt/libjpeg-turbo/include/jmorecfg.h /usr/include/jmorecfg.h && \
ln -s /opt/libjpeg-turbo/include/jpeglib.h /usr/include/jpeglib.h
  • Taken from same link:
echo "/opt/libjpeg-turbo/lib" > /etc/ld.so.conf.d/libjpeg-turbo.conf && \
echo "/usr/local/lib" > /etc/ld.so.conf.d/ffmpeg.conf && \
echo "LD_LIBRARY_PATH=/usr/local/lib:/opt/libjpeg-turbo/lib:$LD_LIBRARY_PATH" >> /etc/bash.bashrc && \
echo "export LD_LIBRARY_PATH" >> /etc/bash.bashrc
  • I used (just for turbo)
echo "/opt/libjpeg-turbo/lib64" > /etc/ld.so.conf.d/libjpeg-turbo.conf && \
echo "LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib64:$LD_LIBRARY_PATH" >> /etc/bash.bashrc && \
echo "export LD_LIBRARY_PATH" >> /etc/bash.bashrc
ldconfig

Disable Corrupt JPEG Data

zmc_m3[12280]: WAR [Corrupt JPEG data: 1 extraneous bytes before marker 0xd9] 

Another way is just disable writing these messages to log files. If you are using rsyslog (default in debian):

#cat /etc/rsyslog.d/00-zm-foscam.conf
:msg, contains, "WAR [Corrupt JPEG data: 1 extraneous bytes before marker 0xd9]" ~
:msg, contains, "WAR [Corrupt JPEG data: 2 extraneous bytes before marker 0xd9]" ~
#service rsyslog restart

If you are use syslog-ng:

destination df_null { };
filter f_libjpeg { message(“WAR \\[Corrupt JPEG data: .+ extraneous bytes before marker”); };
log {
source(s_src);
filter(f_libjpeg);
destination(df_null);
flags(final);
};

Controlling CPU Usage

The lib turbo jpeg is reccomended but if you are using modetect it is best to lower the framrate. From the Zoneminder FAQ's:

  • Capture frame rates. Unless there's a compelling reason in your case there is often little benefit in running cameras at 25fps when 5-10fps would often get you results just as good. Try changing your monitor settings to limit your cameras to lower frame rates. You can still configure ZM to ignore these limits and capture as fast as possible when motion is detected.

I had a VM cpu at 100 percent with 3 cams. I lowered to 5fps and cpu is at 30 percent.

Notes

CentOS 7 w/ Repo Install

Install

Install CentOS Min

wget http://zmrepo.zoneminder.com/el/7/x86_64/zmrepo-7-4.el7.centos.noarch.rpm
sudo yum install --nogpgcheck zmrepo-7-4.el7.centos.noarch.rpm
sudo yum install zoneminder
less /usr/share/doc/zoneminder-*/README.Centos7
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
mysql -u root -p < /usr/share/zoneminder/db/zm_create.sql
mysql -u root -p
grant select,insert,update,delete,lock tables,alter on zm.* to 'zmuser'@localhost identified by 'zmpass';
exit;
mysqladmin -u root -p reload
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

On Upgrade

1. The Apache ScriptAlias has been changed from "/cgi-bin/zm/zms" to

  "/cgi-bin-zm/zms". This has been to done to avoid this bug:
  https://bugzilla.redhat.com/show_bug.cgi?id=973067
  IMPORTANT: ZoneMinder will not update this value during an upgrade. You must
  manually update ZM_PATH_ZMS yourself under Options. This does not affect
  new installs.

2. Verify /etc/zm/zm.conf.

  If zm.conf was manually edited before running the upgrade, the installation
  may not overwrite it. In this case, it will create the file
  /etc/zm/zm.conf.rpmnew.
  For example, this will happen if you are using database account credentials
  other than zmuser/zmpass.
  Compare /etc/zm/zm.conf to /etc/zm/zm.conf.rpmnew. Verify that zm.conf
  contains any new config settings that may be in zm.conf.rpmnew.

3. Verify permissions of the zmuser account.

  Overtime, the database account permissions required for normal operation
  have changed. Verify the zmuser database account has been granted select,
  insert, update, delete, lock tables, and alter permission to the ZoneMinder
  database:
    mysql -u root -p
        mysql> show grants for zmuser@localhost;
        mysql> exit;

4. Verify the database was upgraded automatically.

  From the web console, ZoneMinder should show a status of "Running", and the
  version number should have incremented.
  If it is not running, then try to start it. The web console will indicate
  if there is a database version conflict. If this is the case, then you may
  need to manually update the database from the command line:
    sudo zmupdate.pl
  Modern versions of ZoneMinder don't require any parameters added to the
  zmupdate command. However, if ZoneMinder complains, you may need to call
  zmupdate in the following manner:
    sudo zmupdate.pl --user=root --pass=<mysql_root_pwd> --version=<from version>

Configuration

nano /etc/zm/zm.conf

Moving Location Of Video Storage

http://www.zoneminder.com/wiki/index.php/Using_a_dedicated_Hard_Drive

On many installs you may wish to dedicate a hard drive or partition for Zoneminder events. There are many reasons why you may want to change the storage location - security, data segregation, preventing encroachment onto OS partition by zoneminder etc.

It's not terribly difficult to do, but may be non-obvious to the untaught so here's a brief guide.

Some commands here are based on Debian/Ubuntu installs

1. Become root or "sudo -s" to gain root privs.

2. Stop Zoneminder. "service zoneminder stop", "/usr/bin/zmpkg.pl stop", or "systemctl stop zoneminder"

3. Mount your new partition onto the root filesystem, ensuring it is automatically remounted at boot time by editing /etc/fstab -- For the benefit of this guide, I'm calling my new partition /newdrive

Note this new partition can be a local drive, raid partition, lvm/md device, external NAS, SAN, NFS share or SMB share. The only condition is that the I/O throughput should be up to handling what Zoneminder will throw at it. For that speed reason, some favour non-journalled filesystems and accept the extra risk of data protection

4. Locate Zoneminder's "events" and "images" directories. In Debian and Ubuntu, these are under /var/cache/zoneminder. In CentOS and Fedora, these are under /var/lib/zoneminder.

If you wish to copy the data across, MOVE the events and images directories to /newdrive (Note this will take a long time on systems with many events). Also, DO NOT restart zoneminder until this entire process is completed. Doing so will cause all your events to be lost!

If you don't wish to preserve the data, it is MUCH faster to simply delete or rename the original events and images dirs and create new directories in /newdrive. There is no need to remove the "orphaned" entries in the database, zmaudit will take care of those.

Eg:

mkdir /newdrive/events

mv /var/lib/zoneminder/events /var/lib/zoneminder/events_old -- or -- rm -rf /var/lib/zoneminder/events

Add these lines in fstab to bind-mount an alternate location:

/dev/sdX1 /otherdrive ext3 defaults 0 2
/otherdrive/zoneminder/images /var/cache/zoneminder/images none defaults,bind  0 2
/otherdrive/zoneminder/events /var/cache/zoneminder/events none defaults,bind 0 2

or in some cases,

/otherdrive/zoneminder/images /var/lib/zoneminder/images none defaults,bind  0 2
/otherdrive/zoneminder/events /var/lib/zoneminder/events none defaults,bind 0 2

or if you have a separate partition for each:

/dev/sdX1 /var/cache/zoneminder/images ext3 defaults 0 2
/dev/sdX2 /var/cache/zoneminder/events ext3 defaults 0 2

(Repeat for images)


5. Ensure ZoneMinder can write to the new destination by changing the owner and group to that of the web server user account. Debian based distros typically use "www-data" as the web server user account while many rpm based distros use "apache".

chown -R apache:apache /otherdrive/zoneminder

6. Finally, restart zoneminder ( "service zoneminder start", "/usr/bin/zmpkg.pl start", or "systemctl start zoneminder") Monitor its operation and ensure new events are being created normally and are viewable. Zoneminder should also update the "Disk: %%" on its Console screen to reflect the disk space on its new partition.

FREQUENTLY ASKED QUESTIONS

Question: Why can't I just symlink the newdrive to the events folder? Answer: Because it does not work in every case. Many rpm and deb packages need the file folders set up exactly the way they were when the first zoneminder package was installed. Changing that around can cause package upgrades to fail, or worse you could lose all your data!

Question: I noticed that there is an events folder under /usr/share/zoneminder/www, can I mount my newdrive to that folder? Answer: This will not work in every case either and should be avoided. The events and images folders under /usr/share/zoneminder/www are actually symbolic links that point to the real folders under /var/lib/zoneminder (or /var/cache/zoneminder). Altering this in any way has the same affect as the answer to the first question.

Notes

You can disable SELINUX if you want.

sudo setenforce 0
  To permanently disable SELinux, edit /etc/selinux/conf and change the
  SELINUX line from "enforcing" to "disabled". This change will take
  effect after a reboot.