Cluster de Alta disponibilidade do Zimbra Collaboration System

Este documento destina-se a todos os administradores de sistemas que desejam ter um serviço de alta disponibilidade em seu sistema de colaboração.

[ Hits: 26.523 ]

Por: Braulio Gomes Rodrigues em 17/11/2015 | Blog: http://www.linuxajuda.org


OFC



O OFC (Open Cluster Framework) é um conjunto de scripts para controlar os serviços dos computadores em cluster.

Vamos criar o arquivo /usr/lib/ocf/resource.d/btactic/zimbra:

#!/bin/sh
#
# Resource script for Zimbra
#
# Description:  Manages Zimbra as an OCF resource in
#               an high-availability setup.
#
# Author:       Adrian Gibanel
# <adrian.gibanel@btactic.com> : Original Author
# License:      GNU General Public License (GPL)
# Note:  Aimed at an active/passive cluster originally
#               Inspired from postfix OCF script
#  Inspired from Ubuntu LSB script.
#  Not sure it will work
#  for other distros without modifying
#
#
#   usage: $0 {start|stop|reload|status
#              |monitor|validate-all|meta-data}
#
#       The "start" arg starts Zimbra
#
#       The "stop" arg stops it.
#
# OCF parameters:
#  OCF_RESKEY_binary
#  OCF_RESKEY_config_dir
#  OCF_RESKEY_parameters
#
######################



# Initialization:

: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
: ${OCF_RESKEY_binary="zmcontrol"}
: ${OCF_RESKEY_zimbra_dir="/opt/zimbra"}
: ${OCF_RESKEY_zimbra_user="zimbra"}
: ${OCF_RESKEY_zimbra_group="zimbra"}
USAGE="Usage: $0 {start|stop|reload\
|status|monitor|validate-all|meta-data}";

###############################
usage() {
    echo $USAGE >&2
}
meta_data() {
        cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="zimbra">
<version>0.1</version>
<longdesc lang="en">
This script manages Zimbra as an
OCF resource in a high-availability setup.
</longdesc>
<shortdesc lang="en">
Manages a highly available Zimbra mail server instance
</shortdesc>

<parameters>

<parameter name="binary" unique="0" required="0">
<longdesc lang="en">
Short name to the Zimbra control script.
For example, "zmcontrol".
</longdesc>
<shortdesc lang="en">
Short name to the Zimbra control script</shortdesc>
<content type="string" default="zmcontrol" />
</parameter>

<parameter name="zimbra_dir" unique="1" required="0">
<longdesc lang="en">
Full path to Zimbra directory.
For example, "/opt/zimbra".
</longdesc>
<shortdesc lang="en">
Full path to Zimbra directory</shortdesc>
<content type="string" default="/opt/zimbra" />
</parameter>

<parameter name="zimbra_user" unique="1" required="0">
<longdesc lang="en">
Zimbra username.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra username</shortdesc>
<content type="string" default="zimbra" />
</parameter>

<parameter name="zimbra_group"
unique="1" required="0">
<longdesc lang="en">
Zimbra group.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra group</shortdesc>
<content type="string" default="zimbra" />
</parameter>

</parameters>

<actions>
<action name="start"   timeout="360s" />
<action name="stop"    timeout="360s" />
<action name="reload"  timeout="360s" />
<action name="monitor" depth="0"  timeout="40s"
interval="60s" />
<action name="validate-all"  timeout="360s" />
<action name="meta-data"  timeout="5s" />
</actions>
</resource-agent>
END
}

command()
{
  if [ -f ${zimbra_dir}/redolog/redo.log ]; then
    chown -f ${zimbra_user}:${zimbra_group} \
      ${zimbra_dir}/redolog/redo.log
  fi

  su - ${zimbra_user} -c "${binary} $1 </dev/null"
}

running() {
    # run Zimbra status
    command status
}

zimbra_status()
{
    running
}

zimbra_start()
{
    # if Zimbra is running return success
    if zimbra_status; then
        ocf_log info "Zimbra already running."
        return $OCF_SUCCESS
    fi
    # start Zimbra
    command startup
    ret=$?
    if [ -d /var/lock/subsys -a $ret -eq 0 ]; then
      touch /var/lock/subsys/zimbra
    fi

    if [ $ret -ne 0 ]; then
        ocf_log err "Zimbra returned error." $ret
        return $OCF_ERR_GENERIC
    fi

    # grant some time for
    # startup/forking the sub processes
    sleep 2

    # initial monitoring action
    running
    ret=$?
    if [ $ret -ne $OCF_SUCCESS ]; then
     ocf_log err "Zimbra failed \
initial monitor action." $ret
     return $OCF_ERR_GENERIC
    fi

    ocf_log info "Zimbra started."
    return $OCF_SUCCESS
}

zimbra_stop()
{
    # if Zimbra is not running return success
    if ! zimbra_status; then
        ocf_log info "Zimbra already stopped."
        return $OCF_SUCCESS
    fi

    # stop Zimbra
    command shutdown
    ret=$?

    if [ -d /var/lock/subsys -a $ret -eq 0 ]; then
      rm -f /var/lock/subsys/zimbra
    fi

    if [ $ret -ne 0 ]; then
        ocf_log err "Zimbra returned \
an error while stopping." $ret
        return $OCF_ERR_GENERIC
    fi

    # grant some time for shutdown and recheck 5 times
    for i in 1 2 3 4 5; do
        if zimbra_status; then
            sleep 1
        fi
    done

    # escalate to abort if we did not stop by now
    # @TODO shall we loop here too?
    if zimbra_status; then
        ocf_log err "Zimbra failed to stop. \
Escalating to 'abort'."

        ORPHANED=`ps -u ${zimbra_user} -o \
"pid="` && kill -9 $ORPHANED 2>&1
        ret=$?
        sleep 10

        # zimbra abort did not succeed
        if zimbra_status; then
            ocf_log err "Zimbra failed to abort."
            return $OCF_ERR_GENERIC
        fi
    fi

    ocf_log info "Zimbra stopped."
    return $OCF_SUCCESS
}

