Startseite arrow Linux Server Scripte arrow SUSE: Csync2 Installation
Linux: "SUSE Csync2 Installation"

Dieses Script installiert unter SUSE Linux CSync2 (nicht CSync welches eher nur für Home-Verzeichnisse in SMB Umgebungen verwendet wird). Csync2 dient dazu Verzeichnisse und Dateien auch innerhalb einer komplexen Clusterumgebung (zwei oder mehr Nodes) mit auch unterschiedlichen Regelgruppen abzugleichen.

Standardmäßig werden alle von CSync2 benötigten Dateien (.cfg, keys, etc.) im Verzeichnis /etc gespeichert. Dies führt bei größeren Installationen schnell zu einer unübersichtlichen Konfiguration. Daher wird bei unserem Script ein Verzeichnis /etc/csync2 angelegt, sofern Sie die Option "install a basic csync2-config for the Nagios/Check_mk default configuration" auswählen. Sollten Sie kein Nagios/Check_mk einsetzten ist dies trotzdem eine gute  Vorlage um sich eine eigene Konfiguration zu erstellen.

Fehlende Softwarepakete werden nachinstalliert (Internetzugang ggf. erfolderlich!) und für die Konfigurtaion notwendige Daten interaktiv abgefragt.

Einfach mit einen Unix Editor eine Shellscript-Datei erzeugen. Zum Beispiel "vi /usr/bin/local/csync2_install.sh". Die Scriptcode reinkopieren und speichern. Jetzt nur noch die Datei mit "chmod -x /usr/bin/local/csync2_install.sh" ausführbar machen. Die Datei kann jetzt mit root-Rechten /usr/bin/local/csync2_install.sh ausgeführt werden. Die Aktion auf beiden Nodes durchführen und Fertig!

WICHTIG:
Beachten Sie unbedingt die CSync2 Dokumentation des Csync2 Entwicklers auf http://oss.linbit.com/csync2/

Haftungsausschluss beachten!

#!/bin/bash
# Spirithost, Jun 2010

clear
LOGFILE="./csync_install.log"
exec > >(tee $LOGFILE) 2>&1

set -e

HOST=`hostname`
FQDN=`hostname -f`
DATE=`date +"%y%m%d_%H%M"`

cat <<EOF

  Some helpful Informations before we start with the Installation:
  ----------------------------------------------------------------

  1. Important: Please install first the secondary Cluster-Node(s)
  2. Old configuration files will be saved in the "/etc/csync/old_versions" directory.
  3. Absence source or applications (csync2, librsync, ...) will be installed automaticly if needed.
  4. This script use only rudimentary spell check features.
  5. The "Cluster-Node Name" have to match with the shell command "hostname"!
  6. The "32bit" and "64bit" RPM Installation don't support SSL data transfer, the positive point is,
     that it is faster

EOF

echo -n "Number of Cluster-Nodes (default=\"2\"): ";read CLUSTERS
[ -z $CLUSTERS ] && CLUSTERS="2"

i="0"
while [[ $((++i)) -le $CLUSTERS ]]; do

   if [[ $i = "1" ]]; then
      echo -n "Name PRIMARY Cluster-Node: (default=\"$HOST\"): ";read PNAME
      [ -z $PNAME ] && PNAME=$HOST; [[ $PNAME = $HOST ]] || break
   elif [[ $i > "1" ]]; then
      set SNAME$i="TEST"
      echo -n "Name Cluster-Node \"$i\"   : ";read INPUT
      [ -z $INPUT ] && echo "Error: No Hostname insered!" && exit 1
      eval SNAME[$i]=$INPUT
   fi
  
[[ $PNAME = ${SNAME[$i]} ]] && echo "ERROR: Primary and Secondary Hostname are matching!" && exit 1

done

echo "----------------------------------------------------------"
if [[ ! -f /usr/sbin/csync2 ]]; then
   echo -n "Do you want to install csync2 32bit, 64bit or form Source? (32/64/SCR): "; read CSYNC
fi
[[ $CSYNC = "" ]] && NOCSYNC="Csync2 is not selected"

if [[ $PNAME = $HOST ]]; then
   echo -n "Do you want to install a basic csync2-config for the Nagios/Check_mk default configuration? (yes/no): ";read NAGIOS
fi
[[ $NAGIOS != "yes" ]] && NONAGIOS="Nagios/Check_mk default backup config is not selected"


# ***************************** INSTALLATION *****************************
clear

[[ ! -d /root/csync2 ]] && mkdir -p /root/csync2/
[[ ! -d /etc/csync2 ]] && mkdir -p /etc/csync2/
[[ ! -d /var/backups/csync2 ]] && mkdir -p /var/backups/csync2/

if [[ $CSYNC = "SCR" ]]; then

    echo "Info: Installation from Source is selected"
    if [ ! -f /usr/sbin/csync2 ]; then
      zypper install librsync openssl openssl-devel glibc-devel libgcc gcc gcc-c++ bison \
         flex make gnutls libgnutls-devel libtasn1

      cd /root/csync2/
      [[ -f sqlite-2.8.17.tar.gz ]] || \
         wget https://api.opensuse.org/public/source/home:netmax/csync2/sqlite-2.8.17.tar.gz
      tar xvfz sqlite-2.8.17.tar.gz -C /usr/local/src/
      cd /usr/local/src/sqlite-2.8.17/
      ./configure
      make
      make install
 
      cd /root/csync2/
      [[ -f csync2-1.33.tar.gz ]] || \
         wget https://api.opensuse.org/public/source/home:netmax/csync2/csync2-1.33.tar.gz
      tar xvfz csync2-1.33.tar.gz -C /usr/local/src/
      cd /usr/local/src/csync2-1.33/
      ./configure --disable-gnutls
      make
      make install

      cat /etc/services | grep csync2 || \
         echo "csync2          30865/tcp   # CSync2 Cluster Syncronisation Service" >> /etc/services

      if [[ ! -f /etc/xinetd.d/csync2 ]]; then
