Видеорегистратор на Zoneminder и FreeBSD 8.0

Zoneminder довольно охоч до ресурсов и является очень сырым и неоптимизированным продуктом.
Для обслуживания одной HD-камер (например Arecont 2110 или 3110) ынужно одно ядро с частотой 3GHz.
А мой мини-моноблок с процессором C7 полностью загружается даже от средней камеры Axis 206.

Итак, приступим к установке. Перед установкой необходимо обновить все порты до текущих версий.

Ставим perl с опциями по умолчанию:
/usr/ports/lang/perl5
make
make install

Ставим mysql с опциями по умолчанию:
/usr/ports/databases/mysql55-server
make
make install

Ставим модули DBI и DBD-mysql:
/usr/ports/databases/p5-DBI
make
make install

/usr/ports/databases/p5-DBD-mysql55:
make
make install

Ставим apache2 с опциями:
/usr/ports/www/apache22
make

AUTH_BASIC
AUTH_DIGEST
AUTHN_FILE
AUTHN_DBM
AUTHN_ANON
AUTHN_DEFAULT
AUTHN_ALIAS
AUTHZ_HOST
AUTHZ_GROUPFILE
AUTHZ_USER
AUTHZ_DBM
AUTHZ_OWNER
AUTHZ_DEFAULT
CACHE
DISK_CACHE
FILE_CACHE
DAV
DAV_FS
ACTIONS
ALIAS
ASIS
AUTOINDEX
CERN_META
CGI
CHARSET_LITE
DEFLATE
DIR
DUMPIO
ENV
EXPIRES
HEADERS
IMAGEMAP
INCLUDE
INFO
LOG_CONFIG
LOGIO
MIME
MIME_MAGIC
NEGOTIATION
REWRITE
SETENVIF
SPELING
STATUS
UNIQUE_ID
USERDIR
USERTRACK
VHOST_ALIAS
FILTER
VERSION
SSL

make install

Код zoneminder написан под функции php-5.2.х, по этому не следует ставить более свежие ветки.
В противном случае придется самостоятельно лазить в php коде и править фоункции на их более новые аналоги.
/usr/ports/lang/php52
make

CLI
CGI
APACHE
SUHOSIN
FASTCGI
PATHINFO

make install

Ставим модули расширения для php:
/usr/ports/lang/php52-extensions
make

CTYPE
DOM
FILTER
HASH
ICONV
JSON
MCRYPT
MHASH
MYSQL
PDO
PDO_SQLITE
POSIX
SESSION
SIMPLEXML
SPL
SQLITE
TOKENIZER
XML
XMLREADER
XMLWRITER
ZIP

make install

Ставим сам zoneminder, для этого качаем порт отсюда:
fetch http://white-raven.pisem.net/zoneminder/zoneminder-1.24.2_2-freebsd-8.0.tar.gz

Распаковываем порт, кладем в /usr/ports/multimedia/zoneminder
make
make install

Если не собирается jpeg-7, но обычно он собирается если порты обновлены и устанавливается zoneminder версии 1.24.2
нужна библиотека libjpeg.so.9 делаем на нее симлинк с более новой libjpeg.so.10
ln -s /usr/local/lib/libjpeg.so.10 /usr/local/lib/libjpeg.so.9

При установке по зависимости порта ffmpeg выбираем эти параметры:

OPENJPEG
THEORA
VORBIS
X264

Этот пакет будет задействован при любых обработках видеофайлов, конвертировании, экспорта и т.д.
остальные порты из зависимостей собираем по умолчанию.

В /etc/rc.conf добавляем:
apache22_enable="YES"
mysql_enable="YES"
zm_enable="YES"

запускаем mysql и создаем базу данных для работы zoneminder.
Честно говоря база там практически не нужна, так как функционал ее не задействован на полную, планируемую мощность:
mysql -h localhost -u root -p
mysql> source /usr/ports/multimedia/zoneminder/work/ZoneMinder-1.24.2/db/zm_create.sql;
mysql> grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass'; flush privileges;
mysql> quit

Согласно рекомендациям самого zoneminder, добавим в /etc/sysctl.conf строки:
kern.ipc.shm_use_phys=1
kern.ipc.shmmax=536870912
kern.ipc.shmall=524288
kern.ipc.shm_allow_removed=1

а в /boot/loader.conf добавляем строку:
kern.ipc.shmmni=512

