The following guidance might be useful in helping to configure ZoneMinder on a Linux server. This recounts how I configured a ZoneMinder on my Linux Web-server detailing what worked for me (after much experimentation and not describing the many blind-alleys, etc, that I encountered along the way). By far the most difficult aspect was actually getting the USB Webcam to function on my Linux server.
The ZoneMinder software is described in: http://www.zoneminder.com/.
Bring the Linux system up-to-date with the necessary software using yum:
# yum -y update # # yum -y install mysql-server # yum -y install mysql-devel # yum -y install php-mysql # yum -y install pcre-devel # yum -y install perl-DateManip # yum -y install perl-libwww-perl # yum -y install perl-Device-SerialPort # yum -y install perl-MIME-Lite # yum -y install perl-Archive-Zip # yum -y install perl-Email-MIME # yum -y install perl-Email-MIME-Modifier # yum -y install perl-MIME-tools # yum -y install kdetv # yum -y install tvtime Build and install Perl libraries # perl -MCPAN -e shell ... and then installed a number of packages Details TBA
# cd /tmp # svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg # mv ffmpeg /usr/local/src/ # cd ffmpeg # ./configure # make # make install # make install-libs
# cd /tmp # wget http://www.zoneminder.com/downloads/ZoneMinder-1.22.3.tar.gz # mv ZoneMinder-1.22.3.tar.gz /usr/local/src/ # cd /usr/local/src/ # tar xvfz ZoneMinder-1.22.3.tar.gz # cd ZoneMinder-1.22.3 # ./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin/ ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER='user' ZM_DB_PASS='pwd' --with-ffmpeg=/usr/local/bin # make # make install # install scripts/zm /etc/init.d/ # # ----- change log file dir from /tmp to /var/log/zm # # NB: If zm can not open and write the log files, it will not start. So: # # chown apache:apache /var/log/zm
# service mysqld restart # service httpd restart # # locate mysql # # mysql mysql < db/zm_create.sql mysql> grant select,insert,update,delete on zm.* to 'user'@localhost identified by 'pwd'; mysql> grant select,insert,update,delete on zm.* to 'user'@% identified by 'pwd'; mysql> quit # NB: The second grant line (supposedly for remote access made no difference - but that was no real surprise, even with WAN access it is still local access from zm to the database). # mysqladmin reload # vi /etc/sysctl.conf > kernel.shmall=134217728 > kernel.shmmax=134217728 :wq # # sysctl -p
Start ZoneMinder and ensure that all the necessary components are set in the Linux configuration to be restarted after a reboot.
# service zm start Starting ZoneMinder: [ OK ] # # # chkconfig --add mysqld # chkconfig --level 345 mysqld on # chkconfig --level 345 httpd on # chkconfig --add zm
The ZoneMinder site lists a patch to the version being installed that is required. This is applied as follows:
Open a command shell Download the patch and move a copy to your ZoneMinder build directory Change directory to your ZoneMinder build directory Apply the patch by typing patch -p0 <Check that the patch is applied correctly and you do not get any rejects If necessary rebuild, then reinstall Need: http://www.zoneminder.com/downloads/zm-1.22.3-monpreset.patch # ----- And do it: # patch -p0 < zm-1.22.3-monpreset.patch patching file web/zm_html_view_monitor.php # # service zm stop # # make # make install # # service zm start
By using the following commands and log files the reason why things are not working as expected(!) can be investigated. Details as shown in the following sub-sections.
These need to be carried out otherwise, with incorrect shared memory provision, the images displayed by ZoneMinder can be impaired, as I found with first attemps to show 3 or 4 monitor images of 640x480 size.
The calculation, which can be found on the http://www.zoneminder.com/forums/ FAQ/documentation pages, is shown below.
ring buffer size x image width x image height x 3 (for 24 bit images) + a bit spare (where ring buffer size has a default value of 100 bytes) Thus: 100 * 640 * 480 * 3 = 92160000 bytes = 90000 kBytes = ca. 88MBytes 100 * 320 * 240 * 3 = 23040000 bytes = 22500 kBytes = ca. 22MBytes
Based on this a shared memory size of 132Mbytes for 640x480 images was suggested in documentation and used (as earlier on this web-page).
The current configuration is supporting 3 x (320 * 240) images. But 2 x (320 * 240) + x 1 (640 * 480) images was found to result in the failure to display one of the images (blank screen for the (640 * 480) image. So the shared memory size of 132Mbytes is just on the cusp of what that amount of shared memory supports. TBI: effect of increasing the shared memory size from 134217728 to 256000000.
This is aided by using the following Zoneminder log files:
# pwd /var/log/zm # # ls -l total 11860 -rw-r--r-- 1 apache apache 333402 Jan 22 14:22 zmaudit.log -rw-r--r-- 1 apache apache 5565098 Jan 22 14:24 zmdc.log srwxr-xr-x 1 apache apache 0 Jan 20 00:07 zmdc.sock -rw-r--r-- 1 apache apache 0 Jan 18 23:21 zmfilter.log -rw-r--r-- 1 apache apache 1349 Jan 20 00:07 zmpkg.log -rw-r--r-- 1 apache apache 552 Jan 22 03:07 zmupdate.log -rw-r--r-- 1 apache apache 6202860 Jan 22 14:24 zmwatch.log # # tail -f zmwatch.log ... 01/22/2007 14:24:36.443023 zmwatch[7648].INF ['zmc -d /dev/video0' starting at 07/01/22 14:24:36, pid = 29191] 01/22/2007 14:24:46.449101 zmwatch[7648].INF [Restarting capture daemon for Labtec_1, shared memory not valid] 01/22/2007 14:24:46.958849 zmwatch[7648].INF ['zmc -d /dev/video0' starting at 07/01/22 14:24:46, pid = 29196] 01/22/2007 14:24:56.965838 zmwatch[7648].INF [Restarting capture daemon for Labtec_1, shared memory not valid] # tail -f zmupdate.log ... 01/22/2007 03:07:22.807711 zmupdate[7654].INF [Checking for updates] 01/22/2007 03:07:22.910612 zmupdate[7654].INF [Got version: '1.22.3'] # tail zmpkg.log ... 01/19/2007 19:55:16.258262 zmpkg[6788].ERR [Unable to run "sudo -u apache /usr/local/bin/zmdc.pl start zmc -d /dev/video < ? >", output is ""] 01/19/2007 19:56:46.733222 zmpkg[7330].INF [Command: stop] 01/19/2007 19:57:00.001454 zmpkg[7430].INF [Command: start] 01/19/07 22:58:00.540953 zmpkg[5079].INF [Command: start] 01/20/2007 00:06:50.583907 zmpkg[7537].INF [Command: stop] 01/20/2007 00:07:02.924381 zmpkg[7578].INF [Command: start] # tail -f zmaudit.log ... 01/22/2007 14:22:24.713678 zmaudit[7639].DBG [Found filesystem monitor '2'] 01/22/2007 14:22:24.713989 zmaudit[7639].DBG [Got 0 events] 01/22/2007 14:22:24.714119 zmaudit[7639].DBG [Found filesystem monitor '3'] 01/22/2007 14:22:24.714376 zmaudit[7639].DBG [Got 0 events] 01/22/2007 14:22:24.714504 zmaudit[7639].DBG [Found filesystem monitor '4'] 01/22/2007 14:22:24.714725 zmaudit[7639].DBG [Got 0 events] 01/22/2007 14:22:24.714850 zmaudit[7639].DBG [Found filesystem monitor '5'] 01/22/2007 14:22:24.715065 zmaudit[7639].DBG [Got 0 events] # tail -f zmdc.log 01/22/2007 14:24:57.413358 zmdc[7592].INF ['zmc -d /dev/video0' starting at 07/01/22 14:24:57, pid = 29200] 01/22/2007 14:24:57.462705 zmdc[7592].ERR ['zmc -d /dev/video0' exited abnormally, exit status 255] 01/22/2007 14:25:07.920078 zmdc[7592].INF ['zmc -d /dev/video0' starting at 07/01/22 14:25:07, pid = 29214] 01/22/2007 14:25:07.967951 zmdc[7592].ERR ['zmc -d /dev/video0' exited abnormally, exit status 255] 01/22/2007 14:25:18.444852 zmdc[7592].INF ['zmc -d /dev/video0' starting at 07/01/22 14:25:18, pid = 29219] 01/22/2007 14:25:18.492797 zmdc[7592].ERR ['zmc -d /dev/video0' exited abnormally, exit status 255] 01/22/2007 14:25:28.957421 zmdc[7592].INF ['zmc -d /dev/video0' starting at 07/01/22 14:25:28, pid = 29223] ... #
It is useful to use:
# tail -f /var/log/messages /var/log/httpd/error_log /var/log/zm/zm*.log
Investigate memory allocation problems, e.g.:
# ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 1081344 username 600 393216 2 dest 0x00000000 1114113 username 600 393216 2 dest 0x00000000 1146882 username 600 393216 2 dest 0x00000000 1179651 username 600 393216 2 dest 0x00000000 1212420 username 600 393216 2 dest 0x00000000 1245189 username 600 393216 2 dest 0x00000000 1277958 username 600 393216 2 dest 0x00000000 1310727 username 600 393216 2 dest 0x00000000 1343496 username 600 393216 2 dest 0x00000000 1376265 username 600 393216 2 dest 0x00000000 1409034 username 600 393216 2 dest 0x00000000 1441803 username 600 393216 2 dest 0x00000000 1474572 username 600 393216 2 dest 0x00000000 1507341 username 600 393216 2 dest 0x00000000 1540110 username 600 393216 2 dest 0x00000000 1572879 username 600 393216 2 dest 0x00000000 1605648 username 600 393216 2 dest 0x7a6d2004 1736721 apache 700 9217188 1 0x7a6d2003 1769490 apache 700 36865188 1 0x7a6d2002 1802259 root 700 36865188 0 0x00000000 884758 username 600 393216 1 dest 0x00000000 917527 username 600 393216 1 dest # service zm stop Stopping ZoneMinder: [ OK ] # # ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 1081344 username 600 393216 2 dest 0x00000000 1114113 username 600 393216 2 dest 0x00000000 1146882 username 600 393216 2 dest 0x00000000 1179651 username 600 393216 2 dest 0x00000000 1212420 username 600 393216 2 dest 0x00000000 1245189 username 600 393216 2 dest 0x00000000 1277958 username 600 393216 2 dest 0x00000000 1310727 username 600 393216 2 dest 0x00000000 1343496 username 600 393216 2 dest 0x00000000 1376265 username 600 393216 2 dest 0x00000000 1409034 username 600 393216 2 dest 0x00000000 1441803 username 600 393216 2 dest 0x00000000 1474572 username 600 393216 2 dest 0x00000000 1507341 username 600 393216 2 dest 0x00000000 1540110 username 600 393216 2 dest 0x00000000 1572879 username 600 393216 2 dest 0x00000000 1605648 username 600 393216 2 dest 0x00000000 884758 username 600 393216 1 dest 0x00000000 917527 username 600 393216 1 dest # # service zm start Starting ZoneMinder: [ OK ] # ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 1081344 username 600 393216 2 dest 0x00000000 1114113 username 600 393216 2 dest 0x00000000 1146882 username 600 393216 2 dest 0x00000000 1179651 username 600 393216 2 dest 0x00000000 1212420 username 600 393216 2 dest 0x00000000 1245189 username 600 393216 2 dest 0x00000000 1277958 username 600 393216 2 dest 0x00000000 1310727 username 600 393216 2 dest 0x00000000 1343496 username 600 393216 2 dest 0x00000000 1376265 username 600 393216 2 dest 0x00000000 1409034 username 600 393216 2 dest 0x00000000 1441803 username 600 393216 2 dest 0x00000000 1474572 username 600 393216 2 dest 0x00000000 1507341 username 600 393216 2 dest 0x00000000 1540110 username 600 393216 2 dest 0x00000000 1572879 username 600 393216 2 dest 0x00000000 1605648 username 600 393216 2 dest 0x7a6d2004 1835025 apache 700 9217188 1 0x7a6d2003 1867794 apache 700 36865188 1 0x00000000 884758 username 600 393216 1 dest 0x00000000 917527 username 600 393216 1 dest #
Available from the http://www.zoneminder.com/forums/ the following summary is a very useful crib sheet:
1. Disable selinux (/etc/selinux/config) 2. Set up file database (/etc/updatedb.conf) 3. Install mysql etc (up2date –install mysql-server etc) 4. Set up mysql to auto-start (chkconfig --add mysqld; chkconfig --level 345 mysqld on; service mysqld start) 5. Install libpcre etc (up2date --install pcre-devel) 6. Install subversion (up2date --showall | grep svn) 7. Fetch ffmpeg (svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg) 8. Build ffmpeg (cd ffmpeg; ./configure; make ) 9. Install ffmpeg (make install; make install-libs; make install-headers) 10. Install perl modules (perl –MCPAN –eshell; install Archive::Tar Archive::Zip; install MIME::Lite MIME::Entity) 11. Fetch ZM (wget 'http://www.zoneminder.com/downloads/ZoneMinder-1.22.2.tar.gz') 12. Configure ZM (./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin --with-libarch=lib64 ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=ZM_DB_PASS= CFLAGS="-g -O3 -march=athlon64" CXXFLAGS="-g -O3 -march=athlon64") 13. Patch ZM (wget 'http://www.zoneminder.com/downloads/zm-1.22.2-ffmpeg.patch'; wget 'http://www.zoneminder.com/downloads/zm-1.22.2-userlang2.patch'; wget 'http://www.zoneminder.com/downloads/zm-1.22.2-filter.patch') 14. Build ZM (make) 15. Install ZM (make install) 16. Create zm database (mysql < db/zm_create.sql) 17. Create zm user (grant all on zm.* to ' '@'localhost' identified by ' ';) 18. Start up httpd (chkconfig --level 345 httpd on; service httpd start) 19. Set up ZM to auto-run (install scripts/zm /etc/init.d/; chkconfig --add zm) 20. Start ZM
The firewall/port-blocking configuration may also need to be addressed, if ZoneMinder needs to be accessed from the WAN/Internet. I opted to make ZoneMinder available from a specific port and configured Apache accordingly opening that port on the router.
Consult your hardware router or software routing documentation for details.
The following general links are useful references when setting up ZoneMinder to run on a Linux server:
URL | Summary/Description |
---|---|
http://www.zoneminder.com/ | General ZoneMinder site |
http://www.zoneminder.com/forums/ | ZoneMinder forums ... |
http://www.zoneminder.com/forums/viewtopic.php?t=5393&view=next&sid=f5db6dc233bdae2020f387835e39672b | Difficulties with the Linksys WVC54G Wireless IP Camera |
http://www.howtoforge.com/video_surveillance_zoneminder_ubuntu | ZoneMinder on Ubuntu |