This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

ZoneMinder

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
Resources

ZoneMinder Capture, analyse, record and monitor any cameras attached to your system.

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

All ZoneMinder builds are currently masked and need to be unmasked:

FILE /etc/portage/package.accept_keywords
www-misc/zoneminder ~amd64


Install ZoneMinder:

root #emerge --ask www-misc/zoneminder

Configuration

Apache

  • Select correct version of PHP:
root #eselect php list apache2
  [1]   php7.0 *
  • Edit /etc/php/apache2-php7.0/php.ini to reflect the following:
FILE /etc/php/apache2-php7.0/php.ini
short_open_tag = On
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"
  • 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>

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 select,insert,update,alter,lock tables,delete 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:

root #rc-update add apache2 default
root #/etc/init.d/apache2 start

Add PHP to the default runlevel and start:

root #rc-update add php-fpm default
root #/etc/init.d/php-fpm start

Add MySQL to the default runlevel and start:

root #rc-update add mysql default
root #/etc/init.d/mysql start

Add ZoneMinder to the default runlevel and start:

root #rc-update add zoneminder default
root #/etc/init.d/zoneminder start

systemd

Add Apache to startup and start:

root #systemctl start apache2
root #systemctl enable apache2

Add PHP to startup and start:

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

Add MySQL to startup and start:

root #systemctl start mysql
root #systemctl enable mysql

Add ZoneMinder to startup and start:

root #systemctl start zoneminder
root #systemctl enable 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 utility zmupdate.pl to update the database schema as needed.

Specify your 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.