ZoneMinder

From Gentoo Wiki
Jump to: navigation, search
Resources

ZoneMinder is open source software used to capture, analyse, record, and monitor cameras.

Installation

Dependencies

Important
The following required packages must be configured properly for ZoneMinder to work.

USE flags

Enable the following USE flags for dev-lang/php, app-eselect/eselect-php, and www-misc/zoneminder:

FILE /etc/portage/package.use
dev-lang/php apache2 cgi curl fpm inifile pdo mysql mysqli sockets
app-eselect/eselect-php apache2 fpm
www-misc/zoneminder curl ffmpeg ssl

Emerge

Install ZoneMinder:

root #emerge --ask www-misc/zoneminder

Configuration

Apache

  • Select correct version of PHP:
root #eselect php list apache2
  [1]   php7.2 *
  • Edit /etc/php/apache2-php7.2/php.ini to reflect the following:
FILE /etc/php/apache2-php7.2/php.ini
date.timezone = <Country/City>
  • Edit /etc/conf.d/apache2 and add -D PHP -D PROXY to APACHE2_OPTS:
FILE /etc/conf.d/apache2
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -D PROXY"
  • There is an example config in /usr/share/doc/zoneminder*/10_zoneminder.conf.bz2:
root #bzcat /usr/share/doc/zoneminder-*/10_zoneminder.conf.bz2 > /etc/apache2/vhosts.d/10_zoneminder.conf
  • Or, create an Apache vhost in /etc/apache2/vhosts.d/10_zoneminder.conf
FILE /etc/apache2/vhosts.d/10_zoneminder.conf
ScriptAlias /zm/cgi-bin/ "/usr/libexec/zoneminder/cgi-bin/"

<Directory "/usr/libexec/zoneminder/cgi-bin">
  AllowOverride All
  Options +ExecCGI
  Require all granted
</Directory>

# Order matters. This alias must come first.
Alias /zm/cache "/var/cache/zoneminder"

<Directory "/var/cache/zoneminder">
  Options -Indexes +MultiViews +FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>

Alias /zm "/usr/share/zoneminder/www"

<Directory "/usr/share/zoneminder/www">
  Options -Indexes +MultiViews +FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

MySQL

  • Create ZoneMinder's database, zm, and setup a new user zmuser.
root #mysql -p
mysql> create database zm;

mysql> grant lock tables,alter,drop,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on zm.* to 'zmuser'@localhost identified by 'zmpass';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
  • Import the database schema and base data, the .sql script is created by the configure phase above, so make sure you do that first.
root #mysql -p zm < /usr/share/zoneminder/db/zm_create.sql

ZoneMinder

  • Edit /etc/zm.conf and add the above MySQL database username and password:
FILE /etc/zm.conf
# ZoneMinder database user
ZM_DB_USER=zmuser

# ZoneMinder database password
ZM_DB_PASS=zmpass
 Options -> Paths -> PATH_ZMS = /zm/cgi-bin/zms

Init

OpenRC

Add Apache to the default runlevel and start the service:

root #rc-update add apache2 default
root #rc-service apache2 start

Add PHP to the default runlevel and start the service:

root #rc-update add php-fpm default
root #rc-service php-fpm start

Add MySQL to the default runlevel and start the service:

root #rc-update add mysql default
root #rc-service mysql start

Add ZoneMinder to the default runlevel and start:

root #rc-update add zoneminder default
root #rc-service zoneminder start

systemd

Enable the Apache to start on system boot and start the service:

root #systemctl enable apache2
root #systemctl start apache2

Enable the PHP service to start on system boot and start the service:

root #systemctl enable php-fpm
root #systemctl start php-fpm

Enable the MySQL service to start on system boot and start the service:

root #systemctl enable mysql
root #systemctl start mysql

Enable the ZoneMinder service to start on system boot and start the service:

root #systemctl enable zoneminder
root #systemctl start zoneminder

SELinux

When using SELinux, first create a SELinux policy for the application:

FILE local_zoneminder.teType enforcement rules for ZoneMinder
module local_zoneminder 1.0; 

require { 
               type httpd_t;
               type initrc_var_run_t;
               type initrc_t;
               type v4l_device_t;
               type file_t;
              class unix_stream_socket { read connectto };
              class file { read lock };
              class shm { unix_read unix_write associate read write getattr };
              class chr_file getattr;
}

#============= httpd_t ============== 
allow httpd_t initrc_t:unix_stream_socket connectto;
allow httpd_t initrc_t:shm { unix_read unix_write associate read write getattr };
allow httpd_t initrc_var_run_t:file { read lock };
allow httpd_t v4l_device_t:chr_file getattr;

Now build the modules:

root #checkmodule -M -m -o local_zoneminder.mod local_zoneminder.te
root #semodule_package -o local_zoneminder.pp -m local_zoneminder.mod
root #semodule -i local_zoneminder.pp

Other

Shared memory:

root #sysctl kernel.shmmax=536870912

Upgrading

ZoneMinder includes a Perl utility zmupdate.pl to update the database schema as needed. Note: a Perl interpreter will required to run the script.

Specify the previous version and database credentials for the zm database:

root #/usr/bin/zmupdate.pl --version=1.30.2 --user=zmuser --pass=zmpass
Initiating database upgrade to version 1.30.4 from version 1.30.2

Please ensure that ZoneMinder is stopped on your system prior to upgrading the database.
Press enter to continue or ctrl-C to stop :

Do you wish to take a backup of your database prior to upgrading?
This may result in a large file in /var/tmp/zm if you have a lot of events.
Press 'y' for a backup or 'n' to continue : y
Creating backup to /var/tmp/zm/zm-1.30.2.dump. This may take several minutes.
Database successfully backed up to /var/tmp/zm/zm-1.30.2.dump, proceeding to upgrade.

Upgrading database to version 1.30.4
Loading config from DB
Saving config to DB
Upgrading DB to 1.30.3 from 1.30.2

Database successfully upgraded to version 1.30.3.
Upgrading DB to 1.30.4 from 1.30.2

Database successfully upgraded to version 1.30.4.

Database upgrade to version 1.30.4 successful.

See also

  • PHP — a general-purpose server-side scripting language to produce dynamic web pages.