zimbra_reload()
{
    if zimbra_status; then
        ocf_log info "Reloading Zimbra."
        command reload
    fi
}

zimbra_monitor()
{
    if zimbra_status; then
        return $OCF_SUCCESS
    fi

    return $OCF_NOT_RUNNING
}

zimbra_validate_all()
{
    # check zimbra_dir parameter
    if [ ! -d "$zimbra_dir" ]; then
      ocf_log err "Zimbra directory \
'$config_dir' does not exist." $ret
      return $OCF_ERR_INSTALLED
    fi
    # check that the Zimbra binaries
    # exist and can be executed
    if ! have_binary \
"${zimbra_dir}/bin/${binary}" ; then
      return $OCF_ERR_INSTALLED
    fi

    # check permissions
    user=${zimbra_user}
    zimbra_writable_dirs="${zimbra_dir}/conf"
    for dir in "$zimbra_writable_dirs"; do
        if ! su -s /bin/sh - \
$user -c "test -w $dir"; then
            ocf_log err "Directory \
'$dir' is not writable by user '$user'."
            exit $OCF_ERR_PERM;
        fi
    done

    return $OCF_SUCCESS
}

#
# Main
#

if [ $# -ne 1 ]; then
    usage
    exit $OCF_ERR_ARGS
fi

binary=$OCF_RESKEY_binary
zimbra_dir=$OCF_RESKEY_zimbra_dir
zimbra_user=$OCF_RESKEY_zimbra_user
zimbra_group=$OCF_RESKEY_zimbra_group
parameters=$OCF_RESKEY_parameters

# debugging stuff
#echo OCF_RESKEY_binary=$OCF_RESKEY_binary \
# >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_dir \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_dir
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_user \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_user
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_group \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_group
#echo OCF_RESKEY_binary=$OCF_RESKEY_parameters \
#>> /tmp/prox_conf_$OCF_RESKEY_parameters


# build Zimbra options string
# *outside* to access from each method
OPTIONS=''
OPTION_CONFIG_DIR=''

# check if the Zimbra config_dir exist
if [ "x$config_dir" != "x" ]; then
    # check for postconf binary
    #check_binary "${zimbra_dir}/bin/${binary}"

    # remove all trailing slashes
    zimbra_dir=`echo $zimbra_dir | sed 's/\/*$//'`

fi

case $1 in
    meta-data)  meta_data
                exit $OCF_SUCCESS
                ;;

    usage|help) usage
                exit $OCF_SUCCESS
                ;;
esac

zimbra_validate_all
ret=$?

#echo "debug[$1:$ret]"
LSB_STATUS_STOPPED=3
if [ $ret -ne $OCF_SUCCESS ]; then
    case $1 in
    stop)       exit $OCF_SUCCESS ;;
    monitor)    exit $OCF_NOT_RUNNING;;
    status)     exit $LSB_STATUS_STOPPED;;
    *)          exit $ret;;
    esac
fi

case $1 in
    monitor)    zimbra_monitor
                exit $?
                ;;
    start)      zimbra_start
                exit $?
                ;;

    stop)       zimbra_stop
                exit $?
                ;;

    reload)     zimbra_reload
                exit $?
                ;;
    status)     if zimbra_status; then
                    ocf_log info "Zimbra is running."
                    exit $OCF_SUCCESS
                else
                    ocf_log info "Zimbra is stopped."
                    exit $OCF_NOT_RUNNING
                fi
                ;;
    validate-all)   exit $OCF_SUCCESS
                    ;;

    *)          usage
                exit $OCF_ERR_UNIMPLEMENTED
                ;;
Esac

Depois de criado o arquivo, vamos criar um link simbólico do mesmo:

# ln -s /usr/lib/ocf/resource.d/btactic/zimbra /usr/lib/ocf/resource.d/heartbeat/

Página anterior     Próxima página

Páginas do artigo
   1. Considerações iniciais
   2. Configuração dos serviços de DNS do cluster
   3. Instalação do Zimbra Collaboration System
   4. OFC
   5. Pacemaker
   6. Comandos para controlar e checar os serviços
   7. Criando uma página para exibir o status via web
Outros artigos deste autor

Tutorial completo de implementação de LDAP + Samba + Squid

Leitura recomendada

Qmail e chkuser - fila de mensagens limpa

MTA Selor: Servidor de E-mails - Novo Projeto GPL

Comunicação POP3

Postfix + Dovecot + MySQL + Squirrelmail no CentOS 5.5 32/64 bits

Reforçando a segurança do MTA Postfix com o Apolicy

  
Comentários
[1] Comentário enviado por qxada07 em 03/08/2016 - 09:56h

Parabéns mano...
Att.

01010010 01101001 01100011 01100001 01110010 01100100 01101111 00100000 01010110 01100001 01110011 01100011 01101111 01101110 01100011 01100101 01101100 01101100 01101111 01110011


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts