Tech Tip #25 showed how to configure WildFly on Raspberry Pi. Tech Tip #27 showed how to setup WildFly on two Raspberry Pis in managed domain mode. This tech tip will show how to setup a WildFly cluster over those two hosts.
WildFly supports mod_cluster out of the box. There are several advantages of mod_cluster:
- Dynamic configuration of httpd workers
- Server-side load balance factor calculation
- Fine-grained web app lifecycle control
However there is no ARM build available for it, yet. So we’ll use mod_proxy instead that gets pre-installed as part of Apache2. The Domain Controller and HTTP server need not be on the same host and that’s the configuration we’ll use for our setup. So effectively, there will be three Raspberry Pis:
- Domain Controller
- Host Controller
- Web Server
Lets get started!
- Before installing any modules, including Apache, on Raspbian, the system needs to be fully updated:
1234567891011121314151617181920pi@raspberrypi~ $ <strong>sudo apt-get update && sudo apt-get upgrade</strong>Get:1 http://reflection.oss.ou.edu wheezy Release.gpg [490 B]Hit http://repository.wolfram.com stable Release.gpgHit http://repository.wolfram.com stable ReleaseGet:2 http://reflection.oss.ou.edu wheezy Release [14.4 kB]Get:3 http://raspberrypi.collabora.com wheezy Release.gpg [836 B]Get:4 http://archive.raspberrypi.org wheezy Release.gpg [490 B]. . .Setting up udisks (1.0.4-7wheezy1) ...Setting up rpi-update (20140321) ...Setting up ssh (1:6.0p1-4+deb7u1) ...Setting up perl-modules (5.14.2-21+rpi2+deb7u1) ...Setting up perl (5.14.2-21+rpi2+deb7u1) ...Setting up libdpkg-perl (1.16.14+rpi1) ...Setting up dpkg-dev (1.16.14+rpi1) ...Processing triggers for menu ...
123456789101112Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2.2-bin armhf 2.2.22-13404 Not FoundErr http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2-utils armhf 2.2.22-13404 Not FoundErr http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2.2-common armhf 2.2.22-13404 Not FoundErr http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2-mpm-worker armhf 2.2.22-13404 Not FoundErr http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2 armhf 2.2.22-13404 Not Found
1234567891011121314151617181920212223242526pi@raspberrypi /~ $ <strong>sudo apt-get install apache2</strong>Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following extra packages will be installed:apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-certSuggested packages:apache2-doc apache2-suexec apache2-suexec-custom openssl-blacklistThe following NEW packages will be installed:apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert0 upgraded, 10 newly installed, 0 to remove and 1 not upgraded.Need to get 1,352 kB of archives.After this operation, 4,916 kB of additional disk space will be used.Do you want to continue [Y/n]? <strong>y</strong>Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libapr1 armhf 1.4.6-3+deb7u1 [90.9 kB]Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libaprutil1 armhf 1.4.1-3 [77.1 kB]. . .Setting up apache2-mpm-worker (2.2.22-13+deb7u1) ...[....] Starting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName. okSetting up apache2 (2.2.22-13+deb7u1) ...Setting up ssl-cert (1.0.32) ...
123ServerName localhost - After Apache is installed, “mod_proxy” modules already exists in the “/usr/lib/apache2/modules” directory, and just need to enabled.Create “/etc/apache2/mods-enabled/mod_proxy.load” as:
123456LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.soLoadModule proxy_balancer_module /usr/lib/apache2/modules/mod_proxy_balancer.soLoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.soLoadModule headers_module /usr/lib/apache2/modules/mod_headers.soRestart the server:
123sudo service apache2 restartIf there are any errors, then you can see them in “/var/log/apache2/error.log” directory.
The list of modules loaded can be seen using:
123456789101112131415161718192021222324252627282930313233~ <strong>/apachectl -t -D DUMP_MODULES</strong>Loaded Modules:core_module (static)log_config_module (static)logio_module (static)version_module (static)mpm_worker_module (static)http_module (static)so_module (static)alias_module (shared)auth_basic_module (shared)authn_file_module (shared)authz_default_module (shared)authz_groupfile_module (shared)authz_host_module (shared)authz_user_module (shared)autoindex_module (shared)cgid_module (shared)deflate_module (shared)dir_module (shared)env_module (shared)mime_module (shared)<strong>proxy_module (shared)</strong><strong>proxy_balancer_module (shared)</strong><strong>proxy_http_module (shared)headers_module (shared)</strong>negotiation_module (shared)reqtimeout_module (shared)setenvif_module (shared)status_module (shared)Syntax OKThe newly loaded modules are highlighted in bold.
- Provide convenient host names for each of the Raspberry Pis. The names chosen for each host is shown in the table below:
IP Address Role Host Name 10.0.0.27 Domain Controller raspi-master 10.0.0.28 Host Controller raspi-slave 10.0.0.29 Web Server raspi-apache This is enabled by editing “/etc/hostname” on each Raspberry Pi and changing “raspberrypi” to the given name.
In addition, “/etc/hosts” on each Raspberry Pi need to make two entries of the following format:
1234127.0.0.1 <Host Name><IP Address> <Host Name>Here <IP Address> and <Host Name> for each host needs to be used from the table above.
Finally, added the following entries on “/etc/hosts” on my local Mac:
1234510.0.0.27 raspi-master.example.com10.0.0.28 raspi-slave.example.com10.0.0.29 raspi-apache.example.comThis ensures that any cookies are set from the same domain.
Flush the DNS using:
123sudo dscacheutil -flushcacheNow raspi-master.example.com:8330 in the browser shows:
And similarly raspi-slave.example.com:8330 shows:
- Configure mod_proxy load balancer by editing “/etc/apache2/apache2.conf” and add the following lines at the end of the file:
123456789Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED<Proxy balancer://raspicluster>BalancerMember http://10.0.0.27:8330BalancerMember http://10.0.0.28:8330ProxySet stickysession=ROUTEID</Proxy>ProxyPass / balancer://raspicluster/
This directive provide load balancing between “master” and “slave”. “Header” and “ProxySet” directive provides sticky session.
Now accessing raspi-apache.example.com/http-1.0-SNAPSHOT/index.jsp shows:
And so in three parts (part 1 and part 2), we learned how to setup a WildFly cluster on Raspberry Pi!
Thanks for the tutorial.
When you have a server running the same static addres all the time you should change the address 127.0.1.1 in /etc/hosts to your machines proper IPv4 address.
To change the name of the machine you change raspberrypi in /etc/hosts and /etc/hostname and maybe in /etc/mailname to the new name.
To enable (and disable) sites and modules in apache2 you can/should use a2ensite and a2disite resp a2ensmod and a2dismod. See man pages.
To set up sites, you copy /etc/apache2/sites-available/000-default.conf to /etc/apache2/sites-available/name.conf and edit it and run a2ensite name.
I aam not sure where you are getting your info, but
great topic. I needs to spend some time learning more or understanding more.
Thanks for great info I was looking for this information forr my mission.
Here is my site: canon
Hello there, You have done a fantastic job. I will certainly digg it and
personally suggest to my friends. I’m sure they’ll be benefited from this site.