Tomcat + REX – Debian Sqeeze

Print Friendly, PDF & Email

Narzędzia pozwalające na Deploy aplikacji. Dzięki aplikacji REX, możemy robić to na kilku serwerach.
Potrzebujemy czystego systemu Debian Squeeze, oraz dostępu do serwera jako root.


1) Instalacja Rex:

Dodamy źródła do naszej listy, następnie pobierzemy oraz zainstalujemy je (pierwsze dwa polecenia znajdują się w dwóch wierszach):

echo 'deb http://rex.linux-files.org/debian/ squeeze rex’ && 

/etc/apt/sources.list


wget -O – http://rex.linux-files.org/DPKG-GPG-KEY-REXIFY-REPO |


 apt-key add –




apt-get update && apt-get install rex rex-apache-deploy


2) Przygotowanie REX’a do pierwszego użycia:

mkdir tomcat 

cd tomcat


Pobieramy przykłady dla REX’a:


git clone https://github.com/krimdomu/rex-example-modules.git lib


Tworzymy plik Rexile (w katalogu tomcat):



# File: Rexfile
# at first enable strict and warnings
use strict;
use warnings;
# than include all needed example modules
use ALLMODS;    # this sets the include path to the rex example modules
use apache;     # include apache module
use apache::module;
use tomcat;     # include tomcat module
use tomcat::user;
use tomcat::role;
# set user and password to login to your servers
user „root”;
password „test”;
# enable password authentication.
pass_auth;
# if you want to use key authentication use the following
# and comment out the line „pass_auth”
# public_key „/path/to/your/public.key”;
# private_key „/path/to/your/private.key”;
# define a server group named „tomcat”. 
# put all your servers you want to deploy in that group.
group tomcats => „tc01”, „tc02”;
desc „Install and Configure Apache and Tomcat”;
task „prepare”, group => „tomcats”, sub {
   apache::setup();
   apache::module::setup({name => „jk”});
   tomcat::setup();
   tomcat::role::add_manager();
   tomcat::user::add_manager({
      username => „manager”,
      password => „passw0rd”,
   });
   apache::restart();
   tomcat::restart();
   # take care that the services will start on system boot
   service apache2 => „ensure”, „started”;
   service tomcat6 => „ensure”, „started”;
};

Wykonujemy przygotowane zadanie:

rex prepare

rex -T (wyświetla przygotowane przez nas zadania)


3) Konfiguracja Apache:

mkdir files

Tworzymy plik worker.properties:

## File: files/worker.properties
## this file is managed by rex
##
worker.list=tc,jkstatus
worker.tomcat.port=8009
worker.tomcat.host=<%+ $::Network->{„networkconfiguration”}->{„eth0”}->{„ip”} %>
worker.tomcat.type=ajp13
worker.tomcat.lbfactor=1
worker.tomcat.reference=worker.template
worker.tc.type=lb
worker.tc.balance_workers=tomcat
worker.tc.sticky_session=false
worker.jkstatus.type=status
worker.template.type=ajp13

Tworzymy plik modjk.conf:

## File: files/modjk.conf
## this file is managed by rex
##
JkWorkersFile /etc/apache2/worker.properties
JkLogFile /var/log/apache2/mod_jk.log
JkShmFile /var/log/apache2/jk.shm
JkMount /* tc
# Add the jkstatus mount point
JkMount /jkmanager/* jkstatus
JkMount jkstatus

Do Rexfile dodajemy dalszą konfiguracje: 


desc „Configure Apache and Tomcat”;
task „configure”, group => „tomcats”, sub {
   # remove default vhost
   unlink „/etc/apache2/sites-enabled/000-default”;
   # upload the file, but parse the file as a template
   file „/etc/apache2/worker.properties”,
      content   => template(„files/worker.properties”),
      owner     => „root”,
      group     => „root”,
      mode      => 640,
      on_change => sub { apache::restart(); };
   # upload the configuration files
   file „/etc/apache2/conf.d/modjk.conf”,
      source    => „files/modjk.conf”,
      owner     => „root”,
      group     => „root”,
      mode      => 640,
      on_change => sub { apache::restart(); };
   # patch server.xml to allow ajp access
   # in realworld use a template for this file
   my $content = cat „/etc/tomcat6/server.xml”;
   $content =~ s/</Service>/n</Service>/;
   file „/etc/tomcat6/server.xml”,
      content   => $content,
      on_change => sub { tomcat::restart(); };
   
};
      

Następnie wykonujemy:


rex configure



4) Deploy:


mkdir packages
cd packages
wget http://psi-probe.googlecode.com/files/probe-2.2.3.zip
unzip probe-2.2.3.zip

do Rexfile dodajemy:

# include deployment support for tomcat
use Rex::Apache::Deploy „Tomcat”;

oraz


desc „Deploy the application”;
task „deploy”, group => „tomcats”, sub {
   # set the context path for our tomcat application
   context_path „/psiprobe”;
   # deploy the app. 
   deploy „packages/probe.war”,
      username => „manager”,
      password => „passw0rd”,
      port     => 8080;
};


5) Łączymy wszystkie zadania:


Do Rexfile dodajemy:
desc „Execute all tasks prepare, configure and deploy”;
batch all => „prepare”, „configure”, „deploy”;
na koniec:
rex -b all
Po wykonaniu wszystkie, powinniśmy dostać dostęp do środowiska Deploy w katalogu /psiprobe.


Print Friendly, PDF & Email

Dziękuję Ci, za poświęcony czas na przeczytanie tego artykułu. Jeśli był on dla Ciebie przydatny, to gorąco zachęcam Cię do zapisania się na mój newsletter, jeżeli jeszcze Cię tam nie ma. Proszę Cię także o “polubienie” mojego bloga na Facebooku oraz kanału na YouTube – pomoże mi to dotrzeć do nowych odbiorców. Raz w tygodniu (niedziela punkt 17.00) otrzymasz powiadomienia o nowych artykułach / projektach zanim staną się publiczne. Możesz również pozostawić całkowicie anonimowy pomysł na wpis/nagranie.

Link do formularza tutaj: https://beitadmin.pl/pomysly

Pozostaw również komentarz lub napisz do mnie wiadomość odpisuję na każdą, jeżeli Masz jakieś pytania:).

Dodaj komentarz

beitadmin.pl - Droga Administratora IT