CentOS

From ZoneMinder Wiki
Jump to navigationJump to search

The intent of this walk through is to install a very base/bare bones installation of CentOS that will only run ZoneMinder. This would be for a dedicated ZoneMinder server with no GUI or any unnecessary services running. The reason for the very light-weight installation is so that the majority of system resources are available to ZoneMinder and not having to power the OS. With this installation, memory is reduced to around 140-160MB, and CPU usage is practically nonexistent. CentOS is very easy to install the base installation and doesn’t take too much time as long as you have some type of broadband connection. There are many ways to install CentOS, but this will only cover two because they are related.

All CLI operations/commands in this How-To are done as root in the user root's directory. The reasoning is that this system would be in a secure environment to begin with. However, if you need to add a user to run these services to better secure the system then you can, but keep in mind that some items must be ran as root.

CentOS 5.6 & ZoneMinder 1.25.0

This guide is for CentOS v5.6 with ZoneMinder v1.25.0 which are the newest released versions as of this update (9/3/2009). If you are attempting to install newer versions of either using this guide you will have to adjust file and directory names below. Obviously at at the time of this update released versions newer than these have not been tested together.

Step One - Get CentOS

You can download the “.iso” file(s) for CentOS from http://www.centos.org/
Alternatively download the net-install version of CentOS which is basically just the first CD. Here is one location to download the net-install version:
Download i386: http://mirror.chpc.utah.edu/pub/centos/5.6/isos/i386/CentOS-5.6-i386-netinstall.iso
Download 64 bit: http://centos.cs.wisc.edu/pub/mirrors/linux/centos/5.6/isos/x86_64/CentOS-5.6-x86_64-netinstall.iso
Mirrors List: http://www.centos.org/mirrors/

Step Two - Installation Source

Regardless of which method you use the next few steps are the same.
Begin by booting your system up with either cd/dvd.
Choose the options that best fit your environment until you reach the “Installation Method”.

Centosnetinstal-http.png

Choose HTTP ONLY if you are using the net-install method. Otherwise, you probably want to choose Local CDROM.

If you are using the net-install method then enter:
Website Name: mirror.centos.org
CentOS Directory: (for i386) /centos/5.6/os/i386
CentOS Directory: (for 64 bit) /centos/5.6/os/x86_64

Step Three - Installation Packages

The first screen you want to un-check "Desktop - Gnome" and then check "Server" (not Server-GUI)
Then Make sure that you have "Customize now" selected at the bottom (do not check "Packages from CentOS Extras")

Centosinstall-packages1.png

Then click "Next" to continue on

Once presented with the custom package selection you need to un-check/check the following:

Applications = Check only "Editors" and "Text Based Internet"
Development = Check only "Development Libraries" and "Development Tools"
Servers = Un-check everything
Base System = Check only "Base" (you can check Administration Tools and System Tools if you need them, but they are not necessary)

Centosinstall-packages2.png

Now let the system finish installing

Centosisntall-end.png

Step Four - Configuration

After the first reboot the setup screen should appear. If not then log into the system and type "setup"

Centosinstall-setup1.png

Go into the "Firewall Configuration" disable the Security Level, and Disable SELinux

Centosinstall-setup2.png

Next we are going to disable a number of system services. Go back to the setup screen and go into "System Services"
Un-Check:

apmd
bluetooth
cups
hidd
ip6tables
iptables
netfs
nfslock
pcscd
portmap

After disabling the services then select "Disable Now and On Boot", then exit the setup tool, and log into the system if you haven't already.

  • Screen is a simple program that allows you to run commands from a "Hosted" command line interface. This helps if you loose your connection to the server for any reason in that it allows you to resume (screen -r) right where you left off. Often times I will start a large update/upgrade, leave it for the day, then come back and see where it is at later. Screen allows you to do that without having to be always connected.
  • Install Screen
yum install screen
  • To start a screen session just type
screen
  • If you get disconnected and need to resume your session of screen simply type
screen -r

Step Five - Installing ZoneMinder 1.25.0

First we need to download files and prepare the system

  • Add the RPM Forge repository to CentOS. This will allow the installation of a number of services/applications later on without having to manually install them.
# For i386 CentOS 5.x run:
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

# For 64 bit CentOS 5.x run:
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
  • Download the needed files ZoneMinder 1.25.0 and the Cambozola addon