Для того, чтобы работала система экспорта видео, нужно добавить один java-модуль:
fetch http://www.charliemouse.com:8080/code/cambozola/cambozola-latest.tar.gz
копируем файл /cambozola-0.70/dist/cambozola.jar в /usr/local/www/apache22/data/zm/

В /usr/local/etc/apache22/httpd.conf добавляем

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DocumentRoot /usr/local/www/apache22/data/zm
DirectoryIndex index.php

Еще у меня freebsd собралась без переменной %%RC_SUBR%% которую требует стартстопный скрипт zoneminder.
По этому можно или добавить переменную или заменить ее в конфиге на абсолютный путь /etc/rc.subr

Перегружаем машину, заходим на нее браузером и наслаждаемся работой регистратора.
Далее добавляем камеры, настраиваем режимы их работы, зоны детекторов движения и т.д...

При работе с zoneminder пользовался материалами:

http://www.lissyara.su/articles/freebsd/programms/zoneminder/

http://www.zoneminder.com/

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

== Origin ==

This port project started its life based on quadra's original port for
version 1.19.2. Brooktree (bktr) video input support code written by
quadra is virtually unchanged in this port other than some function
argument changes to match the latest ZoneMinder version (1.22.3).
Although this code compiles, I have not tested its functionality.
Currently, I only have two Axis 206 network cameras, which work fine,
but I have not tested the set up with any other camera
configurations.

I have tested this port on FreeBSD 5.5 (i386) as well as FreeBSD 6.2
(i386) without any problems.

== Preparation ==

* Download the port (zoneminder-freebsd-port-1.22.3p[version].tgz)
* Become root and 'cd' to /usr/ports/multimedia/
* Extract the port files. You know how to do 'tar zxf' right?

You should now have /usr/ports/multimedia/zoneminder/

Now, go to the directory and look at files/patch-SharedMem.pm

What this patch does is to hard-wire native size to 4 (32-bits).
On FreeBSD, Perl is configured with -Duse64bitint by default and the
method that is used by SharedMem.pm to determine architectural bit
width incorrectly considers an i386 machine as 64-bit capable. I'm
not a perl expert -- in fact, I hate perl -- and I really have no
idea how to properly determine pointer size in Perl, so this patch
exists. Obviously, if you are running FreeBSD-AMD64 (or Alpha or
something, although I have no idea if this software would work on
that architecture), you will want to get rid of this patch file.
Just delete it _before_ you make.

And if you're bored, feel free to go through all the patch files just
marvelling at all the trouble I had to go through ^_^;

Now that we've gotten that little quirk out of the way, we'll move on
to Makefile. Open Makefile using your favorite text editor and modify
the following items if they're not suitable for you.

* WEBBASE : This is where your web server will serve from. If you
already have apache installed, you should point this to the same
place where apache thinks is the web base. Default is
/usr/local/www, as can be seen in the Makefile.
* ZM_DB_HOST : This is where mysql server runs. If you're running
mysql server on a different machine, you'll want to update this
line, but I'm not sure if you can avoid installing mysql on this
machine. Disk space is cheap, so I don't think it's that big a deal
having mysql just sitting there, as long as it's not started.
* ZM_DB_NAME : This is the database name that ZoneMinder will use.
I'm pretty sure ZoneMinder won't mind sharing a base database with
other applications, but it certainly doesn't hurt to let it have its
own database space, so this defaults to "zm"
* ZM_DB_USER and ZM_DB_PASS are username and password for the
database.

We're almost ready to "make," but first, consider the following points
and just imagine how things can break based on your situation.

* If you do not have apache installed, this port will install version
1.xx.xx of apache. On the other hand, if you already have apache
2.xx.xx installed, I do not know what will happen. My guess is that
things will work just fine since php5 port will see apache2
installation and skip apache1 installation.
* If you have mysql version other than 5.0.xx installed, this port
build will probably fail. Even if it doesn't fail, you probably do
not want multiple versions of mysql installed on your machine. You
can either edit the dependency in the Makefile to point to your
version of mysql, or get rid of the dependency statement for mysql.
Getting rid of it is not as nice, but I'm sure you're able to keep
the dependencies in mind when messing around with ports in the
future.
* If you have PHP4 installed, you should modify the dependencies in
the Makefile to point to php4-extensions instead of
php5-extensions. I know for a fact that both versions work fine
with ZoneMinder.
* I have not set up dependencies for perl modules Device::SerialPort
and X10::ActiveHome because I do not have PTZ camera and my X10 is
handled by another dedicated machine. If you want this, you'll want
to tinker with the port some more. You can also manually install
those ports (if they exist) before doing make. I imagine
ZoneMinder's configure script will pick them up.