cat <<EOF > /etc/xinetd.d/csync2
# default: on
# description: csync2
service csync2
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        group           = root
        server          = /usr/sbin/csync2
        server_args     = -i
        #log_on_failure += USERID
        disable         = no
        # only_from     = 192.168.199.3 192.168.199.4
}
EOF
      fi

      else
      echo "Csync2 is already installed!"
   fi

elif [[ $CSYNC = "32" ]]; then

   echo "Info: Installation from RPM 32-bit is selected"

   cd /root/csync2/
   zypper install librsync sqlite
   [[ -f csync2-1.33-6.1.i586.rpm ]] || \
      wget http://download.opensuse.org/repositories/home:/netmax/openSUSE_11.0/i586/csync2-1.33-6.1.i586.rpm
   rpm -i csync2-1.33-6.1.i586.rpm --nosignature

elif [[ $CSYNC = "64" ]]; then

   echo "Info: Installation from RPM 64-bit is selected"

   cd /root/csync2/
   zypper install librsync sqlite
   [[ -f csync2-1.33-6.1.x86_64.rpm ]] || \
      wget http://download.opensuse.org/repositories/home:/netmax/openSUSE_11.0/x86_64/csync2-1.33-6.1.x86_64.rpm
   rpm -i csync2-1.33-6.1.x86_64.rpm --nosignature
else
   echo "Info: Csync2 is already installed or not selected!"
fi


# ***************************** CONFIG CSYNC2 *****************************
if [[ $NAGIOS = "yes" ]]; then

   if [[ $PNAME = $HOST ]]; then

   echo "Info: Writing the configrutaion files!"
   echo "Info: The old csync.cfg file is saved in /etc/csync2/"

   [[ -f /etc/csync2.cfg ]] && cp /etc/csync2.cfg /etc/csync2/csync2.cfg_$DATE
   [[ -f /etc/csync2/csync2_group_nagios.cfg ]] && \
      cp /etc/csync2.cfg /etc/csync2/csync2_group_nagios.cfg _$DATE

   grep csync2_group_nagios /etc/csync2.cfg || \
      echo "config /etc/csync2/csync2_group_nagios.cfg" >> /etc/csync2.cfg

   i="1"; HOSTS=$PNAME
   while [[ $((++i)) -le $CLUSTERS ]]; do
      HOSTS="$HOSTS ${SNAME[$i]}"
   done

   [ \( "$CSYNC" = "32" -o "$CSYNC" = "64" \) ] && NOSSL=" nossl $HOSTS;"

cat <<EOF > /etc/csync2/csync2_group_nagios.cfg
group nagiosgroup {
 host $HOSTS;
 key /etc/csync2/keys/csync2_key_group_nagios;
 backup-directory /var/backups/csync2;
 backup-generations 2;

 # Conflict auto-resolving. Possible mechanism are:
 # none, first, younger/older, bigger/smaller, left/right
 auto none;

 # nagios syncronisation
 include /etc/nagios;
 include /var/lib/nagios/rrd;
 include /usr/local/share/nagios/htdocs;
 include /usr/lib/nagios/plugins;

 # apache2 syncronisation
 include /etc/apache2;

 # check_mk syncronisation
 include /etc/check_mk;
 include /var/lib/check_mk/precompiled;
 include /var/lib/check_mk/autochecks;
 include /usr/share/check_mk/checks;
 exclude /etc/check_mk/logwatch.state;

 # nagvis syncronisation
 include /usr/local/share/nagvis/share/var;

 # csync syncronisation
 include /etc/csync2.cfg;
 include /etc/csync2;
 include /etc/xinetd.d/csync2;

 # excludes
 exclude *cache;
 exclude *.log;
 exclude *~ .*;

action
{
        pattern /etc/csync2.cfg;
        pattern /etc/csync2/*;
        pattern /etc/xinetd.d/csync2;
        exec "/etc/inid.d/xinetd reload";
        logfile "/var/log/csync2_action.log";
        do-local;
}

}

$NOSSL
EOF

grep csync2 /etc/crontab || \
cat <<EOF >> /etc/crontab
# csync2 scheduler task
#-00   */1    *     *     *  root /usr/sbin/csync2 -x >/dev/null 2>&1
EOF


   mkdir -p /etc/csync2/keys/
   [[ -f /etc/csync2/keys/csync2_key_nagios_group ]] || \
      /usr/sbin/csync2 -k /etc/csync2/keys/csync2_key_group_nagios


# ***************************** COPY CONFIG *****************************
   clear

   i="1"
   while [[ $((++i)) -le $CLUSTERS ]]; do
      echo ""
      echo "Please insert the root password for the secondary Cluster-Node ${SNAME[$i]} !"
      scp -r /etc/csync2/* root@${SNAME[$i]}:/etc/csync2/
      scp /etc/csync2.cfg root@${SNAME[$i]}:/etc/csync2.cfg
   done

   echo ""
   echo ""
   echo "Csync is now installed. Please sync first all required files with rsync"
   echo "Please read first the csync2 documentation under http://www.clifford.at"
   echo "Then use \"csync2 -cr\" for the first csync database initialisation"
   echo "Don't forgett to open the firwall port 30865/tcp on all CSync Clusternodes!"
   fi
fi
 
exit