wget http://www2.zoneminder.com/downloads/ZoneMinder-1.25.0.tar.gz
wget http://www.zoneminder.com/sites/zoneminder.com/downloads/cambozola.jar
  • Now let's install all the services and programs that will be needed (If you encounter any dependency errors using yum, try running yum clean all and then re-try the install command(s).)
  • tip: Copy/paste two lines at a time
yum -y install mysql mysql-server mysql-devel php php-gd php-mysql httpd gcc \
pcre-devel gd mod_ssl glib2-devel gcc-c++ ntp gnutls-devel ImageMagick

yum -y install libjpeg-devel perl-Archive-Tar perl-MIME-Lite perl-MIME-tools \
perl-Date-Manip perl-LWP-UserAgent-Determined

yum -y install perl-PHP-Serialization perl-Device-SerialPort perl-Archive-Zip perl-Sys-Mmap \
perl-Module-Load subversion git yasm
  • Now let's update everything within the new CentOS install
yum -y update
  • At this point it might be useful to reboot your system. Oddly, sometimes things don't work right unless you reboot after all the updates
reboot   -or-   shutdown -r now
  • After reboot log back into your system

Install ffmpeg

  • Now we need to make sure we use the lasted "tested" version of "ffmpeg". This is the latest version of ffmpeg that the ZoneMinder developers have tested with. Download, compile and install ffmpeg:
git clone git://git.videolan.org/ffmpeg.git
cd ffmpeg
./configure --enable-gpl --enable-shared --enable-pthreads
make 
  • The following commands must be done as root
make install 
make install-libs

cd /lib && ln -s /usr/local/lib/libswscale.so.0 && \
ln -s /usr/local/lib/libavformat.so.52 && \
ln -s /usr/local/lib/libavcodec.so.52 && \
ln -s /usr/local/lib/libavutil.so.50 && \
ln -s /usr/local/lib/libavdevice.so.52 && \
ln -s /usr/local/lib/libavdevice.so.53 && \
ln -s /usr/local/lib/libavfilter.so.2 && \
ln -s /usr/local/lib/libavformat.so.53 && \
ln -s /usr/local/lib/libavcodec.so.53 && \
ln -s /usr/local/lib/libpostproc.so.51 && \
ln -s /usr/local/lib/libswscale.so.2 && \
ln -s /usr/local/lib/libavutil.so.51

ldconfig

  • Next, run 'ffmpeg' from the command line and make sure you do not get any errors:
ffmpeg
  • If 'ffmpeg' runs correctly, you will see something like this:
ffmpeg version N-32260-gaebb56e, Copyright (c) 2000-2011 the FFmpeg developers
  built on Aug 31 2011 21:41:49 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
  configuration: --enable-shared --enable-swscale --enable-gpl --enable-pthreads
  libavutil    51. 14. 0 / 51. 14. 0
  libavcodec   53. 12. 0 / 53. 12. 0
  libavformat  53. 10. 0 / 53. 10. 0
  libavdevice  53.  3. 0 / 53.  3. 0
  libavfilter   2. 37. 0 /  2. 37. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Enable services

  • Turn everything on. These commands must be run as root.
 chkconfig httpd on 
 chkconfig mysqld on 
 chkconfig ntpd on 
 service httpd start 
 service mysqld start 
 service ntpd start

Install Zoneminder

  • Next we need to extract the contents of the ZoneMinder "tar" file, and then jump into its directory
 cd /root/  # Or your work directory for this installation
 tar -zxvf ZoneMinder-1.25.0.tar.gz
 cd ZoneMinder-1.25.0
  • Now we are going to configure ZoneMinder with some added statements. What is listed are default CentOS directory placements.
./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin

Note that it seems for Zoneminder to build with newer versions of ffmpeg (certainly 0.6.3) you also need to append the CPPFLAGS="-D__STDC_CONSTANT_MACROS" to the end of the ./configure line thus:

./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin --with-ffmpeg=/usr/local/share/ffmpeg CPPFLAGS="-D__STDC_CONSTANT_MACROS"

There is a section in the FAQ "When running configure I am getting a lot of messages about not being able to compile the ffmpeg libraries" about this [[1]].

Worth mentioning here also is the section in the FAQ under the heading "My load is too high, how can I reduce it?" [[2]]. This details how one can possibly reduce CPU load by half by changing the system's jpeg libraries & building Zoneminder with processor specific instructions.

