First8 staat voor vakmanschap. Al onze collega’s zijn een groot aanhanger van Open Source en in het bijzonder het Java-platform. Wij zijn gespecialiseerd in het pragmatisch ontwikkelen van bedrijfskritische Java toepassingen waarbij integratie van systemen, hoge eisen aan beveiliging en veel transacties een belangrijke rol spelen. Op deze pagina vind je onze blogs.

Managing multiple gears with Open Shift

In the previous blog post we learned how we could scale an application horizontally. If you run your application on multiple gears, life becomes a bit more complicated. If you are investigating a production problem, the first thing in general to look at is the applications log file. Since there is now more than one instance, there are multiple log files as well, each on different machines. In this blog post I’ll show some tricks which can ease the pain a bit.

If you have a scaled web application with a database, your setup will look something like this:

 

scale2

Accessing log files

To find out what the names are of the gears, you can use rhc app show –gears:

Using this command you can see the gears ID’s, if they are running and what cartridges are running on them (in this case some JBoss AS 7 instances with a PostgreSQL database). Also note that you can access them directly via ssh using the ssh url’s.

You can also inspect the log files on a specific gear directly (without having to ssh into them first) using rhc tail:

Accessing specific gears

As described above, you can always access specific gears via ssh directly (or via your main gear and ssh from there).

In some cases it might be necessary to access the running application server on a specific gear using for example a browser. The problem is that HAProxy will load balance your request to a random gear that is available so you might end up on a different one that you want. In the example above, we could access the second gear (the one ending with …0a8) directly by visiting
http://555ddecc5973ca027b0000a8-first8.rhcloud.com. If we try that on the main gear (the one starting with …062) the request will be server by HAProxy and can thus end up anywhere.

A way around this is to create an ssh tunnel from your workstation towards the specific application ports on your gears. The Red Hat command line tools provide a convenient way of doing that:

Note that this creates port forwards for all processes on the main gear. The Java process on port 8080 is the JBoss web server which is forwarded from your desktop and is now reachable under <i>127.0.0.1:8083</i>. These forwards will exists for as long as you keep the rhc port-forward command running. Note that e.g. the PostgreSQL port on the third gear is also exposed now so you could use this to directly connect a sql client running on your desktop to the PostgreSQL running on Open Shift by using the address 127.0.0.1:55556. There are also two HAProxy instances forwarded, one for each JBoss instance on the two gears, as well as a bunch of other internal JBoss modules.

You can also setup tunnels per gear:

Now you can directly access both application servers explicitly, in this example via 127.0.0.1:8083 for the main gear and 127.0.0.1:8084 for the second gear.

Using these commands, it is a lot easier to manage multiple gears.

Read more