View Source

h4. Tech Tip 2 (01/2016) - Running GroundWork in a Linux Container

Linux containers are simple, portable instances of Linux that run under the LXC container system. Whether you have Groundwork Core or Enterprise, it’s always good to have portable versions of your GroundWork servers. With containers, you can move them, copy them, snapshot them, and upgrade them (or test doing so) easily.

h5. Requirements

A Linux system with enough horsepower to run GroundWork. That usually means at least a dual-core CPU and 8 GB RAM, and 160 GB free on your hard drive. Yes, you could run this on a VM, but we can safely ignore that consideration since it’s abstract. If you want to run GroundWork on Amazon EC2, you can do it in a container as well, but you will want to follow a particular configuration option. See below.

h5. How do you do it?

* Install LXC
* Create a container ([or download the 7.1 beta container|])
* Install GroundWork in the container

# Really, it’s almost that simple. On our lab system here, running Ubuntu 14.4, step 1 is all of:
{noformat}# apt-get install lxc lxctl lxc-templates{noformat}
Of course, there's more to it if you want to get the most up-to-date version, but this works fine.
If you are using another distro, you can find the equivalent for your package manager.
# Just for fun, you might want the web panel too:
{noformat}# wget -O - | bash{noformat}
That gives you a nice little view into what the containers are doing.
Figure: LXC Web Panel
The web panel runs on port 5000 on your local system by default. The default username and password is admin/admin.
# Once you install, you will be able to run commands that start with lxc-, like this:
{noformat}# lxc-ls{noformat}This will list all installed containers. Or you can run:
{noformat}# lxc-ls --fancy{noformat}
This says a bit more about the containers, like if they are running and their IP addresses.
# But first, you will need a container\! *If you downloaded the 7.1 beta, just un-tar it to /var/lib/lxc, like this:*
{noformat}# tar -xzvf lxc-gwos-server-71-beta.tgz -C / {noformat} Then *skip to step 15*, below.
# Otherwise, here's how you make one: You need an “image” to make a container with. Let’s say you are running on Ubuntu, but you want the container to run Centos. Well, you would need to install yum for that to work:
{noformat}# apt-get install yum{noformat}
# Then you can download an image and create a container with just one line:
{noformat}# lxc-create -t download -n mycentos -- --dist centos --release 6 --arch amd64{noformat}
# Call it whatever you want. The “-n” is for name, and you can be as creative as you like.
You can start the container like this:
{noformat}# lxc-start -n mycentos{noformat}
# Then you can attach to it like this:
{noformat}# lxc-attach -n mycentos{noformat}
# Now you have a root shell on the container\! But networking is still not done. Let’s fix that.
By default, LXC installs a DHCP server that hands out private addresses to containers, so you can probably just type:
{noformat}# yum install openssh-server{noformat}
{noformat}# yum install wget{noformat}
{noformat}# yum install patch{noformat}
{noformat}# yum install tar{noformat}
# That will get a few useful things installed. Then you can start the SSH server:
{noformat}# chkconfig sshd on{noformat}
{noformat}# service sshd start{noformat}
# Then set a root password:
{noformat}# passwd root{noformat}
# Finally, exit the shell:
{noformat}# exit{noformat}
And you are back at the prompt of your Ubuntu Linux system. From here, you can see what the IP address is with:
{noformat}# lxc-ls --fancy
mycentos RUNNING - - NO{noformat}
# You can SSH to this address (whatever it is on your system) from the Ubuntu command line:
{noformat}ssh root@{noformat}
# Now you are ready to install GroundWork. Just follow the usual instructions to transfer the file to the container and install it from a root shell. See: []\\
# Once GroundWork is installed, how do you access the portal pages? Isn’t the whole thing on a private address?
Yes it is. Of course you can access it using a browser from your Ubuntu desktop, but what if you want to get to it from other systems? You can’t reach that private address directly, but you can reach the address of your Ubuntu system that has LXC running on it.
You actually have two choices. You can either run Apache on the Ubuntu system and proxy HTTP requests to the GroundWork container, or you can make the container itself have an address on your normal network via a bridge. If you are running on the Amazon AWS cloud, you should use the proxy method. If you have control of your DHCP server, or can safely allocate static IP addresses, you might want to use the bridge method. The bridge method is covered nicely at this link: []\\
We recommend setting a hostname with DHCP/DNS that matches the hostname on the container, and ensuring that it correctly resolves prior to installing GroundWork.
To proxy HTTP requests to the GroundWork container, first install GroundWork on the container as mentioned above. Then install Apache and the proxy module on the Ubuntu host running the container. *We will assume the Ubuntu host has address, and that the container has private address You can adjust as necessary.*
{noformat}# apt-get install httpd{noformat}
{noformat}# a2enmod proxy proxy_http{noformat}
# Modify the conf file:
# Add the lines:
{noformat}RewriteEngine On
RewriteCond %{HTTP_HOST} ^*
RewriteRule (.*)$1 [P,L]
ProxyPreserveHost On
ProxyPass /
ProxyPassReverse /{noformat}
# Edit the /etc/apache2/mods-enabled/proxy.conf file:
Add the lines:
{noformat}<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
# Ok, now run Apache on the Ubuntu server:
{noformat}# service apache2 restart{noformat}
# Now to modify things on the GroundWork server, SSH to the Centos container (or use lxc-attach). Find the gw-config utility, and run it:
{noformat}# ./gw-config --machine_hostname{noformat}
# That will adjust all the portal configuration files to point to the proxied address. Note: depending on the version of GroundWork you are using, you might also need to do this:
{noformat}# sed -i 's/mycentos/' /usr/local/groundwork/config/josso-agent-config.xml{noformat}
# Replace ‘mycentos’ with the name of your container host. Then restart GroundWork portal services:
{noformat}service groundwork restart gwservices{noformat}
# Now if you point a browser to [], you will see the GroundWork portal\!

h5. Notes

There are a few limitations with the proxy approach. GDMA won’t work without a lot of adjustments that we haven’t covered here. Also, for example, it’s not possible to directly upload background files for the views application. The portal applications do work, though, and it’s adequate for testing and light-duty production monitoring. The best part is, you can move the server to any host just by stopping it (lxc-stop command) and tarring it up, then untarring it in the new location. If you use the bridge method, it’s just like having a GroundWork server on the network, but be advised that the load on the Ubuntu system network interface will be heavy, so you should use a capable machine.