Building a new Ubuntu 10.04 LTS server. The old Ubuntu server needed a replacement of both hardware and software.
Hardware Setup:
A new 19" C2D DFI-ACP machine is used with four SATA drives:
- 250 GB System
- 500 GB Network Share
- 500 GB Backups
- 1 TB Zoneminder Events
Installation:
Ubuntu was installed from a CD without LVM on /dev/sda (250GB) Options chose where:
- Web Server
- File Server
- MySQL
- PostGreSQL
First network settings:
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.3
sudo ifdown -a
sudo ifup -a
The rest is mainly taken from this guide on www.zoneminder.com
http://www.zoneminder.com/wiki/index.php/Ubuntu_Server_11.04_64-bit_with_ZoneMinder_1.25.0_Preview,_FFmpeg,_libjpeg-turbo,_Webmin,_Cambozola
Update system software
sudo apt-get update
sudo apt-get upgrade
Set Zoneminder Shared Memory
sudo nano /etc/sysctl.conf
#Add in the following lines at the bottom of the file followed by an empty line:
kernel.shmall = 167772160
kernel.shmmax = 167772160
sudo reboot
sudo su
Optimize GCC compiler
export CFLAGS="-march=native -O2 -pipe" && \
export CXXFLAGS="${CFLAGS}" && \
export CPPFLAGS="${CFLAGS}"
Install prerequisites from repositories
aptitude install acpid build-essential linux-headers-`uname -r` automake perl libauthen-pam-perl \
apache2 libpam-runtime libio-pty-perl libmysqlclient-dev php5 php5-cli libapache2-mod-php5 php5-mysql \
libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libjpeg62 libmime-perl libstdc++6 libwww-perl \
zlib1g zip unzip patch ntp openssl libpcre3-dev libssl-dev libjpeg-progs libcurl4-gnutls-dev munin munin-node libmime-lite-perl \
netpbm libbz2-dev subversion yasm libnet-ssleay-perl libauthen-pam-perl libio-pty-perl apt-show-versions git-core mysql-server mysql-client
Install libjpeg-turbo (AMD64)
wget http://downloads.sourceforge.net/project/libjpeg-turbo/1.1.1/libjpeg-turbo_1.1.1_amd64.deb?use_mirror=voxel
mv libjpeg-turbo_1.1.1_amd64.deb?use_mirror=voxel libjpeg-turbo_1.1.1_amd64.deb && \
dpkg -i libjpeg-turbo_1.1.1_amd64.deb
ln -s /opt/libjpeg-turbo/lib/libjpeg.a /usr/lib/libjpeg.a && \
ln -s /opt/libjpeg-turbo/include/jconfig.h /usr/include/jconfig.h && \
ln -s /opt/libjpeg-turbo/include/jerror.h /usr/include/jerror.h && \
ln -s /opt/libjpeg-turbo/include/jmorecfg.h /usr/include/jmorecfg.h && \
ln -s /opt/libjpeg-turbo/include/jpeglib.h /usr/include/jpeglib.h
Configure Lib Paths
echo "/opt/libjpeg-turbo/lib" > /etc/ld.so.conf.d/libjpeg-turbo.conf && \
echo "/usr/local/lib" > /etc/ld.so.conf.d/ffmpeg.conf && \
echo "LD_LIBRARY_PATH=/usr/local/lib:/opt/libjpeg-turbo/lib:$LD_LIBRARY_PATH" >> /etc/bash.bashrc && \
echo "export LD_LIBRARY_PATH" >> /etc/bash.bashrc
ldconfig
Install Perl Modules
perl -MCPAN -e shell
install CPAN
exit
perl -MCPAN -e shell
install YAML PHP::Serialization Module::Load X10::ActiveHome
exit
LC_ALL=C perl -MCPAN -e shell
install Sys::Mmap
install DBI
install DBD::mysql
exit
Install FFmpeg
# !!!!!! Use the following line for FFMpeg from GIT skipping the 0.8.5 release instructions, otherwise, use the 0.8.5 release instructions
cd /usr/src && git clone git://git.videolan.org/ffmpeg.git
cd /usr/src/ffmpeg/ && ./configure --enable-gpl --enable-shared --enable-pthreads
#FFMPEG 0.8.5 release#
cd /usr/src && wget http://ffmpeg.org/releases/ffmpeg-0.8.5.tar.gz
tar -xzvf ffmpeg-0.8.5.tar.gz
mv ffmpeg-0.8.5 ffmpeg
#Continue from here regardless of method of getting FFMPEG#
cd /usr/src/ffmpeg/ && ./configure --enable-gpl --enable-shared --enable-pthreads --enable-libx264 --enable-libfaac --enable-nonfree --enable-x11grab --enable-version3
make
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
ldconfig
Install Zoneminder
cd /usr/src
wget http://www.zoneminder.com/downloads/ZoneMinder-1.25.0.tar.gz
tar -xzvf ZoneMinder-1.25.0.tar.gz
mv ZoneMinder-1.25.0 zm
cd /usr/src/zm && \
./configure --with-webdir=/var/www/zm --with-cgidir=/usr/lib/cgi-bin \
ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=zmuser \
ZM_DB_PASS=zmpass ZM_SSL_LIB=openssl --enable-debug=no \
--with-webgroup=www-data --with-webuser=www-data --enable-mmap=yes CPPFLAGS="-D__STDC_CONSTANT_MACROS ${CPPFLAGS}"
autoconf
aclocal
automake
make
mysql -u root -p < db/zm_create.sql
#Password that is requested is Mysql root password that was entered during install, not your ubuntu password.
mysql -u root -p
grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass';
quit
mysqladmin -p reload
make install
Create Zoneminder startup script
nano -w /etc/init.d/zm
#Paste everything BETWEEN the lines below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
# description: Control ZoneMinder as a Service
# chkconfig: 2345 99 99
# Source function library.
#. /etc/rc.d/init.d/functions
prog=ZoneMinder
ZM_PATH_BIN="/usr/local/bin"
command="$ZM_PATH_BIN/zmpkg.pl"
start() {
echo -n "Starting $prog: "
$command start
RETVAL=$?
[ $RETVAL = 0 ] && echo success
[ $RETVAL != 0 ] && echo failure
return $RETVAL
}
stop() {
echo -n "Stopping $prog: "
$command stop
RETVAL=$?
[ $RETVAL = 0 ] && echo success
[ $RETVAL != 0 ] && echo failure
}
status() {
result=`$command status`
if [ "$result" = "running" ]; then
echo "ZoneMinder is running"
RETVAL=0
else
echo "ZoneMinder is stopped"
RETVAL=1
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chmod 755 /etc/init.d/zm
Edit Zoneminder Script
#Because Ubuntu clears /tmp for some kind of reason at reboot,
#the /tmp/zm directory will also be deleted after a reboot. Creation in script/zmdc.in.pl
#will resolve this.
nano /usr/local/bin/zmdc.pl
#Add following lines (marked with a '+'-sign between the lines given (do not include '+').
foreach my $arg ( @ARGV )
}
}
+# Create the directory first if it doesn't exist
+mkdir(ZM_PATH_SOCKS);
+
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
my $saddr = sockaddr_un( SOCK_FILE );
#To be sure, add rights to the /tmp/zm directory
chown www-data:www-data -R /tmp/zm
Setup additional hard drives
mkfs.ext4 for all drives
/dev/sda1 as /
/dev/sdb1 as /var/www/zm/event/
/dev/sdc1 as /network
/dev/sdd1 as /backups
For the ZoneMinder share I set the noatime attribute to reduce write cycles.
sudo chown www-data:www-data events/
Setup PCI capture card
I used a Kodicom 4400R and an Ad-Link RTV24 card, with the following settings the machine booted in 18 seconds!
sudo nano /etc/modprobe.d/bttv.conf
alias char-major-81 bttv
options i2c-algo-bit bit_test=1
options bttv gbuffers=16 card=133,132,133,133,134,134,134,134 tuner=4,4,4,4,4,4,4,4
sudo adduser www-data video
Edit Apache:
change /var/www to /var/www/zm in /etc/apache2/sites-available/default
Well, that's the first part. The machine is now basically running. I can configure the rest of the ZoneMinder setup and I can see video now. Next up is transferring the data to this new machine, setup Samba, MySQL, backups and Apache.