Jboss 7 : Industrialisation part 1 – Cluster
Le 28/12/2012 Par Pierre Liseronjbosslinuxclusterscriptjboss 7installationindustrialisationnode
Automatisation de l’installation d’un node JBOSS 7 dans un cluster
Ajout du node
Par exemple l’ajout d’un node sur un cluster peut être rapidement réalisé avec un script:
Voici un script qui permet de télécharger directement un nouveau JBOSS 7.1, d’installer et de configurer l’instance pour se connecter au master avec son nom et son mot de passe.
Les sed sont ici présent pour correctement paramètrer l’instance sans aller modifier le fichier host.xml.
De même on peut supprimer un certain nombre de dossier inutile dans l’installation de JBOSS 7.1 afin de ne pas se laisser perturber.
#!/bin/sh JBOSS_URL_DOWNLOAD=http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz JBOSS_ZIP_FILE=jboss-as-7.1.1.Final.tar.gz JBOSS_INSTALL_PATH=/opt/ JBOSS_INSTALL_PATH_FULL=$JBOSS_INSTALL_PATH/jboss-as-7.1.1.Final JBOSS_INSTANCE_NAME=slave1 JBOSS_MASTER_PASSWORD=’password’ JBOSS_MASTER_IP=10.0.10.3 JBOSS_INSTANCE_IP=10.0.10.4 JBOSS_FILESYTEM_IP=10.0.10.5 JBOSS_HEAP_SIZE=512m cd $JBOSS_INSTALL_PATH #rm $JBOSS_INSTALL_PATH/* -r wget $JBOSS_URL_DOWNLOAD && tar -xzf $JBOSS_ZIP_FILE rm $JBOSS_ZIP_FILE rm $JBOSS_INSTALL_PATH_FULL/standalone/ -rf rm $JBOSS_INSTALL_PATH_FULL/copyright.txt rm $JBOSS_INSTALL_PATH_FULL/LICENSE.txt rm $JBOSS_INSTALL_PATH_FULL/README.txt rm $JBOSS_INSTALL_PATH_FULL/docs -rf rm $JBOSS_INSTALL_PATH_FULL/domain/configuration/host-master.xml rm $JBOSS_INSTALL_PATH_FULL/domain/configuration/host-slave.xml rm $JBOSS_INSTALL_PATH_FULL/domain/configuration/domain.xml sed -e "s/master/$JBOSS_INSTANCE_NAME/" $JBOSS_INSTALL_PATH_FULL//domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL//domain/configuration/host.xml sed -e "s/< security-realm name=\"ManagementRealm\">/ < security-realm name=\"ManagementRealm\">< server-identities> < secret value=\"$JBOSS_MASTER_PASSWORD\" \/>< \/server-identities>/" $JBOSS_INSTALL_PATH_FULL//domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml sed -e "s/< local\/>/< remote host=\"$JBOSS_MASTER_IP\" port=\"9999\" security-realm=\"ManagementRealm\" \/>/" $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml sed -e "s/127.0.0.1/$JBOSS_INSTANCE_IP/" $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml sed -e ’/< server name="server-three" group="other-server-group" auto-start="false">/,/< \/server>/d’ $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL/domain/configuration/host.xml sed -e "s/< heap size=\"64m\" max-size=\"256m\"\/>/< heap size=\"$JBOSS_HEAP_SIZE\" max-size=\"$JBOSS_HEAP_SIZE\"\/>/" $JBOSS_INSTALL_PATH_FULL//domain/configuration/host.xml > /tmp/host.tmp && mv -f /tmp/host.tmp $JBOSS_INSTALL_PATH_FULL//domain/configuration/host.xml
Ajout d’un script de démarrage
Maintenant que votre instance est configurée, il reste nécessaire de créer le script de démarrage et d’arret de JBOSS 7.1. Pour ce faire on peut encore une fois créer un script qui va créer le script de démarrage dans /etc/init.d/
Ce script va automatiquement créer le bon script de démarrage ainsi que mettre ce sript au démarrage de votre machine. Ainsi plus rien n’est nécessaire. Au passage, ce script va créer le bon utilisateur (jboss) ainsi que mettre les bons droits sur votre répertoire d’installation de JBOSS 7.1.
#!/bin/sh JBOSS_INSTALL_PATH=/opt/ JBOSS_INSTALL_PATH_FULL=$JBOSS_INSTALL_PATH/jboss-as-7.1.1.Final JBOSS_INSTANCE_NAME=slave1 JBOSS_INSTANCE_IP=10.0.10.4 echo -n " ### BEGIN INIT INFO # Provides: skeleton # Required-Start: \$remote_fs $syslog # Required-Stop: \$remote_fs $syslog # Should-Start: \$portmap # Should-Stop: \$portmap # X-Start-Before: nis # X-Stop-After: nis # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: true # Short-Description: Example initscript # Description: This file should be used to construct scripts to be placed in /etc/init.d. # ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/jboss-as-7.1.1.Final/bin NAME=jboss DESC=\"JBoss AS\" JBOSSOPTS=\" \" USER=\"jboss\" test -x \$DAEMON || exit 0 set -e case \"\$1\" in start) echo -n \"Starting \$DESC: \" start-stop-daemon -u \$USER --start --background --quiet --exec \$DAEMON/domain.sh -- \$JBOSSOPTS echo \"$NAME.\" ;; stop) echo -n \"Stopping \$DESC: \" echo \"Stopping JBoss AS 7.1.1\" sh \$DAEMON/jboss-cli.sh --connect --controller=$JBOSS_INSTANCE_IP:9999 command=/host=$JBOSS_INSTANCE_NAME:shutdown ;; restart|force-reload) echo -n \"Restarting \$DESC: \" start-stop-daemon -u \$USER --stop --quiet --exec \$DAEMON/domain.sh -- $JBOSSOPTS sleep 1 start-stop-daemon -u \$USER --start --background --quiet --exec \$DAEMON/domain.sh -- \$JBOSSOPTS echo \"\$NAME.\" ;; *) N=/etc/init.d/\$NAME echo \"Usage: \$N {start|stop|restart|force-reload}\" >&2 exit 1 ;; esac exit " > /etc/init.d/jboss71 useradd jboss chmod +x /etc/init.d/jboss71 chown -R jboss $JBOSS_INSTALL_PATH_FULL chgrp -R jboss $JBOSS_INSTALL_PATH_FULL update-rc.d jboss71 defaults
Sommaire
Ajout du node
Ajout d’un script de démarrage