By default ZM_DB_HOST=localhost, ZM_DB_NAME=zm, ZM_DB_USER=zmuser, and ZM_DB_PASS=zmpass.

  • Change "zmuser" (if you want) with the user that you will use within MySQL to access the ZoneMinder database
  • Change "zmpass" with the password you will be using with the "zmuser" account

So if you wish to change it then use a command like:

./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin --with-webuser=apache --with-webgroup=apache ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=zmuser ZM_DB_PASS=zmpass
  • if you get the configure "error zm requires libmysqlclient.a" with 64 bit CentOS add the following to the end of your configure statement
 --with-extralibs="-L/usr/lib64 -L/usr/lib64/mysql"

e.g. For CentOS 5.6 64-bit. The whole command must be executed on one line. Make sure to change the zmpass to a password that matches your installation.

./configure --with-webdir=/var/www/html/zm --with-cgidir=/var/www/cgi-bin --with-webuser=apache --with-webgroup=apache ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=zmuser ZM_DB_PASS=zmpass --with-extralibs="-L/usr/lib64 -L/usr/lib64/mysql" CXXFLAGS="-D__STDC_CONSTANT_MACROS"
  • Run make and make install after running the configuration steps above.
make
# Run next command as root
make install

Configure MySQL

  • Need to add a password for the root user of MySQL
  • Create the zm database
  • Create the zm database user with permissions and password
mysql
mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_root_password');

>Query OK, 0 rows affected (0.00 sec)

mysql> create database zm;

>Query OK, 1 row affected (0.01 sec)

mysql> grant CREATE, INSERT, SELECT, DELETE, UPDATE on zm.* to your_zm_user@localhost;

>Query OK, 0 rows affected (0.02 sec)

mysql> SET PASSWORD FOR your_zm_user@localhost=PASSWORD('your_zm_password_from_above');

>Query OK, 0 rows affected (0.25 sec)

mysql> exit

>Bye

  • Import the tables into the zm database
cd /root/ZoneMinder-1.24.2 
mysql -u root -p zm < db/zm_create.sql

Finalize Installation of ZoneMinder

All remaining CLI commands need to be run as root.

  • Make it so that ZoneMinder will startup automatically when the system is rebooted
# from the ZoneMinder-1.24.2 source directory
cp scripts/zm /etc/init.d/
chmod +x /etc/init.d/zm
chkconfig zm on
  • Add the Cambozola Java web interface
cp cambozola.jar /var/www/html/zm/
  • and make sure you have permission to view it from apache:
chown apache:apache /var/www/html/zm/cambozola.jar
  • Start ZoneMinder
service zm start

Note that you may get an error when you try to start Zoneminder using the 'zm' startup script as per this forum post: [[3]] . The reason for this was because the default 'zm' startup script was formatted with DOS line endings. If you get the errors as detailed in the above post then the fix is convert the 'zm' file to use UNIX style line endings. You can do this in the Vim text editor whilst editing the 'zm' file thus: ':set fileformat=unix' then save the file ':wq'. You can also use the utility dos2unix to convert the file.


  • tick the box for support for the Cambozola addon within your ZoneMinder installation: http://ip-address/zm (Options->Images tab->OPT_CAMBOZOLA)


Now have fun and add your cameras to ZoneMinder knowing that you now have a very stable and streamlined OS to run it on.



== '''P.S.''' == aspcicc@jumpy.it (Update: This does not appear to be required any more.)

Hi! and thanks for your guide.. i want to add a little correction that have made me crazy to resolve, when I poweroff or reboot system i obtain an error related to mysql database and i have understood that the problem was because mysqld is stopped before zoneminder to be more specific there isn't a link under rc0.d (halt) and rc6.d (reboot) to zoneminder that for this lack is simply killed by killall. To resolve this problem you need to add at the start of zm (under /etc/init.d) the line

' # chkconfig: 345 99 01 '  (without ' of course)

and then run chkconfig --level 345 zm on chkconfig --level 06 zm off

So the link to shutdown zm is created under rc0.d and rc6.d and zoneminder is started at the end of poweron and stopped at the beginning of the poweroff

For information about priority starting and stopping processes see: http://www.netadmintools.com/art94.html



Added Dependency: ImageMagick

Removed Dependency: perl-Time-HiRes, which causes a conflict with the default perl package.

Also, mysql seems to install with no password for the root user, and the zm DB create script creates the database on the fly, which means that the database create command needs to have the "-p zm" removed from the command line.

Could someone verify that this is correct, to make sure it's not just something I missed?

Thanks! terry@cnysupport.com