That's about it. Let's make!

== Making ==

There's really nothing special about making. Just 'make' will do.
However, during the dependency builds, make sure PHP install includes
the apache module. If you already have PHP installed without apache
module, you can always tinker with the Makefile in
/usr/ports/lang/php5/ and do 'make deinstall' followed by 'make
reinstall' to reinstall the port with additional modules.

If the build fails, take a deep breath, yell at your computer for
a moment, and try to figure out if you messed up anything while
changing the Makefile in one of the above steps. If you do not
believe you've done anything wrong and still can't figure out why
the build fails, there's always the forum....

If it builds fine, feel free to 'make install'

However, do NOT 'make clean' yet!

== Seeding the database ==

If this is the first time installing ZoneMinder, you'll need to seed
the mysql database with ZoneMinder's configuration information. To do
this, follow these steps as a root user.

First, if this is the first time mysql was installed, you'll want to
consider where you want the database files to reside. Default is
/var/db/mysql/ but you may have set up a dedicated partition for it.
If you want to change it, just put the following line in /etc/rc.conf

* mysql_dbdir="/somewhere/else/you/want"

Obviously, you'll want this line in there, too:

* mysql_enable="YES"

Now, start the sucker up.

shell> /usr/local/etc/rc.d/mysql-server start

Assuming it started fine, give it a few seconds and then continue.
Note that you should be at /usr/ports/multimedia/zoneminder/ for the
following steps.

shell> mysql -h localhost -u root -p

This will ask for a password. Just press enter to go with an empty
password. You should now be in mysql command line interface.

mysql> source work/ZoneMinder-1.22.3/db/zm_create.sql

Above runs bunch of SQL commands from the file, seeding the
database.

mysql> grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass'; flush privileges;

Above sets up permissions. Note that if you changed database name,
user name, or password in the Makefile, you'll need to modify above
command accordingly.

mysql> quit

That one should be obvious to you.

== Post-Installation Quirks ==

PHP5 installation does not necessarily set up the apache configuration
file properly. You will want to make sure that following lines are in
apache configuration file, /usr/local/etc/apache/httpd.conf

* AddType application/x-httpd-php .php
* AddType application/x-httpd-php-source .phps

While you're at it, you might also want to check that following line
is in the configuration file.

* LoadModule php5_module libexec/apache/libphp5.so

== Automatic Execution at Boot ==

Obviously, if this is to be used as a security device, you'll want it
to start automatically on a reboot. Again obviously, you need to have
both apache and mysql start up as well, unless of course, you're
running mysql on a remote machine. If you are, I'm sure you're an
expert at this stuff already.

Add following lines into /etc/rc.conf, if not already present. Order
is not important.

* apache_enable="YES"
* mysql_enable="YES"
* zm_enable="YES"

Just for your information, I had to put 'sleep 10' in ZoneMinder
startup script because mysql port does not become available
immediately after mysql startup script finishes.

== More Quirks ==

Depending on the number of cameras and their resolution settings, you
may need a lot more shared memory than provided by a default kernel.
If you've never built a custom kernel before, umm, time for you to
read the FreeBSD Handbook. It can be found at
/usr/share/doc/handbook/index.html or at http://www.freebsd.org/

Adding the following line into /etc/sysctl.conf may speed up the
shared memory accesses, so even though it's not required, it's
probably a good idea.

* kern.ipc.shm_use_phys=1
* kern.ipc.shmmax=536870912
* kern.ipc.shmall=524288
* kern.ipc.shm_allow_removed=1

and into /boot/loader.conf
* kern.ipc.shmmni=512

That's all folks!
===> Installing rc.d startup script(s)
===> Registering installation for zoneminder-1.24.2,2
===> SECURITY REPORT:
This port has installed the following binaries which execute with
increased privileges.
/usr/local/bin/zmfix

This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/zmu
/usr/local/bin/zma
/usr/local/bin/zmc
/usr/local/bin/zmf
/usr/local/www/apache22/cgi-bin/zms

This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/zm

If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.

For more information, and contact details about the security
status of this software, see the following webpage:

http://www.zoneminder.com

Поделиться

Опубликовать в Facebook
Опубликовать в LiveJournal

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

*

Можно использовать следующие HTML-теги и атрибуты: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>