Une machine virtuelle en cours d’exécution avec Vagrant

In this section you will find instructions on how to setup an Ubuntu 16.04 VM using `Vagrant`_

Programme d’installation de Vagrant

  1. Download and install latest version of VirtualBox
  2. Download Vagrant from the official web site. Choose the installer matching your operating system and architecture.

Le processus d’installation est simple, consultez Vagrant documentation officielle si vous rencontrez n’importe quel problème.

À la fin du processus d’installation déconnectez-vous de votre système et se reconnectez vous.

Vagrant aura besoin d’un fournisseur afin de configurer des ordinateurs virtuels. VirtualBox est prise en charge hors de la boîte. Assurez-vous juste que vous installez une des versions prises en charge de VirtualBox

Open a terminal and type vagrant version. A message containing the installed version of Vagrant will be printed on the terminal

Installed Version: 1.7.2
Latest Version: 1.7.4
...

Configuration de la Machine virtuelle

Setup of a VM with a Vagrantfile assuming you are on unix.

Starting from a provided Vagrant BOX

$ mkdir geonode && cd geonode
$ vagrant box add geonode-ws.box --name ubuntu/geonode-ws
$ vagrant init ubuntu/geonode-ws

Edit the vagrantfile for more memory (see issue #2076):

config.ssh.username = "ubuntu"
config.ssh.password = "ubuntu"
config.vm.provider "virtualbox" do |vb|
    vb.memory = "4092"
end

Starting from a Vagrant online image

$ mkdir geonode && cd geonode && vagrant init ubuntu/xenial64
# Create a working directory and initialize the vagrantfile within

This will create a configuration file called Vagrantfile containing the settings for the virtual machine, notably the config.vm.box variable set to “ubuntu/xenial64” will tell Vagrant the specific VM we want to run (Ubuntu 16.04 “Xenial”, 64 bit version)

Edit the vagrantfile for more memory (see issue #2076):

config.vm.provider "virtualbox" do |vb|
    vb.memory = "4092"
end
# Uncomment the section related to memory settings and edit that to at least

Vagrant needs a VirtualBox installed on your system to start. Download it and install from VirtualBox.

With the latest bersions of VirtualBox, you may also need to update your Vagrant system. Download and install the latest version from Vagrant.

To start the VM, run

$ vagrant up --provider=virtualbox
# Start the virtual machine as defined into the vagrantfile

The first time you run the command it is going to take some since you do not have a locally available image of the VM. Vagrant will download the VM from the Vagrant Could to your local system.

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty32' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/trusty32'
default: URL: https://atlas.hashicorp.com/ubuntu/trusty32
==> default: Adding box 'ubuntu/trusty32' (v20150928.0.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty32/versions/20150928.0.0/providers/virtualbox.b
ox
default: Progress: 3% (Rate: 489k/s, Estimated time remaining: 0:11:11)))

À la fin de la procédure de téléchargement Vagrant va démarrer la machine virtuelle.

To access the Virtual machine, run

$ vagrant ssh
# Get into the box with the vagrant user

Note

Vous avez besoin d’un client SSH pour la commande précédente pour travailler. La plupart des distributions Linux disposent d’un SSH installé. Si vous utilisez Windows comme l’installation de système d’exploitation invité MinGW ou Cygwin ou Git pour obtenir une ligne de commande SSH client. Plus d’informations disponibles ici

Vous serez connecté à l’invité d’ordinateur virtuel par SSH en tant qu’utilisateur Vagrant.

Install GeoNode into Ubuntu

From the GeoNode documentation

$ sudo add-apt-repository ppa:geonode/testing #only for workshop
# vagrant is already into sudoers
$ sudo apt-get update
# update packages
$ sudo apt-get install geonode
# download of all required dependencies for installing GeoNode

Avertissement

The command sudo apt-get install geonode may create issues if your system locale is not correctly configured.

In order to fix this, please follow the procedures below. If everything went well, you can skip those passages

$ sudo locale-gen en_US
$ sudo locale-gen en_US.UTF-8
$ sudo locale-gen it_IT.ISO-8859-1
$ sudo locale-gen it_IT.UTF-8
$ sudo locale-gen it_IT.ISO-8859-15@euro
$ sudo update-locale
# Update Locale
$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LANGUAGE=en_US.UTF-8
$ sudo dpkg-reconfigure geonode
# Export locale env vars and reconfigure geonode

Initialize GeoNode systemwide

$ geonode createsuperuser
# a commandline toolkit has been installed systemwide so let's create the superuser of the GeoNode instance
# use username: 'geonode' and password: 'geonode'

$ sudo geonode-updateip localhost:8001
# tell geonode which is its trusted address.

The geonode-updateip command will automatically fix GeoNode and GeoServer settings using the correct host and port.

You have installed GeoNode! Congratulations!!!

Anyway you don’t have GeoNode available from your local browser. So we have to set a new forwarding port in the vagrantfile:

config.vm.network "forwarded_port", guest: 80, host: 8001
# This port has to be the same of that before and equal between guest and host. You can understand this later on.
# Again don't use a port lower than 1024 on your host machine (not privileged)!!!

After this you have to reload the vagrant configuration:

$ vagrant reload
# reload vagrantfile with the new configuration

Behind the magic

Security hints and tricks

Security in GeoServer is hugely changed with the introduction of OAuth2

  1. Be sure that the ports are available to your host machine

    config.vm.network "forwarded_port", guest: 80, host: 8001
    # config.vm.network "forwarded_port", guest: 8080, host: 8080 # Optional,
    # enable if you don't need to reproduce a fully GeoNode proxied use case
    # forward another port to the host. You need to 'vagrant reload' to apply the changes
    
  2. Double check that the correct GeoNode Base Url has been configure on GeoServer

    $ sudo vi /usr/share/geoserver/data/security/role/geonode\ REST\ role\ service/config.xml
    # edit the configuration of geonode REST role service
    

    Must contain the following value:

    <baseUrl>http://localhost:80/</baseUrl>
    <!-- base url of geonode web server -->
    
  3. Set the correct OAuth2 server FQDN to GeoServer

    $ sudo vi /usr/share/geoserver/data/security/filter/geonode-oauth2/config.xml
    # edit the configuration of GeoServer security for the oauth2 provider
    

    Make sure it contains these values:

    <!-- GeoNode accessTokenUri -->
    <accessTokenUri>http://localhost/o/token/</accessTokenUri>
    <!-- GeoNode userAuthorizationUri -->
    <userAuthorizationUri>http://localhost:8001/o/authorize/</userAuthorizationUri>
    <!-- GeoServer Public URL -->
    <redirectUri>http://localhost:8001/geoserver</redirectUri>
    <!-- GeoNode checkTokenEndpointUrl -->
    <checkTokenEndpointUrl>http://localhost/api/o/v4/tokeninfo/</checkTokenEndpointUrl>
    <!-- GeoNode logoutUri -->
    <logoutUri>http://localhost:8001/account/logout/</logoutUri>
    
  4. Set the correct OAuth2 Keys to GeoServer

    $ sudo vi /usr/share/geoserver/data/security/filter/geonode-oauth2/config.xml
    # edit the configuration of GeoServer security for the oauth2 provider
    

    Make sure the clientId and clientSecret keys are the same of the GeoNode ones:

    <!-- GeoNode OAuth2 Client ID -->
    <cliendId>the_geonode_oauth_client_id</cliendId>
    <!-- GeoNode OAuth2 Client Secret -->
    <clientSecret>the_geonode_oauth_client_secret</clientSecret>
    
  5. Check the settings of GeoServer Global Proxy Base and Default Authentication Provider

    $ sudo vi /usr/share/geoserver/data/security/auth/geonodeAuthProvider/config.xml
    # edit configuration of default GeoServer authentication provider
    $ sudo vi /usr/share/geoserver/data/global.xml
    # edit configuration of default GeoServer proxy base url
    

    Change with these values:

    <baseUrl>http://localhost:8001/</baseUrl>
    <!-- base url of geonode web server -->
    

    Leave the default for this vagrant configuration:

    <proxyBaseUrl>http://localhost:80/geoserver</proxyBaseUrl>
    <!-- proxy base url of geonode web server -->
    <!-- set the port to 8080 if you are forwarding that to the host -->
    
  6. Restart the server:

    $ sudo service tomcat7 restart
    # restart Tomcat
    

Open GeoNode GUI at http://localhost:8001/