Building Zimbra on Gentoo

Revision as of 22:47, 13 December 2007 by Spcmnspff (talk | contribs) (Creating the init scripts)

Here's a howto that will get Zimbra going on a Gentoo install. This method basically leverages debootstrap to get a bare debain sarge install in a chroot environment. The open source zimbra 4.5 package for Debian can then be installed. This is working on Gentoo 2006.1 kernel 2.6.17-gentoo-r5. But you shouldn't have any issues running it on older versions. At first this may seem like extra work and a waste of resources, but to the contrary running Zimbra in a chroot is a pretty good idea. People have been hosting chroot jails on *BSD's to run various internet services for quite some time. This can add a level of protection for the host system. I.e. if the unthinkable happens and an attacker does find a way to gain root through the host services on your Zimbra instance, (s)he will only have access to the chroot environment.

Stopping Apache on the Gentoo host

If you have a web server runing on your host Gentoo system you will need to stop it for now. Later you can change the ports Zimbra will listen on and run your host's web server and your zimbra web server on the same machine.


# /etc/ini.d/apache2 stop
# rc-update delete apahce2

Installing Zimbra in a Gentoo chroot

(Some of this was taken from http://www.elfenbeinturm.cc/2006/07/28/zimbra-on-gentoo/)


Emerge debootstrap

# echo "dev-util/debootstrap" >> /etc/portage/package.keywords
# emerge debootstrap


Create the chroot environment

# mkdir /zimbra


Run debootstrap

# debootstrap sarge /zimbra http://ftp.debian.org/debian

If you are on amd64 you will need to use debootstrap --arch i386 sarge /zimbra http://ftp.debian.org/debian so that it knows which architecture to bootstrap onto your machine.


Mount proc, dev and sys

# mount -o bind /proc /zimbra/proc
# mount -o bind /sys /zimbra/sys
# mount -o bind /dev /zimbra/dev
# mount -o bind /dev/pts /zimbra/dev/pts
# mount -o bind /dev/shm /zimbra/dev/shm


Chroot to the debian environment

# chroot /zimbra


Set a root password

# passwd


Adjust your hosts and hostname files

# nano -w /etc/hosts
# nano -w /etc/hostname


Add cache limit to apt.conf

# echo "APT::Cache-Limit 16777216" >> /etc/apt/apt.conf


Tell apt where to get all the repositories

This will execute an ncurses menu prompting you to choose a debian mirror pick http or ftp and select a (hopefully) fast mirror:

# apt-setup


Update the package listing

# apt-get update


Install some packages that we will need

# apt-get install sshd wget sudo libidn11 curl fetchmail libgmp3 libxml2 libstdc++6 openssl file perl libexpat1


Get the zimbra debian package and untar the archive

# CD ~
# wget http://files.zimbra.com/downloads/4.5.10_GA/zcs-4.5.10_GA_1575.DEBIAN3.1.tgz
# tar -xvzf zcs-4.5.10_GA_1575.DEBIAN3.1.tgz


Run install script in the newly created zcs directory

# cd zcs
# ./install.sh

Follow the instructions. See the Zimbra documentation for help.


Configure sshd to run on a different port inside the chroot:

sshd running on the Gentoo host is one of those conflicting services mentioned earlier. It will hinder Zimbra's ability to monitor queues from the management console. So let's fix it:

# nano -w /etc/ssh/sshd_config

Find the line that reads:

port 22

and change it to:

port 23


Start sshd

# /etc/init.d/sshd start


Test your Zimbra install

# su - zimbra
$ zmcontrol start


Creating the init scripts

It would be nice to get Zimbra to start at boot in the default run level. This requires an init script. Some of the init scripts that have been floating around for this are a little rough, raising job control issues while piping to the chroot command in the init shell. To avoid this we'll generate three scripts. Two scripts will live inside the chroot environment and will start and stop Zimbra. One script will live in /etc/init.d in the Gentoo host environment and will pass control to the start and stop scripts at the right time.


Exit chroot and create the gentoo init.d script

$ exit && exit
# nano -w /etc/init.d/zimbra
append init.d script from below


Create zimbra_start.sh

# nano -w /zimbra/usr/sbin/zimbra_start.sh
append zimbra_start.sh script from below


Create zimbra_stop.sh

# nano -w /zimbra/usr/sbin/zimbra_stop.sh
append zimbra_stop.sh script from below


Make the scripts executable

# chmod +x /etc/init.d/zimbra
# chmod +x /zimbra/usr/sbin/zimbra_start.sh
# chmod +x /zimbra/usr/sbin/zimbra_stop.sh


Test the init script

# /etc/init.d/zimbra stop
# /etc/init.d/zimbra start


Add it to the default run level

# rc-update add zimbra default


Now you should have a functioning Zimbra system installed in a chroot that you can manage from the host gentoo system at boot or otherwise. If you were running a web server on your host gentoo system you will need to configure Zimbra to listen on different port for web and ssl (try 81 and 1443). Search the zimbra forums there is some documentation for this already in place. You will then be able to cofigure a named based vitual host to link from you gentoo hosted site to zimbra.

Script: /etc/init.d/zimbra

#!/sbin/runscript

depend() {
    need net
    after portmap
    after iptables
    after dnsmasq
}

start() {

ebegin "Starting Zimbra in chroot environment"

   mount -o bind /proc /zimbra/proc
   mount -o bind /dev /zimbra/dev
   mount -o bind /dev/shm /zimbra/dev/shm
   mount -o bind /dev/pts /zimbra/dev/pts
   mount -o bind /dev/sys /zimbra/sys

   chroot /zimbra /usr/sbin/zimbra_start.sh

eend $? "Errors were encountered while starting Zimbra in chroot environment"

}

stop() {

ebegin "Stopping Zimbra in chroot environment"

   chroot /zimbra /usr/sbin/zimbra_stop.sh

   umount -f /zimbra/proc
   umount -f /zimbra/dev
   umount -f /zimbra/dev/shm
   umount -f /zimbra/dev/pts
   umount -f /zimbra/sys

eend $? "Errors were encountered while stopping Zimbra in chroot environment"

} 

Script: /zimbra/usr/sbin/zimbra_start.sh

#!/bin/bash

   rm -rf /var/run/*.pid
   /etc/init.d/sysklogd start
   /etc/init.d/cron start
   /etc/init.d/sshd start
   su - zimbra -c /opt/zimbra/bin/zmcontrol start

Script: /zimbra/usr/sbin/zimbra_stop.sh

#!/bin/bash

   su - zimbra -c /opt/zimbra/bin/zmcontrol stop
   /etc/init.d/sshd stop
   /etc/init.d/cron stop
   /etc/init.d/sysklogd stop

Building Zimbra from source on Gentoo

(needs to be documented)

Jump to: navigation, search